OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util_proxy.h" | 5 #include "base/file_util_proxy.h" |
6 | 6 |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
8 | 8 |
9 // TODO(jianli): Move the code from anonymous namespace to base namespace so | 9 // TODO(jianli): Move the code from anonymous namespace to base namespace so |
10 // that all of the base:: prefixes would be unnecessary. | 10 // that all of the base:: prefixes would be unnecessary. |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 int file_flags_; | 160 int file_flags_; |
161 base::FileUtilProxy::CreateOrOpenCallback* callback_; | 161 base::FileUtilProxy::CreateOrOpenCallback* callback_; |
162 base::PlatformFile file_handle_; | 162 base::PlatformFile file_handle_; |
163 bool created_; | 163 bool created_; |
164 }; | 164 }; |
165 | 165 |
166 class RelayCreateTemporary : public MessageLoopRelay { | 166 class RelayCreateTemporary : public MessageLoopRelay { |
167 public: | 167 public: |
168 RelayCreateTemporary( | 168 RelayCreateTemporary( |
169 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | 169 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, |
| 170 int additional_file_flags, |
170 base::FileUtilProxy::CreateTemporaryCallback* callback) | 171 base::FileUtilProxy::CreateTemporaryCallback* callback) |
171 : message_loop_proxy_(message_loop_proxy), | 172 : message_loop_proxy_(message_loop_proxy), |
| 173 additional_file_flags_(additional_file_flags), |
172 callback_(callback), | 174 callback_(callback), |
173 file_handle_(base::kInvalidPlatformFileValue) { | 175 file_handle_(base::kInvalidPlatformFileValue) { |
174 DCHECK(callback); | 176 DCHECK(callback); |
175 } | 177 } |
176 | 178 |
177 protected: | 179 protected: |
178 virtual ~RelayCreateTemporary() { | 180 virtual ~RelayCreateTemporary() { |
179 if (file_handle_ != base::kInvalidPlatformFileValue) | 181 if (file_handle_ != base::kInvalidPlatformFileValue) |
180 base::FileUtilProxy::Close(message_loop_proxy_, file_handle_, NULL); | 182 base::FileUtilProxy::Close(message_loop_proxy_, file_handle_, NULL); |
181 } | 183 } |
182 | 184 |
183 virtual void RunWork() { | 185 virtual void RunWork() { |
184 // TODO(darin): file_util should have a variant of CreateTemporaryFile | 186 // TODO(darin): file_util should have a variant of CreateTemporaryFile |
185 // that returns a FilePath and a PlatformFile. | 187 // that returns a FilePath and a PlatformFile. |
186 file_util::CreateTemporaryFile(&file_path_); | 188 file_util::CreateTemporaryFile(&file_path_); |
187 | 189 |
188 // Use a fixed set of flags that are appropriate for writing to a temporary | |
189 // file from the IO thread using a net::FileStream. | |
190 int file_flags = | 190 int file_flags = |
| 191 base::PLATFORM_FILE_WRITE | |
| 192 base::PLATFORM_FILE_TEMPORARY | |
191 base::PLATFORM_FILE_CREATE_ALWAYS | | 193 base::PLATFORM_FILE_CREATE_ALWAYS | |
192 base::PLATFORM_FILE_WRITE | | 194 additional_file_flags_; |
193 base::PLATFORM_FILE_ASYNC | | 195 |
194 base::PLATFORM_FILE_TEMPORARY; | |
195 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; | 196 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; |
196 file_handle_ = base::CreatePlatformFile(file_path_, file_flags, | 197 file_handle_ = base::CreatePlatformFile(file_path_, file_flags, |
197 NULL, &error_code); | 198 NULL, &error_code); |
198 set_error_code(error_code); | 199 set_error_code(error_code); |
199 } | 200 } |
200 | 201 |
201 virtual void RunCallback() { | 202 virtual void RunCallback() { |
202 callback_->Run(error_code(), base::PassPlatformFile(&file_handle_), | 203 callback_->Run(error_code(), base::PassPlatformFile(&file_handle_), |
203 file_path_); | 204 file_path_); |
204 delete callback_; | 205 delete callback_; |
205 } | 206 } |
206 | 207 |
207 private: | 208 private: |
208 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 209 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 210 int additional_file_flags_; |
209 base::FileUtilProxy::CreateTemporaryCallback* callback_; | 211 base::FileUtilProxy::CreateTemporaryCallback* callback_; |
210 base::PlatformFile file_handle_; | 212 base::PlatformFile file_handle_; |
211 FilePath file_path_; | 213 FilePath file_path_; |
212 }; | 214 }; |
213 | 215 |
214 class RelayWithStatusCallback : public MessageLoopRelay { | 216 class RelayWithStatusCallback : public MessageLoopRelay { |
215 public: | 217 public: |
216 explicit RelayWithStatusCallback( | 218 explicit RelayWithStatusCallback( |
217 base::FileUtilProxy::StatusCallback* callback) | 219 base::FileUtilProxy::StatusCallback* callback) |
218 : callback_(callback) { | 220 : callback_(callback) { |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 737 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
736 const FilePath& file_path, int file_flags, | 738 const FilePath& file_path, int file_flags, |
737 CreateOrOpenCallback* callback) { | 739 CreateOrOpenCallback* callback) { |
738 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen( | 740 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen( |
739 message_loop_proxy, file_path, file_flags, callback)); | 741 message_loop_proxy, file_path, file_flags, callback)); |
740 } | 742 } |
741 | 743 |
742 // static | 744 // static |
743 bool FileUtilProxy::CreateTemporary( | 745 bool FileUtilProxy::CreateTemporary( |
744 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 746 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
| 747 int additional_file_flags, |
745 CreateTemporaryCallback* callback) { | 748 CreateTemporaryCallback* callback) { |
746 return Start(FROM_HERE, message_loop_proxy, | 749 return Start(FROM_HERE, message_loop_proxy, |
747 new RelayCreateTemporary(message_loop_proxy, callback)); | 750 new RelayCreateTemporary(message_loop_proxy, |
| 751 additional_file_flags, |
| 752 callback)); |
748 } | 753 } |
749 | 754 |
750 // static | 755 // static |
751 bool FileUtilProxy::Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, | 756 bool FileUtilProxy::Close(scoped_refptr<MessageLoopProxy> message_loop_proxy, |
752 base::PlatformFile file_handle, | 757 base::PlatformFile file_handle, |
753 StatusCallback* callback) { | 758 StatusCallback* callback) { |
754 return Start(FROM_HERE, message_loop_proxy, | 759 return Start(FROM_HERE, message_loop_proxy, |
755 new RelayClose(file_handle, callback)); | 760 new RelayClose(file_handle, callback)); |
756 } | 761 } |
757 | 762 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 | 913 |
909 // static | 914 // static |
910 bool FileUtilProxy::Flush( | 915 bool FileUtilProxy::Flush( |
911 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 916 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
912 PlatformFile file, | 917 PlatformFile file, |
913 StatusCallback* callback) { | 918 StatusCallback* callback) { |
914 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); | 919 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); |
915 } | 920 } |
916 | 921 |
917 } // namespace base | 922 } // namespace base |
OLD | NEW |