Index: base/file_util_proxy.cc |
diff --git a/base/file_util_proxy.cc b/base/file_util_proxy.cc |
index 1d5b9cc3cea8ca3b11d232c2a10f87b5c5dba582..0435b112e8ee09f294497254ee24795b53292e75 100644 |
--- a/base/file_util_proxy.cc |
+++ b/base/file_util_proxy.cc |
@@ -5,6 +5,7 @@ |
#include "base/file_util_proxy.h" |
#include "base/message_loop_proxy.h" |
+#include "base/platform_file.h" |
// TODO(jianli): Move the code from anonymous namespace to base namespace so |
// that all of the base:: prefixes would be unnecessary. |
@@ -167,8 +168,10 @@ class RelayCreateTemporary : public MessageLoopRelay { |
public: |
RelayCreateTemporary( |
scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
+ int file_flags, |
base::FileUtilProxy::CreateTemporaryCallback* callback) |
: message_loop_proxy_(message_loop_proxy), |
+ file_flags_(file_flags), |
callback_(callback), |
file_handle_(base::kInvalidPlatformFileValue) { |
DCHECK(callback); |
@@ -185,15 +188,17 @@ class RelayCreateTemporary : public MessageLoopRelay { |
// that returns a FilePath and a PlatformFile. |
file_util::CreateTemporaryFile(&file_path_); |
- // Use a fixed set of flags that are appropriate for writing to a temporary |
- // file from the IO thread using a net::FileStream. |
- int file_flags = |
- base::PLATFORM_FILE_CREATE_ALWAYS | |
- base::PLATFORM_FILE_WRITE | |
- base::PLATFORM_FILE_ASYNC | |
- base::PLATFORM_FILE_TEMPORARY; |
+ if (!(file_flags_ & base::PLATFORM_FILE_WRITE) || |
+ !(file_flags_ & base::PLATFORM_FILE_TEMPORARY) || |
+ (!(file_flags_ & base::PLATFORM_FILE_CREATE_ALWAYS) && |
+ !(file_flags_ & base::PLATFORM_FILE_CREATE) && |
+ !(file_flags_ & base::PLATFORM_FILE_OPEN_ALWAYS))) { |
+ LOG(DFATAL) << "Invalid file_flags for CreateTemporary: " << file_flags_; |
+ set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
+ return; |
+ } |
base::PlatformFileError error_code = base::PLATFORM_FILE_OK; |
- file_handle_ = base::CreatePlatformFile(file_path_, file_flags, |
+ file_handle_ = base::CreatePlatformFile(file_path_, file_flags_, |
NULL, &error_code); |
set_error_code(error_code); |
} |
@@ -206,6 +211,7 @@ class RelayCreateTemporary : public MessageLoopRelay { |
private: |
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
+ int file_flags_; |
base::FileUtilProxy::CreateTemporaryCallback* callback_; |
base::PlatformFile file_handle_; |
FilePath file_path_; |
@@ -742,9 +748,12 @@ bool FileUtilProxy::CreateOrOpen( |
// static |
bool FileUtilProxy::CreateTemporary( |
scoped_refptr<MessageLoopProxy> message_loop_proxy, |
+ int file_flags, |
CreateTemporaryCallback* callback) { |
return Start(FROM_HERE, message_loop_proxy, |
- new RelayCreateTemporary(message_loop_proxy, callback)); |
+ new RelayCreateTemporary(message_loop_proxy, |
+ file_flags, |
+ callback)); |
} |
// static |