| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "webkit/fileapi/file_writer_delegate.h" | 25 #include "webkit/fileapi/file_writer_delegate.h" |
| 26 #include "webkit/fileapi/remove_operation_delegate.h" | 26 #include "webkit/fileapi/remove_operation_delegate.h" |
| 27 #include "webkit/fileapi/sandbox_file_stream_writer.h" | 27 #include "webkit/fileapi/sandbox_file_stream_writer.h" |
| 28 #include "webkit/quota/quota_manager.h" | 28 #include "webkit/quota/quota_manager.h" |
| 29 #include "webkit/quota/quota_types.h" | 29 #include "webkit/quota/quota_types.h" |
| 30 | 30 |
| 31 using webkit_blob::ShareableFileReference; | 31 using webkit_blob::ShareableFileReference; |
| 32 | 32 |
| 33 namespace fileapi { | 33 namespace fileapi { |
| 34 | 34 |
| 35 namespace { |
| 36 void NopCloseFileCallback() {} |
| 37 } |
| 38 |
| 35 LocalFileSystemOperation::LocalFileSystemOperation( | 39 LocalFileSystemOperation::LocalFileSystemOperation( |
| 36 FileSystemContext* file_system_context, | 40 FileSystemContext* file_system_context, |
| 37 scoped_ptr<FileSystemOperationContext> operation_context) | 41 scoped_ptr<FileSystemOperationContext> operation_context) |
| 38 : file_system_context_(file_system_context), | 42 : file_system_context_(file_system_context), |
| 39 operation_context_(operation_context.Pass()), | 43 operation_context_(operation_context.Pass()), |
| 40 async_file_util_(NULL), | 44 async_file_util_(NULL), |
| 41 peer_handle_(base::kNullProcessHandle), | 45 peer_handle_(base::kNullProcessHandle), |
| 42 pending_operation_(kOperationNone), | 46 pending_operation_(kOperationNone), |
| 43 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 47 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 44 DCHECK(operation_context_.get()); | 48 DCHECK(operation_context_.get()); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 const OpenFileCallback& callback) { | 328 const OpenFileCallback& callback) { |
| 325 DCHECK(SetPendingOperationType(kOperationOpenFile)); | 329 DCHECK(SetPendingOperationType(kOperationOpenFile)); |
| 326 scoped_ptr<LocalFileSystemOperation> deleter(this); | 330 scoped_ptr<LocalFileSystemOperation> deleter(this); |
| 327 | 331 |
| 328 peer_handle_ = peer_handle; | 332 peer_handle_ = peer_handle; |
| 329 | 333 |
| 330 if (file_flags & ( | 334 if (file_flags & ( |
| 331 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | | 335 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | |
| 332 base::PLATFORM_FILE_HIDDEN))) { | 336 base::PLATFORM_FILE_HIDDEN))) { |
| 333 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, | 337 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, |
| 334 base::PlatformFile(), base::ProcessHandle()); | 338 base::PlatformFile(), |
| 339 base::Closure(), |
| 340 base::ProcessHandle()); |
| 335 return; | 341 return; |
| 336 } | 342 } |
| 337 if (file_flags & | 343 if (file_flags & |
| 338 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | | 344 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | |
| 339 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | | 345 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | |
| 340 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 346 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 341 base::PLATFORM_FILE_DELETE_ON_CLOSE | | 347 base::PLATFORM_FILE_DELETE_ON_CLOSE | |
| 342 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { | 348 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { |
| 343 base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE); | 349 base::PlatformFileError result = SetUp(url, OPERATION_MODE_WRITE); |
| 344 if (result != base::PLATFORM_FILE_OK) { | 350 if (result != base::PLATFORM_FILE_OK) { |
| 345 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); | 351 callback.Run(result, |
| 352 base::PlatformFile(), |
| 353 base::Closure(), |
| 354 base::ProcessHandle()); |
| 346 return; | 355 return; |
| 347 } | 356 } |
| 348 } else { | 357 } else { |
| 349 base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ); | 358 base::PlatformFileError result = SetUp(url, OPERATION_MODE_READ); |
| 350 if (result != base::PLATFORM_FILE_OK) { | 359 if (result != base::PLATFORM_FILE_OK) { |
| 351 callback.Run(result, base::PlatformFile(), base::ProcessHandle()); | 360 callback.Run(result, |
| 361 base::PlatformFile(), |
| 362 base::Closure(), |
| 363 base::ProcessHandle()); |
| 352 return; | 364 return; |
| 353 } | 365 } |
| 354 } | 366 } |
| 355 GetUsageAndQuotaThenRunTask( | 367 GetUsageAndQuotaThenRunTask( |
| 356 url, | 368 url, |
| 357 base::Bind(&LocalFileSystemOperation::DoOpenFile, | 369 base::Bind(&LocalFileSystemOperation::DoOpenFile, |
| 358 base::Unretained(deleter.release()), | 370 base::Unretained(deleter.release()), |
| 359 url, callback, file_flags), | 371 url, callback, file_flags), |
| 360 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, | 372 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, |
| 361 base::kInvalidPlatformFileValue, | 373 base::kInvalidPlatformFileValue, |
| 374 base::Closure(), |
| 362 base::kNullProcessHandle)); | 375 base::kNullProcessHandle)); |
| 363 } | 376 } |
| 364 | 377 |
| 365 void LocalFileSystemOperation::NotifyCloseFile(const FileSystemURL& url) { | 378 void LocalFileSystemOperation::NotifyCloseFile(const FileSystemURL& url) { |
| 366 // No particular task to do. This method is for remote file systems that | 379 // No particular task to do. This method is for remote file systems that |
| 367 // need synchronization with remote server. | 380 // need synchronization with remote server. |
| 368 delete this; | 381 delete this; |
| 369 } | 382 } |
| 370 | 383 |
| 371 // We can only get here on a write or truncate that's not yet completed. | 384 // We can only get here on a write or truncate that's not yet completed. |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 callback.Run(rv); | 825 callback.Run(rv); |
| 813 } | 826 } |
| 814 | 827 |
| 815 void LocalFileSystemOperation::DidOpenFile( | 828 void LocalFileSystemOperation::DidOpenFile( |
| 816 const OpenFileCallback& callback, | 829 const OpenFileCallback& callback, |
| 817 base::PlatformFileError rv, | 830 base::PlatformFileError rv, |
| 818 base::PassPlatformFile file, | 831 base::PassPlatformFile file, |
| 819 bool unused) { | 832 bool unused) { |
| 820 if (rv == base::PLATFORM_FILE_OK) | 833 if (rv == base::PLATFORM_FILE_OK) |
| 821 CHECK_NE(base::kNullProcessHandle, peer_handle_); | 834 CHECK_NE(base::kNullProcessHandle, peer_handle_); |
| 822 callback.Run(rv, file.ReleaseValue(), peer_handle_); | 835 callback.Run(rv, file.ReleaseValue(), |
| 836 base::Bind(&NopCloseFileCallback), |
| 837 peer_handle_); |
| 823 } | 838 } |
| 824 | 839 |
| 825 void LocalFileSystemOperation::DidCreateSnapshotFile( | 840 void LocalFileSystemOperation::DidCreateSnapshotFile( |
| 826 const SnapshotFileCallback& callback, | 841 const SnapshotFileCallback& callback, |
| 827 base::PlatformFileError result, | 842 base::PlatformFileError result, |
| 828 const base::PlatformFileInfo& file_info, | 843 const base::PlatformFileInfo& file_info, |
| 829 const base::FilePath& platform_path, | 844 const base::FilePath& platform_path, |
| 830 SnapshotFilePolicy snapshot_policy) { | 845 SnapshotFilePolicy snapshot_policy) { |
| 831 scoped_refptr<ShareableFileReference> file_ref; | 846 scoped_refptr<ShareableFileReference> file_ref; |
| 832 if (result == base::PLATFORM_FILE_OK && | 847 if (result == base::PLATFORM_FILE_OK && |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 } | 884 } |
| 870 | 885 |
| 871 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 886 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
| 872 if (pending_operation_ != kOperationNone) | 887 if (pending_operation_ != kOperationNone) |
| 873 return false; | 888 return false; |
| 874 pending_operation_ = type; | 889 pending_operation_ = type; |
| 875 return true; | 890 return true; |
| 876 } | 891 } |
| 877 | 892 |
| 878 } // namespace fileapi | 893 } // namespace fileapi |
| OLD | NEW |