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

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, 3 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 <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/guid.h"
13 #include "base/message_loop/message_loop_proxy.h" 14 #include "base/message_loop/message_loop_proxy.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
16 #include "base/task_runner_util.h" 17 #include "base/task_runner_util.h"
17 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" 18 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
18 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" 19 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
19 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" 20 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
20 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" 21 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "webkit/browser/blob/mock_blob_url_request_context.h" 23 #include "webkit/browser/blob/mock_blob_url_request_context.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 std::copy(entries.begin(), entries.end(), std::back_inserter(*entries_out)); 141 std::copy(entries.begin(), entries.end(), std::back_inserter(*entries_out));
141 142
142 if (!has_more) 143 if (!has_more)
143 callback.Run(error); 144 callback.Run(error);
144 } 145 }
145 146
146 class WriteHelper { 147 class WriteHelper {
147 public: 148 public:
148 WriteHelper() : bytes_written_(0) {} 149 WriteHelper() : bytes_written_(0) {}
149 WriteHelper(MockBlobURLRequestContext* request_context, 150 WriteHelper(MockBlobURLRequestContext* request_context,
150 const GURL& blob_url,
151 const std::string& blob_data) 151 const std::string& blob_data)
152 : bytes_written_(0), 152 : bytes_written_(0),
153 request_context_(request_context), 153 request_context_(request_context),
154 blob_data_(new ScopedTextBlob(*request_context, blob_url, blob_data)) {} 154 blob_data_(new ScopedTextBlob(*request_context,
155 base::GenerateGUID(),
156 blob_data)) {
157 }
155 158
156 ~WriteHelper() { 159 ~WriteHelper() {
157 if (request_context_) { 160 if (request_context_) {
158 base::MessageLoop::current()->DeleteSoon(FROM_HERE, 161 base::MessageLoop::current()->DeleteSoon(FROM_HERE,
159 request_context_.release()); 162 request_context_.release());
160 } 163 }
161 } 164 }
162 165
166 ScopedTextBlob* scoped_text_blob() const { return blob_data_.get(); }
167
163 void DidWrite(const base::Callback<void(int64 result)>& completion_callback, 168 void DidWrite(const base::Callback<void(int64 result)>& completion_callback,
164 PlatformFileError error, int64 bytes, bool complete) { 169 PlatformFileError error, int64 bytes, bool complete) {
165 if (error == base::PLATFORM_FILE_OK) { 170 if (error == base::PLATFORM_FILE_OK) {
166 bytes_written_ += bytes; 171 bytes_written_ += bytes;
167 if (!complete) 172 if (!complete)
168 return; 173 return;
169 } 174 }
170 completion_callback.Run(error == base::PLATFORM_FILE_OK 175 completion_callback.Run(error == base::PLATFORM_FILE_OK
171 ? bytes_written_ : static_cast<int64>(error)); 176 ? bytes_written_ : static_cast<int64>(error));
172 } 177 }
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 io_task_runner_.get(), 446 io_task_runner_.get(),
442 FROM_HERE, 447 FROM_HERE,
443 base::Bind(&CannedSyncableFileSystem::DoReadDirectory, 448 base::Bind(&CannedSyncableFileSystem::DoReadDirectory,
444 base::Unretained(this), 449 base::Unretained(this),
445 url, 450 url,
446 entries)); 451 entries));
447 } 452 }
448 453
449 int64 CannedSyncableFileSystem::Write( 454 int64 CannedSyncableFileSystem::Write(
450 net::URLRequestContext* url_request_context, 455 net::URLRequestContext* url_request_context,
451 const FileSystemURL& url, const GURL& blob_url) { 456 const FileSystemURL& url,
457 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle) {
452 return RunOnThread<int64>(io_task_runner_.get(), 458 return RunOnThread<int64>(io_task_runner_.get(),
453 FROM_HERE, 459 FROM_HERE,
454 base::Bind(&CannedSyncableFileSystem::DoWrite, 460 base::Bind(&CannedSyncableFileSystem::DoWrite,
455 base::Unretained(this), 461 base::Unretained(this),
456 url_request_context, 462 url_request_context,
457 url, 463 url,
458 blob_url)); 464 base::Passed(&blob_data_handle)));
459 } 465 }
460 466
461 int64 CannedSyncableFileSystem::WriteString( 467 int64 CannedSyncableFileSystem::WriteString(
462 const FileSystemURL& url, const std::string& data) { 468 const FileSystemURL& url, const std::string& data) {
463 return RunOnThread<int64>(io_task_runner_.get(), 469 return RunOnThread<int64>(io_task_runner_.get(),
464 FROM_HERE, 470 FROM_HERE,
465 base::Bind(&CannedSyncableFileSystem::DoWriteString, 471 base::Bind(&CannedSyncableFileSystem::DoWriteString,
466 base::Unretained(this), 472 base::Unretained(this),
467 url, 473 url,
468 data)); 474 data));
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 const FileSystemURL& url, 625 const FileSystemURL& url,
620 FileEntryList* entries, 626 FileEntryList* entries,
621 const StatusCallback& callback) { 627 const StatusCallback& callback) {
622 EXPECT_TRUE(is_filesystem_opened_); 628 EXPECT_TRUE(is_filesystem_opened_);
623 operation_runner()->ReadDirectory( 629 operation_runner()->ReadDirectory(
624 url, base::Bind(&OnReadDirectory, entries, callback)); 630 url, base::Bind(&OnReadDirectory, entries, callback));
625 } 631 }
626 632
627 void CannedSyncableFileSystem::DoWrite( 633 void CannedSyncableFileSystem::DoWrite(
628 net::URLRequestContext* url_request_context, 634 net::URLRequestContext* url_request_context,
629 const FileSystemURL& url, const GURL& blob_url, 635 const FileSystemURL& url,
636 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle,
630 const WriteCallback& callback) { 637 const WriteCallback& callback) {
631 EXPECT_TRUE(is_filesystem_opened_); 638 EXPECT_TRUE(is_filesystem_opened_);
632 WriteHelper* helper = new WriteHelper; 639 WriteHelper* helper = new WriteHelper;
633 operation_runner()->Write(url_request_context, url, blob_url, 0, 640 operation_runner()->Write(url_request_context, url,
641 blob_data_handle.Pass(), 0,
634 base::Bind(&WriteHelper::DidWrite, 642 base::Bind(&WriteHelper::DidWrite,
635 base::Owned(helper), callback)); 643 base::Owned(helper), callback));
636 } 644 }
637 645
638 void CannedSyncableFileSystem::DoWriteString( 646 void CannedSyncableFileSystem::DoWriteString(
639 const FileSystemURL& url, 647 const FileSystemURL& url,
640 const std::string& data, 648 const std::string& data,
641 const WriteCallback& callback) { 649 const WriteCallback& callback) {
642 MockBlobURLRequestContext* url_request_context( 650 MockBlobURLRequestContext* url_request_context(
643 new MockBlobURLRequestContext(file_system_context_.get())); 651 new MockBlobURLRequestContext(file_system_context_.get()));
644 const GURL blob_url(std::string("blob:") + data); 652 WriteHelper* helper = new WriteHelper(url_request_context, data);
645 WriteHelper* helper = new WriteHelper(url_request_context, blob_url, data); 653 operation_runner()->Write(url_request_context, url,
646 operation_runner()->Write(url_request_context, url, blob_url, 0, 654 helper->scoped_text_blob()->GetBlobDataHandle(), 0,
647 base::Bind(&WriteHelper::DidWrite, 655 base::Bind(&WriteHelper::DidWrite,
648 base::Owned(helper), callback)); 656 base::Owned(helper), callback));
649 } 657 }
650 658
651 void CannedSyncableFileSystem::DoGetUsageAndQuota( 659 void CannedSyncableFileSystem::DoGetUsageAndQuota(
652 int64* usage, 660 int64* usage,
653 int64* quota, 661 int64* quota,
654 const quota::StatusCallback& callback) { 662 const quota::StatusCallback& callback) {
655 quota_manager_->GetUsageAndQuota( 663 quota_manager_->GetUsageAndQuota(
656 origin_, storage_type(), 664 origin_, storage_type(),
(...skipping 13 matching lines...) Expand all
670 sync_status_ = status; 678 sync_status_ = status;
671 base::MessageLoop::current()->Quit(); 679 base::MessageLoop::current()->Quit();
672 } 680 }
673 681
674 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { 682 void CannedSyncableFileSystem::InitializeSyncStatusObserver() {
675 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); 683 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
676 backend()->sync_context()->sync_status()->AddObserver(this); 684 backend()->sync_context()->sync_status()->AddObserver(this);
677 } 685 }
678 686
679 } // namespace sync_file_system 687 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698