| 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" |
| 11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
| 12 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
| 13 #include "webkit/blob/blob_storage_context.h" |
| 13 #include "webkit/blob/shareable_file_reference.h" | 14 #include "webkit/blob/shareable_file_reference.h" |
| 15 #include "webkit/blob/blob_url_request_job_factory.h" |
| 14 #include "webkit/fileapi/file_observers.h" | 16 #include "webkit/fileapi/file_observers.h" |
| 15 #include "webkit/fileapi/file_system_context.h" | 17 #include "webkit/fileapi/file_system_context.h" |
| 16 #include "webkit/fileapi/file_system_file_util_proxy.h" | 18 #include "webkit/fileapi/file_system_file_util_proxy.h" |
| 17 #include "webkit/fileapi/file_system_mount_point_provider.h" | 19 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 18 #include "webkit/fileapi/file_system_task_runners.h" | 20 #include "webkit/fileapi/file_system_task_runners.h" |
| 19 #include "webkit/fileapi/file_system_types.h" | 21 #include "webkit/fileapi/file_system_types.h" |
| 20 #include "webkit/fileapi/file_system_url.h" | 22 #include "webkit/fileapi/file_system_url.h" |
| 21 #include "webkit/fileapi/file_system_util.h" | 23 #include "webkit/fileapi/file_system_util.h" |
| 22 #include "webkit/fileapi/file_writer_delegate.h" | 24 #include "webkit/fileapi/file_writer_delegate.h" |
| 23 #include "webkit/fileapi/sandbox_file_stream_writer.h" | 25 #include "webkit/fileapi/sandbox_file_stream_writer.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 259 |
| 258 FileSystemFileUtilProxy::Delete( | 260 FileSystemFileUtilProxy::Delete( |
| 259 operation_context_.get(), src_util_, url, recursive, | 261 operation_context_.get(), src_util_, url, recursive, |
| 260 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, | 262 base::Bind(&LocalFileSystemOperation::DidFinishFileOperation, |
| 261 base::Owned(this), callback)); | 263 base::Owned(this), callback)); |
| 262 } | 264 } |
| 263 | 265 |
| 264 void LocalFileSystemOperation::Write( | 266 void LocalFileSystemOperation::Write( |
| 265 const net::URLRequestContext* url_request_context, | 267 const net::URLRequestContext* url_request_context, |
| 266 const FileSystemURL& url, | 268 const FileSystemURL& url, |
| 267 const GURL& blob_url, | 269 scoped_ptr<webkit_blob::BlobDataHandle> blob, |
| 268 int64 offset, | 270 int64 offset, |
| 269 const WriteCallback& callback) { | 271 const WriteCallback& callback) { |
| 270 GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run(); | 272 GetWriteClosure(url_request_context, url, blob.Pass(), offset, callback) |
| 273 .Run(); |
| 271 } | 274 } |
| 272 | 275 |
| 273 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, | 276 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, |
| 274 const StatusCallback& callback) { | 277 const StatusCallback& callback) { |
| 275 DCHECK(SetPendingOperationType(kOperationTruncate)); | 278 DCHECK(SetPendingOperationType(kOperationTruncate)); |
| 276 | 279 |
| 277 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); | 280 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); |
| 278 if (result != base::PLATFORM_FILE_OK) { | 281 if (result != base::PLATFORM_FILE_OK) { |
| 279 callback.Run(result); | 282 callback.Run(result); |
| 280 delete this; | 283 delete this; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 return; | 501 return; |
| 499 } | 502 } |
| 500 | 503 |
| 501 operation_context_->set_allowed_bytes_growth(quota - usage); | 504 operation_context_->set_allowed_bytes_growth(quota - usage); |
| 502 task.Run(); | 505 task.Run(); |
| 503 } | 506 } |
| 504 | 507 |
| 505 base::Closure LocalFileSystemOperation::GetWriteClosure( | 508 base::Closure LocalFileSystemOperation::GetWriteClosure( |
| 506 const net::URLRequestContext* url_request_context, | 509 const net::URLRequestContext* url_request_context, |
| 507 const FileSystemURL& url, | 510 const FileSystemURL& url, |
| 508 const GURL& blob_url, | 511 scoped_ptr<webkit_blob::BlobDataHandle> blob_handle, |
| 509 int64 offset, | 512 int64 offset, |
| 510 const WriteCallback& callback) { | 513 const WriteCallback& callback) { |
| 511 DCHECK(SetPendingOperationType(kOperationWrite)); | 514 DCHECK(SetPendingOperationType(kOperationWrite)); |
| 512 | 515 |
| 513 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); | 516 base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE); |
| 514 if (result != base::PLATFORM_FILE_OK) { | 517 if (result != base::PLATFORM_FILE_OK) { |
| 515 return base::Bind(&LocalFileSystemOperation::DidFailWrite, | 518 return base::Bind(&LocalFileSystemOperation::DidFailWrite, |
| 516 base::Owned(this), callback, result); | 519 base::Owned(this), callback, result); |
| 517 } | 520 } |
| 518 | 521 |
| 519 FileSystemMountPointProvider* provider = file_system_context()-> | 522 FileSystemMountPointProvider* provider = file_system_context()-> |
| 520 GetMountPointProvider(url.type()); | 523 GetMountPointProvider(url.type()); |
| 521 DCHECK(provider); | 524 DCHECK(provider); |
| 522 scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter( | 525 scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter( |
| 523 url, offset, file_system_context())); | 526 url, offset, file_system_context())); |
| 524 | 527 |
| 525 if (!writer.get()) { | 528 if (!writer.get()) { |
| 526 // Write is not supported. | 529 // Write is not supported. |
| 527 return base::Bind(&LocalFileSystemOperation::DidFailWrite, | 530 return base::Bind(&LocalFileSystemOperation::DidFailWrite, |
| 528 base::Owned(this), callback, | 531 base::Owned(this), callback, |
| 529 base::PLATFORM_FILE_ERROR_SECURITY); | 532 base::PLATFORM_FILE_ERROR_SECURITY); |
| 530 } | 533 } |
| 531 | 534 |
| 532 DCHECK(blob_url.is_valid()); | |
| 533 file_writer_delegate_.reset(new FileWriterDelegate( | 535 file_writer_delegate_.reset(new FileWriterDelegate( |
| 534 base::Bind(&LocalFileSystemOperation::DidWrite, | 536 base::Bind(&LocalFileSystemOperation::DidWrite, |
| 535 weak_factory_.GetWeakPtr(), url), | 537 weak_factory_.GetWeakPtr(), url), |
| 536 writer.Pass())); | 538 writer.Pass())); |
| 537 | 539 |
| 538 set_write_callback(callback); | 540 set_write_callback(callback); |
| 541 |
| 542 // Use a URLRequest to read the blob data that's to be written to the file. |
| 539 scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest( | 543 scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest( |
| 540 blob_url, file_writer_delegate_.get())); | 544 GURL("blob://see_user_data/"), file_writer_delegate_.get())); |
| 545 webkit_blob::BlobProtocolHandler::SetRequestedBlobDataHandle( |
| 546 blob_request.get(), |
| 547 blob_handle.Pass()); |
| 541 | 548 |
| 542 return base::Bind(&FileWriterDelegate::Start, | 549 return base::Bind(&FileWriterDelegate::Start, |
| 543 base::Unretained(file_writer_delegate_.get()), | 550 base::Unretained(file_writer_delegate_.get()), |
| 544 base::Passed(&blob_request)); | 551 base::Passed(&blob_request)); |
| 545 } | 552 } |
| 546 | 553 |
| 547 void LocalFileSystemOperation::DidFailWrite( | 554 void LocalFileSystemOperation::DidFailWrite( |
| 548 const WriteCallback& callback, | 555 const WriteCallback& callback, |
| 549 base::PlatformFileError result) { | 556 base::PlatformFileError result) { |
| 550 callback.Run(result, 0, false); | 557 callback.Run(result, 0, false); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 } | 812 } |
| 806 | 813 |
| 807 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 814 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
| 808 if (pending_operation_ != kOperationNone) | 815 if (pending_operation_ != kOperationNone) |
| 809 return false; | 816 return false; |
| 810 pending_operation_ = type; | 817 pending_operation_ = type; |
| 811 return true; | 818 return true; |
| 812 } | 819 } |
| 813 | 820 |
| 814 } // namespace fileapi | 821 } // namespace fileapi |
| OLD | NEW |