| 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 OperationID FileSystemOperationRunner::OpenFile( | 343 OperationID FileSystemOperationRunner::OpenFile( |
| 344 const FileSystemURL& url, | 344 const FileSystemURL& url, |
| 345 int file_flags, | 345 int file_flags, |
| 346 const OpenFileCallback& callback) { | 346 const OpenFileCallback& callback) { |
| 347 base::File::Error error = base::File::FILE_OK; | 347 base::File::Error error = base::File::FILE_OK; |
| 348 FileSystemOperation* operation = | 348 FileSystemOperation* operation = |
| 349 file_system_context_->CreateFileSystemOperation(url, &error); | 349 file_system_context_->CreateFileSystemOperation(url, &error); |
| 350 BeginOperationScoper scope; | 350 BeginOperationScoper scope; |
| 351 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 351 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); |
| 352 if (!operation) { | 352 if (!operation) { |
| 353 DidOpenFile(handle, callback, error, base::kInvalidPlatformFileValue, | 353 DidOpenFile(handle, callback, base::File(error), base::Closure()); |
| 354 base::Closure()); | |
| 355 return handle.id; | 354 return handle.id; |
| 356 } | 355 } |
| 357 if (file_flags & | 356 if (file_flags & |
| 358 (base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_OPEN_ALWAYS | | 357 (base::File::FLAG_CREATE | base::File::FLAG_OPEN_ALWAYS | |
| 359 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_TRUNCATED | | 358 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_OPEN_TRUNCATED | |
| 360 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 359 base::File::FLAG_WRITE | base::File::FLAG_EXCLUSIVE_WRITE | |
| 361 base::PLATFORM_FILE_DELETE_ON_CLOSE | | 360 base::File::FLAG_DELETE_ON_CLOSE | |
| 362 base::PLATFORM_FILE_WRITE_ATTRIBUTES)) { | 361 base::File::FLAG_WRITE_ATTRIBUTES)) { |
| 363 PrepareForWrite(handle.id, url); | 362 PrepareForWrite(handle.id, url); |
| 364 } else { | 363 } else { |
| 365 PrepareForRead(handle.id, url); | 364 PrepareForRead(handle.id, url); |
| 366 } | 365 } |
| 367 operation->OpenFile( | 366 operation->OpenFile( |
| 368 url, file_flags, | 367 url, file_flags, |
| 369 base::Bind(&FileSystemOperationRunner::DidOpenFile, AsWeakPtr(), | 368 base::Bind(&FileSystemOperationRunner::DidOpenFile, AsWeakPtr(), |
| 370 handle, callback)); | 369 handle, callback)); |
| 371 return handle.id; | 370 return handle.id; |
| 372 } | 371 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 return; | 571 return; |
| 573 } | 572 } |
| 574 callback.Run(rv, bytes, complete); | 573 callback.Run(rv, bytes, complete); |
| 575 if (rv != base::File::FILE_OK || complete) | 574 if (rv != base::File::FILE_OK || complete) |
| 576 FinishOperation(handle.id); | 575 FinishOperation(handle.id); |
| 577 } | 576 } |
| 578 | 577 |
| 579 void FileSystemOperationRunner::DidOpenFile( | 578 void FileSystemOperationRunner::DidOpenFile( |
| 580 const OperationHandle& handle, | 579 const OperationHandle& handle, |
| 581 const OpenFileCallback& callback, | 580 const OpenFileCallback& callback, |
| 582 base::File::Error rv, | 581 base::File file, |
| 583 base::PlatformFile file, | |
| 584 const base::Closure& on_close_callback) { | 582 const base::Closure& on_close_callback) { |
| 585 if (handle.scope) { | 583 if (handle.scope) { |
| 586 finished_operations_.insert(handle.id); | 584 finished_operations_.insert(handle.id); |
| 587 base::MessageLoopProxy::current()->PostTask( | 585 base::MessageLoopProxy::current()->PostTask( |
| 588 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidOpenFile, | 586 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidOpenFile, |
| 589 AsWeakPtr(), handle, callback, rv, file, | 587 AsWeakPtr(), handle, callback, Passed(&file), |
| 590 on_close_callback)); | 588 on_close_callback)); |
| 591 return; | 589 return; |
| 592 } | 590 } |
| 593 callback.Run(rv, file, on_close_callback); | 591 callback.Run(file.Pass(), on_close_callback); |
| 594 FinishOperation(handle.id); | 592 FinishOperation(handle.id); |
| 595 } | 593 } |
| 596 | 594 |
| 597 void FileSystemOperationRunner::DidCreateSnapshot( | 595 void FileSystemOperationRunner::DidCreateSnapshot( |
| 598 const OperationHandle& handle, | 596 const OperationHandle& handle, |
| 599 const SnapshotFileCallback& callback, | 597 const SnapshotFileCallback& callback, |
| 600 base::File::Error rv, | 598 base::File::Error rv, |
| 601 const base::File::Info& file_info, | 599 const base::File::Info& file_info, |
| 602 const base::FilePath& platform_path, | 600 const base::FilePath& platform_path, |
| 603 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 601 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 stray_cancel_callbacks_.find(id); | 680 stray_cancel_callbacks_.find(id); |
| 683 if (found_cancel != stray_cancel_callbacks_.end()) { | 681 if (found_cancel != stray_cancel_callbacks_.end()) { |
| 684 // This cancel has been requested after the operation has finished, | 682 // This cancel has been requested after the operation has finished, |
| 685 // so report that we failed to stop it. | 683 // so report that we failed to stop it. |
| 686 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 684 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 687 stray_cancel_callbacks_.erase(found_cancel); | 685 stray_cancel_callbacks_.erase(found_cancel); |
| 688 } | 686 } |
| 689 } | 687 } |
| 690 | 688 |
| 691 } // namespace fileapi | 689 } // namespace fileapi |
| OLD | NEW |