| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/fileapi/file_system_operation_runner.h" | 5 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 operation->CreateDirectory( | 79 operation->CreateDirectory( |
| 80 url, exclusive, recursive, | 80 url, exclusive, recursive, |
| 81 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 81 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 82 handle, callback)); | 82 handle, callback)); |
| 83 return handle.id; | 83 return handle.id; |
| 84 } | 84 } |
| 85 | 85 |
| 86 OperationID FileSystemOperationRunner::Copy( | 86 OperationID FileSystemOperationRunner::Copy( |
| 87 const FileSystemURL& src_url, | 87 const FileSystemURL& src_url, |
| 88 const FileSystemURL& dest_url, | 88 const FileSystemURL& dest_url, |
| 89 const CopyProgressCallback& progress_callback, |
| 89 const StatusCallback& callback) { | 90 const StatusCallback& callback) { |
| 90 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 91 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 91 FileSystemOperation* operation = | 92 FileSystemOperation* operation = |
| 92 file_system_context_->CreateFileSystemOperation(dest_url, &error); | 93 file_system_context_->CreateFileSystemOperation(dest_url, &error); |
| 93 BeginOperationScoper scope; | 94 BeginOperationScoper scope; |
| 94 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 95 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); |
| 95 if (!operation) { | 96 if (!operation) { |
| 96 DidFinish(handle, callback, error); | 97 DidFinish(handle, callback, error); |
| 97 return handle.id; | 98 return handle.id; |
| 98 } | 99 } |
| 99 PrepareForWrite(handle.id, dest_url); | 100 PrepareForWrite(handle.id, dest_url); |
| 100 PrepareForRead(handle.id, src_url); | 101 PrepareForRead(handle.id, src_url); |
| 101 operation->Copy( | 102 operation->Copy( |
| 102 src_url, dest_url, | 103 src_url, dest_url, progress_callback, |
| 103 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 104 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 104 handle, callback)); | 105 handle, callback)); |
| 105 return handle.id; | 106 return handle.id; |
| 106 } | 107 } |
| 107 | 108 |
| 108 OperationID FileSystemOperationRunner::Move( | 109 OperationID FileSystemOperationRunner::Move( |
| 109 const FileSystemURL& src_url, | 110 const FileSystemURL& src_url, |
| 110 const FileSystemURL& dest_url, | 111 const FileSystemURL& dest_url, |
| 111 const StatusCallback& callback) { | 112 const StatusCallback& callback) { |
| 112 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 113 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 operation->RemoveDirectory( | 433 operation->RemoveDirectory( |
| 433 url, | 434 url, |
| 434 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 435 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 435 handle, callback)); | 436 handle, callback)); |
| 436 return handle.id; | 437 return handle.id; |
| 437 } | 438 } |
| 438 | 439 |
| 439 OperationID FileSystemOperationRunner::CopyFileLocal( | 440 OperationID FileSystemOperationRunner::CopyFileLocal( |
| 440 const FileSystemURL& src_url, | 441 const FileSystemURL& src_url, |
| 441 const FileSystemURL& dest_url, | 442 const FileSystemURL& dest_url, |
| 443 const CopyFileProgressCallback& progress_callback, |
| 442 const StatusCallback& callback) { | 444 const StatusCallback& callback) { |
| 443 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 445 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 444 FileSystemOperation* operation = | 446 FileSystemOperation* operation = |
| 445 file_system_context_->CreateFileSystemOperation(src_url, &error); | 447 file_system_context_->CreateFileSystemOperation(src_url, &error); |
| 446 BeginOperationScoper scope; | 448 BeginOperationScoper scope; |
| 447 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 449 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); |
| 448 if (!operation) { | 450 if (!operation) { |
| 449 DidFinish(handle, callback, error); | 451 DidFinish(handle, callback, error); |
| 450 return handle.id; | 452 return handle.id; |
| 451 } | 453 } |
| 452 operation->CopyFileLocal( | 454 operation->CopyFileLocal( |
| 453 src_url, dest_url, | 455 src_url, dest_url, progress_callback, |
| 454 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 456 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
| 455 handle, callback)); | 457 handle, callback)); |
| 456 return handle.id; | 458 return handle.id; |
| 457 } | 459 } |
| 458 | 460 |
| 459 OperationID FileSystemOperationRunner::MoveFileLocal( | 461 OperationID FileSystemOperationRunner::MoveFileLocal( |
| 460 const FileSystemURL& src_url, | 462 const FileSystemURL& src_url, |
| 461 const FileSystemURL& dest_url, | 463 const FileSystemURL& dest_url, |
| 462 const StatusCallback& callback) { | 464 const StatusCallback& callback) { |
| 463 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 465 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 stray_cancel_callbacks_.find(id); | 651 stray_cancel_callbacks_.find(id); |
| 650 if (found_cancel != stray_cancel_callbacks_.end()) { | 652 if (found_cancel != stray_cancel_callbacks_.end()) { |
| 651 // This cancel has been requested after the operation has finished, | 653 // This cancel has been requested after the operation has finished, |
| 652 // so report that we failed to stop it. | 654 // so report that we failed to stop it. |
| 653 found_cancel->second.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 655 found_cancel->second.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| 654 stray_cancel_callbacks_.erase(found_cancel); | 656 stray_cancel_callbacks_.erase(found_cancel); |
| 655 } | 657 } |
| 656 } | 658 } |
| 657 | 659 |
| 658 } // namespace fileapi | 660 } // namespace fileapi |
| OLD | NEW |