Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / image_writer_private / image_writer_utils.cc
index 36c9ea4..1c0a36b 100644 (file)
@@ -1,4 +1,4 @@
-// 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.
 
@@ -11,19 +11,19 @@ namespace image_writer_utils
 
 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,
@@ -39,8 +39,9 @@ bool ImageWriter::Open(const base::FilePath& 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";
@@ -68,18 +69,18 @@ int ImageWriter::Write(const char* data_block, int data_size) {
   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,
@@ -95,8 +96,9 @@ bool ImageReader::Open(const base::FilePath& 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";