OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
6 | 6 |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "net/url_request/url_request_context.h" | 8 #include "net/url_request/url_request_context.h" |
9 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 9 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
10 #include "webkit/fileapi/file_writer_delegate.h" | 10 #include "webkit/fileapi/file_writer_delegate.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 base::FileUtilProxy::Close(proxy_, file_writer_delegate_->file(), NULL); | 29 base::FileUtilProxy::Close(proxy_, file_writer_delegate_->file(), NULL); |
30 } | 30 } |
31 | 31 |
32 void FileSystemOperation::CreateFile(const FilePath& path, | 32 void FileSystemOperation::CreateFile(const FilePath& path, |
33 bool exclusive) { | 33 bool exclusive) { |
34 #ifndef NDEBUG | 34 #ifndef NDEBUG |
35 DCHECK(kOperationNone == pending_operation_); | 35 DCHECK(kOperationNone == pending_operation_); |
36 pending_operation_ = kOperationCreateFile; | 36 pending_operation_ = kOperationCreateFile; |
37 #endif | 37 #endif |
38 | 38 |
39 base::FileUtilProxy::Create( | 39 base::FileUtilProxy::EnsureFileExists( |
40 proxy_, path, base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_READ, | 40 proxy_, path, callback_factory_.NewCallback( |
41 callback_factory_.NewCallback( | 41 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive |
42 exclusive ? &FileSystemOperation::DidCreateFileExclusive | 42 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); |
43 : &FileSystemOperation::DidCreateFileNonExclusive)); | |
44 } | 43 } |
45 | 44 |
46 void FileSystemOperation::CreateDirectory(const FilePath& path, | 45 void FileSystemOperation::CreateDirectory(const FilePath& path, |
47 bool exclusive, | 46 bool exclusive, |
48 bool recursive) { | 47 bool recursive) { |
49 #ifndef NDEBUG | 48 #ifndef NDEBUG |
50 DCHECK(kOperationNone == pending_operation_); | 49 DCHECK(kOperationNone == pending_operation_); |
51 pending_operation_ = kOperationCreateDirectory; | 50 pending_operation_ = kOperationCreateDirectory; |
52 #endif | 51 #endif |
53 | 52 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 DCHECK(kOperationTruncate == pending_operation_); | 211 DCHECK(kOperationTruncate == pending_operation_); |
213 #endif | 212 #endif |
214 // We're cancelling a truncate operation, but we can't actually stop it | 213 // We're cancelling a truncate operation, but we can't actually stop it |
215 // since it's been proxied to another thread. We need to save the | 214 // since it's been proxied to another thread. We need to save the |
216 // cancel_operation so that when the truncate returns, it can see that it's | 215 // cancel_operation so that when the truncate returns, it can see that it's |
217 // been cancelled, report it, and report that the cancel has succeeded. | 216 // been cancelled, report it, and report that the cancel has succeeded. |
218 cancel_operation_ = cancel_operation; | 217 cancel_operation_ = cancel_operation; |
219 } | 218 } |
220 } | 219 } |
221 | 220 |
222 void FileSystemOperation::DidCreateFileExclusive( | 221 void FileSystemOperation::DidEnsureFileExistsExclusive( |
223 base::PlatformFileError rv, | 222 base::PlatformFileError rv, bool created) { |
224 base::PassPlatformFile file, | 223 if (rv == base::PLATFORM_FILE_OK && !created) |
225 bool created) { | 224 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS); |
| 225 else |
| 226 DidFinishFileOperation(rv); |
| 227 } |
| 228 |
| 229 void FileSystemOperation::DidEnsureFileExistsNonExclusive( |
| 230 base::PlatformFileError rv, bool /* created */) { |
226 DidFinishFileOperation(rv); | 231 DidFinishFileOperation(rv); |
227 } | 232 } |
228 | 233 |
229 void FileSystemOperation::DidCreateFileNonExclusive( | |
230 base::PlatformFileError rv, | |
231 base::PassPlatformFile file, | |
232 bool created) { | |
233 // Suppress the already exists error and report success. | |
234 if (rv == base::PLATFORM_FILE_OK || | |
235 rv == base::PLATFORM_FILE_ERROR_EXISTS) | |
236 dispatcher_->DidSucceed(); | |
237 else | |
238 dispatcher_->DidFail(rv); | |
239 } | |
240 | |
241 void FileSystemOperation::DidFinishFileOperation( | 234 void FileSystemOperation::DidFinishFileOperation( |
242 base::PlatformFileError rv) { | 235 base::PlatformFileError rv) { |
243 if (cancel_operation_) { | 236 if (cancel_operation_) { |
244 #ifndef NDEBUG | 237 #ifndef NDEBUG |
245 DCHECK(kOperationTruncate == pending_operation_); | 238 DCHECK(kOperationTruncate == pending_operation_); |
246 #endif | 239 #endif |
247 FileSystemOperation *cancel_op = cancel_operation_; | 240 FileSystemOperation *cancel_op = cancel_operation_; |
248 // This call deletes us, so we have to extract cancel_op first. | 241 // This call deletes us, so we have to extract cancel_op first. |
249 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); | 242 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); |
250 cancel_op->dispatcher_->DidSucceed(); | 243 cancel_op->dispatcher_->DidSucceed(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 301 } |
309 | 302 |
310 void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { | 303 void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { |
311 if (rv == base::PLATFORM_FILE_OK) | 304 if (rv == base::PLATFORM_FILE_OK) |
312 dispatcher_->DidSucceed(); | 305 dispatcher_->DidSucceed(); |
313 else | 306 else |
314 dispatcher_->DidFail(rv); | 307 dispatcher_->DidFail(rv); |
315 } | 308 } |
316 | 309 |
317 } // namespace fileapi | 310 } // namespace fileapi |
OLD | NEW |