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

Side by Side Diff: chrome/browser/sync_file_system/local/canned_syncable_file_system.cc

Issue 23223003: Chromium Blob hacking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 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 "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" 5 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 std::copy(entries.begin(), entries.end(), std::back_inserter(*entries_out)); 139 std::copy(entries.begin(), entries.end(), std::back_inserter(*entries_out));
140 140
141 if (!has_more) 141 if (!has_more)
142 callback.Run(error); 142 callback.Run(error);
143 } 143 }
144 144
145 class WriteHelper { 145 class WriteHelper {
146 public: 146 public:
147 WriteHelper() : bytes_written_(0) {} 147 WriteHelper() : bytes_written_(0) {}
148 WriteHelper(MockBlobURLRequestContext* request_context, 148 WriteHelper(MockBlobURLRequestContext* request_context,
149 const GURL& blob_url, 149 const std::string& blob_id,
150 const std::string& blob_data) 150 const std::string& blob_data)
151 : bytes_written_(0), 151 : bytes_written_(0),
152 request_context_(request_context), 152 request_context_(request_context),
153 blob_data_(new ScopedTextBlob(*request_context, blob_url, blob_data)) {} 153 blob_data_(new ScopedTextBlob(*request_context, blob_id, blob_data)) {}
154 154
155 ~WriteHelper() { 155 ~WriteHelper() {
156 if (request_context_) { 156 if (request_context_) {
157 base::MessageLoop::current()->DeleteSoon(FROM_HERE, 157 base::MessageLoop::current()->DeleteSoon(FROM_HERE,
158 request_context_.release()); 158 request_context_.release());
159 } 159 }
160 } 160 }
161 161
162 ScopedTextBlob* scoped_text_blob() const { return blob_data_.get(); }
163
162 void DidWrite(const base::Callback<void(int64 result)>& completion_callback, 164 void DidWrite(const base::Callback<void(int64 result)>& completion_callback,
163 PlatformFileError error, int64 bytes, bool complete) { 165 PlatformFileError error, int64 bytes, bool complete) {
164 if (error == base::PLATFORM_FILE_OK) { 166 if (error == base::PLATFORM_FILE_OK) {
165 bytes_written_ += bytes; 167 bytes_written_ += bytes;
166 if (!complete) 168 if (!complete)
167 return; 169 return;
168 } 170 }
169 completion_callback.Run(error == base::PLATFORM_FILE_OK 171 completion_callback.Run(error == base::PLATFORM_FILE_OK
170 ? bytes_written_ : static_cast<int64>(error)); 172 ? bytes_written_ : static_cast<int64>(error));
171 } 173 }
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 io_task_runner_.get(), 442 io_task_runner_.get(),
441 FROM_HERE, 443 FROM_HERE,
442 base::Bind(&CannedSyncableFileSystem::DoReadDirectory, 444 base::Bind(&CannedSyncableFileSystem::DoReadDirectory,
443 base::Unretained(this), 445 base::Unretained(this),
444 url, 446 url,
445 entries)); 447 entries));
446 } 448 }
447 449
448 int64 CannedSyncableFileSystem::Write( 450 int64 CannedSyncableFileSystem::Write(
449 net::URLRequestContext* url_request_context, 451 net::URLRequestContext* url_request_context,
450 const FileSystemURL& url, const GURL& blob_url) { 452 const FileSystemURL& url,
453 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle) {
451 return RunOnThread<int64>(io_task_runner_.get(), 454 return RunOnThread<int64>(io_task_runner_.get(),
452 FROM_HERE, 455 FROM_HERE,
453 base::Bind(&CannedSyncableFileSystem::DoWrite, 456 base::Bind(&CannedSyncableFileSystem::DoWrite,
454 base::Unretained(this), 457 base::Unretained(this),
455 url_request_context, 458 url_request_context,
456 url, 459 url,
457 blob_url)); 460 base::Passed(&blob_data_handle)));
458 } 461 }
459 462
460 int64 CannedSyncableFileSystem::WriteString( 463 int64 CannedSyncableFileSystem::WriteString(
461 const FileSystemURL& url, const std::string& data) { 464 const FileSystemURL& url, const std::string& data) {
462 return RunOnThread<int64>(io_task_runner_.get(), 465 return RunOnThread<int64>(io_task_runner_.get(),
463 FROM_HERE, 466 FROM_HERE,
464 base::Bind(&CannedSyncableFileSystem::DoWriteString, 467 base::Bind(&CannedSyncableFileSystem::DoWriteString,
465 base::Unretained(this), 468 base::Unretained(this),
466 url, 469 url,
467 data)); 470 data));
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 const FileSystemURL& url, 621 const FileSystemURL& url,
619 FileEntryList* entries, 622 FileEntryList* entries,
620 const StatusCallback& callback) { 623 const StatusCallback& callback) {
621 EXPECT_TRUE(is_filesystem_opened_); 624 EXPECT_TRUE(is_filesystem_opened_);
622 operation_runner()->ReadDirectory( 625 operation_runner()->ReadDirectory(
623 url, base::Bind(&OnReadDirectory, entries, callback)); 626 url, base::Bind(&OnReadDirectory, entries, callback));
624 } 627 }
625 628
626 void CannedSyncableFileSystem::DoWrite( 629 void CannedSyncableFileSystem::DoWrite(
627 net::URLRequestContext* url_request_context, 630 net::URLRequestContext* url_request_context,
628 const FileSystemURL& url, const GURL& blob_url, 631 const FileSystemURL& url,
632 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle,
629 const WriteCallback& callback) { 633 const WriteCallback& callback) {
630 EXPECT_TRUE(is_filesystem_opened_); 634 EXPECT_TRUE(is_filesystem_opened_);
631 WriteHelper* helper = new WriteHelper; 635 WriteHelper* helper = new WriteHelper;
632 operation_runner()->Write(url_request_context, url, blob_url, 0, 636 operation_runner()->Write(url_request_context, url,
637 blob_data_handle.Pass(), 0,
633 base::Bind(&WriteHelper::DidWrite, 638 base::Bind(&WriteHelper::DidWrite,
634 base::Owned(helper), callback)); 639 base::Owned(helper), callback));
635 } 640 }
636 641
637 void CannedSyncableFileSystem::DoWriteString( 642 void CannedSyncableFileSystem::DoWriteString(
638 const FileSystemURL& url, 643 const FileSystemURL& url,
639 const std::string& data, 644 const std::string& data,
640 const WriteCallback& callback) { 645 const WriteCallback& callback) {
641 MockBlobURLRequestContext* url_request_context( 646 MockBlobURLRequestContext* url_request_context(
642 new MockBlobURLRequestContext(file_system_context_.get())); 647 new MockBlobURLRequestContext(file_system_context_.get()));
643 const GURL blob_url(std::string("blob:") + data); 648 const std::string blob_id(std::string("blob:") + data);
ericu 2013/08/21 23:26:09 What's this blob_id for? Why are you putting the
michaeln 2013/08/27 23:24:06 Done.
644 WriteHelper* helper = new WriteHelper(url_request_context, blob_url, data); 649 WriteHelper* helper = new WriteHelper(url_request_context, blob_id, data);
645 operation_runner()->Write(url_request_context, url, blob_url, 0, 650 operation_runner()->Write(url_request_context, url,
651 helper->scoped_text_blob()->GetBlobDataHandle(), 0,
646 base::Bind(&WriteHelper::DidWrite, 652 base::Bind(&WriteHelper::DidWrite,
647 base::Owned(helper), callback)); 653 base::Owned(helper), callback));
648 } 654 }
649 655
650 void CannedSyncableFileSystem::DoGetUsageAndQuota( 656 void CannedSyncableFileSystem::DoGetUsageAndQuota(
651 int64* usage, 657 int64* usage,
652 int64* quota, 658 int64* quota,
653 const quota::StatusCallback& callback) { 659 const quota::StatusCallback& callback) {
654 quota_manager_->GetUsageAndQuota( 660 quota_manager_->GetUsageAndQuota(
655 origin_, storage_type(), 661 origin_, storage_type(),
(...skipping 13 matching lines...) Expand all
669 sync_status_ = status; 675 sync_status_ = status;
670 base::MessageLoop::current()->Quit(); 676 base::MessageLoop::current()->Quit();
671 } 677 }
672 678
673 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { 679 void CannedSyncableFileSystem::InitializeSyncStatusObserver() {
674 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); 680 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
675 backend()->sync_context()->sync_status()->AddObserver(this); 681 backend()->sync_context()->sync_status()->AddObserver(this);
676 } 682 }
677 683
678 } // namespace sync_file_system 684 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698