summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/file_util_proxy.cc23
-rw-r--r--base/file_util_proxy.h7
-rw-r--r--webkit/fileapi/file_system_operation.cc4
3 files changed, 31 insertions, 3 deletions
diff --git a/base/file_util_proxy.cc b/base/file_util_proxy.cc
index b3b18f8..9cfff63 100644
--- a/base/file_util_proxy.cc
+++ b/base/file_util_proxy.cc
@@ -119,12 +119,14 @@ class RelayCreateOrOpen : public MessageLoopRelay {
scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
const FilePath& file_path,
int file_flags,
+ bool return_no_handle,
base::FileUtilProxy::CreateOrOpenCallback* callback)
: message_loop_proxy_(message_loop_proxy),
file_path_(file_path),
file_flags_(file_flags),
callback_(callback),
file_handle_(base::kInvalidPlatformFileValue),
+ return_no_handle_(return_no_handle),
created_(false) {
DCHECK(callback);
}
@@ -139,6 +141,13 @@ class RelayCreateOrOpen : public MessageLoopRelay {
base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
file_handle_ = base::CreatePlatformFile(file_path_, file_flags_,
&created_, &error_code);
+ // If the return_no_handle is true the caller is not interested
+ // in the file_handle_. Close it right now.
+ if (return_no_handle_ && file_handle_ != base::kInvalidPlatformFileValue) {
+ // We don't check the return value here.
+ base::ClosePlatformFile(file_handle_);
+ file_handle_ = base::kInvalidPlatformFileValue;
+ }
set_error_code(error_code);
}
@@ -154,6 +163,7 @@ class RelayCreateOrOpen : public MessageLoopRelay {
int file_flags_;
base::FileUtilProxy::CreateOrOpenCallback* callback_;
base::PlatformFile file_handle_;
+ bool return_no_handle_;
bool created_;
};
@@ -680,7 +690,18 @@ bool FileUtilProxy::CreateOrOpen(
const FilePath& file_path, int file_flags,
CreateOrOpenCallback* callback) {
return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(
- message_loop_proxy, file_path, file_flags, callback));
+ message_loop_proxy, file_path, file_flags, false /* return_no_handle */,
+ callback));
+}
+
+// static
+bool FileUtilProxy::Create(
+ scoped_refptr<MessageLoopProxy> message_loop_proxy,
+ const FilePath& file_path, int file_flags,
+ CreateOrOpenCallback* callback) {
+ return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(
+ message_loop_proxy, file_path, file_flags, true /* return_no_handle */,
+ callback));
}
// static
diff --git a/base/file_util_proxy.h b/base/file_util_proxy.h
index e716ab7..11fc988 100644
--- a/base/file_util_proxy.h
+++ b/base/file_util_proxy.h
@@ -48,6 +48,13 @@ class FileUtilProxy {
int file_flags,
CreateOrOpenCallback* callback);
+ // Creates a file with the given flags. This one is a variation of
+ // CreateOrOpen but it doesn't return a file handle.
+ static bool Create(scoped_refptr<MessageLoopProxy> message_loop_proxy,
+ const FilePath& file_path,
+ int file_flags,
+ CreateOrOpenCallback* callback);
+
// Creates a temporary file for writing. The path and an open file handle
// are returned. It is invalid to pass NULL for the callback.
typedef Callback3<base::PlatformFileError /* error code */,
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index 29690b9..e15de4c 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -36,7 +36,7 @@ void FileSystemOperation::CreateFile(const FilePath& path,
pending_operation_ = kOperationCreateFile;
#endif
- base::FileUtilProxy::CreateOrOpen(
+ base::FileUtilProxy::Create(
proxy_, path, base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ,
callback_factory_.NewCallback(
exclusive ? &FileSystemOperation::DidCreateFileExclusive
@@ -145,7 +145,7 @@ void FileSystemOperation::Write(
file_writer_delegate_.reset(new FileWriterDelegate(this, offset));
blob_request_.reset(new URLRequest(blob_url, file_writer_delegate_.get()));
blob_request_->set_context(url_request_context);
- base::FileUtilProxy::CreateOrOpen(
+ base::FileUtilProxy::Create(
proxy_,
path,
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE |