| 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 "storage/browser/fileapi/file_system_operation_runner.h" | 5 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "net/url_request/url_request_context.h" | 14 #include "net/url_request/url_request_context.h" |
| 14 #include "storage/browser/blob/blob_url_request_job_factory.h" | 15 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 15 #include "storage/browser/blob/shareable_file_reference.h" | 16 #include "storage/browser/blob/shareable_file_reference.h" |
| 16 #include "storage/browser/fileapi/file_observers.h" | 17 #include "storage/browser/fileapi/file_observers.h" |
| 17 #include "storage/browser/fileapi/file_stream_writer.h" | 18 #include "storage/browser/fileapi/file_stream_writer.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 } | 256 } |
| 256 | 257 |
| 257 scoped_ptr<FileStreamWriter> writer( | 258 scoped_ptr<FileStreamWriter> writer( |
| 258 file_system_context_->CreateFileStreamWriter(url, offset)); | 259 file_system_context_->CreateFileStreamWriter(url, offset)); |
| 259 if (!writer) { | 260 if (!writer) { |
| 260 // Write is not supported. | 261 // Write is not supported. |
| 261 DidWrite(handle, callback, base::File::FILE_ERROR_SECURITY, 0, true); | 262 DidWrite(handle, callback, base::File::FILE_ERROR_SECURITY, 0, true); |
| 262 return handle.id; | 263 return handle.id; |
| 263 } | 264 } |
| 264 | 265 |
| 265 scoped_ptr<FileWriterDelegate> writer_delegate( | 266 scoped_ptr<FileWriterDelegate> writer_delegate(new FileWriterDelegate( |
| 266 new FileWriterDelegate(writer.Pass(), url.mount_option().flush_policy())); | 267 std::move(writer), url.mount_option().flush_policy())); |
| 267 | 268 |
| 268 scoped_ptr<net::URLRequest> blob_request( | 269 scoped_ptr<net::URLRequest> blob_request( |
| 269 storage::BlobProtocolHandler::CreateBlobRequest( | 270 storage::BlobProtocolHandler::CreateBlobRequest( |
| 270 blob.Pass(), url_request_context, writer_delegate.get())); | 271 std::move(blob), url_request_context, writer_delegate.get())); |
| 271 | 272 |
| 272 PrepareForWrite(handle.id, url); | 273 PrepareForWrite(handle.id, url); |
| 273 operation->Write( | 274 operation->Write(url, std::move(writer_delegate), std::move(blob_request), |
| 274 url, writer_delegate.Pass(), blob_request.Pass(), | 275 base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), |
| 275 base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), | 276 handle, callback)); |
| 276 handle, callback)); | |
| 277 return handle.id; | 277 return handle.id; |
| 278 } | 278 } |
| 279 | 279 |
| 280 OperationID FileSystemOperationRunner::Truncate( | 280 OperationID FileSystemOperationRunner::Truncate( |
| 281 const FileSystemURL& url, | 281 const FileSystemURL& url, |
| 282 int64_t length, | 282 int64_t length, |
| 283 const StatusCallback& callback) { | 283 const StatusCallback& callback) { |
| 284 base::File::Error error = base::File::FILE_OK; | 284 base::File::Error error = base::File::FILE_OK; |
| 285 FileSystemOperation* operation = | 285 FileSystemOperation* operation = |
| 286 file_system_context_->CreateFileSystemOperation(url, &error); | 286 file_system_context_->CreateFileSystemOperation(url, &error); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 base::File file, | 584 base::File file, |
| 585 const base::Closure& on_close_callback) { | 585 const base::Closure& on_close_callback) { |
| 586 if (handle.scope) { | 586 if (handle.scope) { |
| 587 finished_operations_.insert(handle.id); | 587 finished_operations_.insert(handle.id); |
| 588 base::ThreadTaskRunnerHandle::Get()->PostTask( | 588 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 589 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidOpenFile, | 589 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidOpenFile, |
| 590 AsWeakPtr(), handle, callback, Passed(&file), | 590 AsWeakPtr(), handle, callback, Passed(&file), |
| 591 on_close_callback)); | 591 on_close_callback)); |
| 592 return; | 592 return; |
| 593 } | 593 } |
| 594 callback.Run(file.Pass(), on_close_callback); | 594 callback.Run(std::move(file), on_close_callback); |
| 595 FinishOperation(handle.id); | 595 FinishOperation(handle.id); |
| 596 } | 596 } |
| 597 | 597 |
| 598 void FileSystemOperationRunner::DidCreateSnapshot( | 598 void FileSystemOperationRunner::DidCreateSnapshot( |
| 599 const OperationHandle& handle, | 599 const OperationHandle& handle, |
| 600 const SnapshotFileCallback& callback, | 600 const SnapshotFileCallback& callback, |
| 601 base::File::Error rv, | 601 base::File::Error rv, |
| 602 const base::File::Info& file_info, | 602 const base::File::Info& file_info, |
| 603 const base::FilePath& platform_path, | 603 const base::FilePath& platform_path, |
| 604 const scoped_refptr<storage::ShareableFileReference>& file_ref) { | 604 const scoped_refptr<storage::ShareableFileReference>& file_ref) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 stray_cancel_callbacks_.find(id); | 683 stray_cancel_callbacks_.find(id); |
| 684 if (found_cancel != stray_cancel_callbacks_.end()) { | 684 if (found_cancel != stray_cancel_callbacks_.end()) { |
| 685 // This cancel has been requested after the operation has finished, | 685 // This cancel has been requested after the operation has finished, |
| 686 // so report that we failed to stop it. | 686 // so report that we failed to stop it. |
| 687 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 687 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
| 688 stray_cancel_callbacks_.erase(found_cancel); | 688 stray_cancel_callbacks_.erase(found_cancel); |
| 689 } | 689 } |
| 690 } | 690 } |
| 691 | 691 |
| 692 } // namespace storage | 692 } // namespace storage |
| OLD | NEW |