-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const int kFsyncRatio = 1024;
-ImageWriter::ImageWriter() : file_(0),
+ImageWriter::ImageWriter() : file_(base::kInvalidPlatformFileValue),
writes_count_(0) {
}
ImageWriter::~ImageWriter() {
- if (file_)
+ if (file_ != base::kInvalidPlatformFileValue)
base::ClosePlatformFile(file_);
}
bool ImageWriter::Open(const base::FilePath& path) {
- if (file_)
+ if (file_ != base::kInvalidPlatformFileValue)
Close();
- DCHECK(!file_);
+ DCHECK_EQ(base::kInvalidPlatformFileValue, file_);
base::PlatformFileError error;
file_ = base::CreatePlatformFile(
path,
}
bool ImageWriter::Close() {
- if (file_ && base::ClosePlatformFile(file_)) {
- file_ = 0;
+ if (file_ != base::kInvalidPlatformFileValue &&
+ base::ClosePlatformFile(file_)) {
+ file_ = base::kInvalidPlatformFileValue;
return true;
} else {
LOG(ERROR) << "Could not close target file";
return written;
}
-ImageReader::ImageReader() : file_(0) {
+ImageReader::ImageReader() : file_(base::kInvalidPlatformFileValue) {
}
ImageReader::~ImageReader() {
- if (file_)
+ if (file_ != base::kInvalidPlatformFileValue)
base::ClosePlatformFile(file_);
}
bool ImageReader::Open(const base::FilePath& path) {
- if (file_)
+ if (file_ != base::kInvalidPlatformFileValue)
Close();
- DCHECK(!file_);
+ DCHECK_EQ(base::kInvalidPlatformFileValue, file_);
base::PlatformFileError error;
file_ = base::CreatePlatformFile(
path,
}
bool ImageReader::Close() {
- if (file_ && base::ClosePlatformFile(file_)) {
- file_ = 0;
+ if (file_ != base::kInvalidPlatformFileValue &&
+ base::ClosePlatformFile(file_)) {
+ file_ = base::kInvalidPlatformFileValue;
return true;
} else {
LOG(ERROR) << "Could not close target file";