Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: webkit/fileapi/local_file_system_operation.cc

Issue 11410019: ********** Chromium Blob hacking (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/async_file_util.h" 16 #include "webkit/fileapi/async_file_util.h"
15 #include "webkit/fileapi/cross_operation_delegate.h" 17 #include "webkit/fileapi/cross_operation_delegate.h"
16 #include "webkit/fileapi/file_observers.h" 18 #include "webkit/fileapi/file_observers.h"
17 #include "webkit/fileapi/file_system_context.h" 19 #include "webkit/fileapi/file_system_context.h"
18 #include "webkit/fileapi/file_system_mount_point_provider.h" 20 #include "webkit/fileapi/file_system_mount_point_provider.h"
19 #include "webkit/fileapi/file_system_task_runners.h" 21 #include "webkit/fileapi/file_system_task_runners.h"
20 #include "webkit/fileapi/file_system_types.h" 22 #include "webkit/fileapi/file_system_types.h"
21 #include "webkit/fileapi/file_system_url.h" 23 #include "webkit/fileapi/file_system_url.h"
22 #include "webkit/fileapi/file_system_util.h" 24 #include "webkit/fileapi/file_system_util.h"
23 #include "webkit/fileapi/file_writer_delegate.h" 25 #include "webkit/fileapi/file_writer_delegate.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 base::Unretained(this), callback))); 243 base::Unretained(this), callback)));
242 if (recursive) 244 if (recursive)
243 recursive_operation_delegate_->RunRecursively(); 245 recursive_operation_delegate_->RunRecursively();
244 else 246 else
245 recursive_operation_delegate_->Run(); 247 recursive_operation_delegate_->Run();
246 } 248 }
247 249
248 void LocalFileSystemOperation::Write( 250 void LocalFileSystemOperation::Write(
249 const net::URLRequestContext* url_request_context, 251 const net::URLRequestContext* url_request_context,
250 const FileSystemURL& url, 252 const FileSystemURL& url,
251 const GURL& blob_url, 253 scoped_ptr<webkit_blob::BlobDataHandle> blob,
252 int64 offset, 254 int64 offset,
253 const WriteCallback& callback) { 255 const WriteCallback& callback) {
254 GetWriteClosure(url_request_context, url, blob_url, offset, callback).Run(); 256 GetWriteClosure(url_request_context, url, blob.Pass(), offset, callback)
257 .Run();
255 } 258 }
256 259
257 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length, 260 void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length,
258 const StatusCallback& callback) { 261 const StatusCallback& callback) {
259 DCHECK(SetPendingOperationType(kOperationTruncate)); 262 DCHECK(SetPendingOperationType(kOperationTruncate));
260 263
261 base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE); 264 base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
262 if (result != base::PLATFORM_FILE_OK) { 265 if (result != base::PLATFORM_FILE_OK) {
263 callback.Run(result); 266 callback.Run(result);
264 delete this; 267 delete this;
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 return; 580 return;
578 } 581 }
579 582
580 operation_context()->set_allowed_bytes_growth(quota - usage); 583 operation_context()->set_allowed_bytes_growth(quota - usage);
581 task.Run(); 584 task.Run();
582 } 585 }
583 586
584 base::Closure LocalFileSystemOperation::GetWriteClosure( 587 base::Closure LocalFileSystemOperation::GetWriteClosure(
585 const net::URLRequestContext* url_request_context, 588 const net::URLRequestContext* url_request_context,
586 const FileSystemURL& url, 589 const FileSystemURL& url,
587 const GURL& blob_url, 590 scoped_ptr<webkit_blob::BlobDataHandle> blob_handle,
588 int64 offset, 591 int64 offset,
589 const WriteCallback& callback) { 592 const WriteCallback& callback) {
590 DCHECK(SetPendingOperationType(kOperationWrite)); 593 DCHECK(SetPendingOperationType(kOperationWrite));
591 594
592 base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE); 595 base::PlatformFileError result = SetUp(url, SETUP_FOR_WRITE);
593 if (result != base::PLATFORM_FILE_OK) { 596 if (result != base::PLATFORM_FILE_OK) {
594 return base::Bind(&LocalFileSystemOperation::DidFailWrite, 597 return base::Bind(&LocalFileSystemOperation::DidFailWrite,
595 base::Owned(this), callback, result); 598 base::Owned(this), callback, result);
596 } 599 }
597 600
598 FileSystemMountPointProvider* provider = file_system_context()-> 601 FileSystemMountPointProvider* provider = file_system_context()->
599 GetMountPointProvider(url.type()); 602 GetMountPointProvider(url.type());
600 DCHECK(provider); 603 DCHECK(provider);
601 scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter( 604 scoped_ptr<FileStreamWriter> writer(provider->CreateFileStreamWriter(
602 url, offset, file_system_context())); 605 url, offset, file_system_context()));
603 606
604 if (!writer.get()) { 607 if (!writer.get()) {
605 // Write is not supported. 608 // Write is not supported.
606 return base::Bind(&LocalFileSystemOperation::DidFailWrite, 609 return base::Bind(&LocalFileSystemOperation::DidFailWrite,
607 base::Owned(this), callback, 610 base::Owned(this), callback,
608 base::PLATFORM_FILE_ERROR_SECURITY); 611 base::PLATFORM_FILE_ERROR_SECURITY);
609 } 612 }
610 613
611 DCHECK(blob_url.is_valid());
612 file_writer_delegate_.reset(new FileWriterDelegate( 614 file_writer_delegate_.reset(new FileWriterDelegate(
613 base::Bind(&LocalFileSystemOperation::DidWrite, 615 base::Bind(&LocalFileSystemOperation::DidWrite,
614 weak_factory_.GetWeakPtr(), url), 616 weak_factory_.GetWeakPtr(), url),
615 writer.Pass())); 617 writer.Pass()));
616 618
617 write_callback_ = callback; 619 write_callback_ = callback;
620
621 // Use a URLRequest to read the blob data that's to be written to the file.
618 scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest( 622 scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest(
619 blob_url, file_writer_delegate_.get())); 623 GURL("blob://see_user_data/"), file_writer_delegate_.get()));
624 webkit_blob::BlobProtocolHandler::SetRequestedBlobDataHandle(
625 blob_request.get(),
626 blob_handle.Pass());
620 627
621 return base::Bind(&FileWriterDelegate::Start, 628 return base::Bind(&FileWriterDelegate::Start,
622 base::Unretained(file_writer_delegate_.get()), 629 base::Unretained(file_writer_delegate_.get()),
623 base::Passed(&blob_request)); 630 base::Passed(&blob_request));
624 } 631 }
625 632
626 void LocalFileSystemOperation::DidFailWrite( 633 void LocalFileSystemOperation::DidFailWrite(
627 const WriteCallback& callback, 634 const WriteCallback& callback,
628 base::PlatformFileError result) { 635 base::PlatformFileError result) {
629 callback.Run(result, 0, false); 636 callback.Run(result, 0, false);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 } 868 }
862 869
863 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { 870 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) {
864 if (pending_operation_ != kOperationNone) 871 if (pending_operation_ != kOperationNone)
865 return false; 872 return false;
866 pending_operation_ = type; 873 pending_operation_ = type;
867 return true; 874 return true;
868 } 875 }
869 876
870 } // namespace fileapi 877 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/local_file_system_operation.h ('k') | webkit/fileapi/syncable/syncable_file_system_operation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698