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

Side by Side Diff: webkit/fileapi/syncable/canned_syncable_file_system.cc

Issue 11416382: ********** Content tests with blob hacking. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 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/syncable/canned_syncable_file_system.h" 5 #include "webkit/fileapi/syncable/canned_syncable_file_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webkit/blob/blob_storage_context.h"
15 #include "webkit/blob/mock_blob_url_request_context.h" 16 #include "webkit/blob/mock_blob_url_request_context.h"
16 #include "webkit/fileapi/external_mount_points.h" 17 #include "webkit/fileapi/external_mount_points.h"
17 #include "webkit/fileapi/file_system_context.h" 18 #include "webkit/fileapi/file_system_context.h"
18 #include "webkit/fileapi/file_system_operation_context.h" 19 #include "webkit/fileapi/file_system_operation_context.h"
19 #include "webkit/fileapi/file_system_task_runners.h" 20 #include "webkit/fileapi/file_system_task_runners.h"
20 #include "webkit/fileapi/local_file_system_operation.h" 21 #include "webkit/fileapi/local_file_system_operation.h"
21 #include "webkit/fileapi/mock_file_system_options.h" 22 #include "webkit/fileapi/mock_file_system_options.h"
22 #include "webkit/fileapi/sandbox_mount_point_provider.h" 23 #include "webkit/fileapi/sandbox_mount_point_provider.h"
23 #include "webkit/fileapi/syncable/local_file_change_tracker.h" 24 #include "webkit/fileapi/syncable/local_file_change_tracker.h"
24 #include "webkit/fileapi/syncable/local_file_sync_context.h" 25 #include "webkit/fileapi/syncable/local_file_sync_context.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 DCHECK(platform_path_out); 118 DCHECK(platform_path_out);
118 *file_info_out = file_info; 119 *file_info_out = file_info;
119 *platform_path_out = platform_path; 120 *platform_path_out = platform_path;
120 callback.Run(result); 121 callback.Run(result);
121 } 122 }
122 123
123 class WriteHelper { 124 class WriteHelper {
124 public: 125 public:
125 WriteHelper() : bytes_written_(0) {} 126 WriteHelper() : bytes_written_(0) {}
126 WriteHelper(MockBlobURLRequestContext* request_context, 127 WriteHelper(MockBlobURLRequestContext* request_context,
127 const GURL& blob_url, 128 const std::string& blob_id,
128 const std::string& blob_data) 129 const std::string& blob_data)
129 : bytes_written_(0), 130 : bytes_written_(0),
130 request_context_(request_context), 131 request_context_(request_context),
131 blob_data_(new ScopedTextBlob(*request_context, blob_url, blob_data)) {} 132 blob_data_(new ScopedTextBlob(*request_context, blob_id, blob_data)) {}
132 133
133 ~WriteHelper() { 134 ~WriteHelper() {
134 if (request_context_) 135 if (request_context_)
135 MessageLoop::current()->DeleteSoon(FROM_HERE, request_context_.release()); 136 MessageLoop::current()->DeleteSoon(FROM_HERE, request_context_.release());
136 } 137 }
137 138
138 void DidWrite(const base::Callback<void(int64 result)>& completion_callback, 139 void DidWrite(const base::Callback<void(int64 result)>& completion_callback,
139 PlatformFileError error, int64 bytes, bool complete) { 140 PlatformFileError error, int64 bytes, bool complete) {
140 if (error == base::PLATFORM_FILE_OK) { 141 if (error == base::PLATFORM_FILE_OK) {
141 bytes_written_ += bytes; 142 bytes_written_ += bytes;
142 if (!complete) 143 if (!complete)
143 return; 144 return;
144 } 145 }
145 completion_callback.Run(error == base::PLATFORM_FILE_OK 146 completion_callback.Run(error == base::PLATFORM_FILE_OK
146 ? bytes_written_ : static_cast<int64>(error)); 147 ? bytes_written_ : static_cast<int64>(error));
147 } 148 }
148 149
150 ScopedTextBlob* scoped_text_blob() const { return blob_data_.get(); }
151
149 private: 152 private:
150 int64 bytes_written_; 153 int64 bytes_written_;
151 scoped_ptr<MockBlobURLRequestContext> request_context_; 154 scoped_ptr<MockBlobURLRequestContext> request_context_;
152 scoped_ptr<ScopedTextBlob> blob_data_; 155 scoped_ptr<ScopedTextBlob> blob_data_;
153 156
154 DISALLOW_COPY_AND_ASSIGN(WriteHelper); 157 DISALLOW_COPY_AND_ASSIGN(WriteHelper);
155 }; 158 };
156 159
157 void DidGetUsageAndQuota(const quota::StatusCallback& callback, 160 void DidGetUsageAndQuota(const quota::StatusCallback& callback,
158 int64* usage_out, int64* quota_out, 161 int64* usage_out, int64* quota_out,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 base::FilePath* platform_path) { 385 base::FilePath* platform_path) {
383 return RunOnThread<PlatformFileError>( 386 return RunOnThread<PlatformFileError>(
384 io_task_runner_, 387 io_task_runner_,
385 FROM_HERE, 388 FROM_HERE,
386 base::Bind(&CannedSyncableFileSystem::DoGetMetadata, 389 base::Bind(&CannedSyncableFileSystem::DoGetMetadata,
387 base::Unretained(this), url, info, platform_path)); 390 base::Unretained(this), url, info, platform_path));
388 } 391 }
389 392
390 int64 CannedSyncableFileSystem::Write( 393 int64 CannedSyncableFileSystem::Write(
391 net::URLRequestContext* url_request_context, 394 net::URLRequestContext* url_request_context,
392 const FileSystemURL& url, const GURL& blob_url) { 395 const FileSystemURL& url, scoped_ptr<webkit_blob::BlobDataHandle> blob_data_ handle) {
393 return RunOnThread<int64>( 396 return RunOnThread<int64>(
394 io_task_runner_, 397 io_task_runner_,
395 FROM_HERE, 398 FROM_HERE,
396 base::Bind(&CannedSyncableFileSystem::DoWrite, 399 base::Bind(&CannedSyncableFileSystem::DoWrite,
397 base::Unretained(this), url_request_context, url, blob_url)); 400 base::Unretained(this), url_request_context, url, base::Passed( &blob_data_handle)));
398 } 401 }
399 402
400 int64 CannedSyncableFileSystem::WriteString( 403 int64 CannedSyncableFileSystem::WriteString(
401 const FileSystemURL& url, const std::string& data) { 404 const FileSystemURL& url, const std::string& data) {
402 return RunOnThread<int64>( 405 return RunOnThread<int64>(
403 io_task_runner_, 406 io_task_runner_,
404 FROM_HERE, 407 FROM_HERE,
405 base::Bind(&CannedSyncableFileSystem::DoWriteString, 408 base::Bind(&CannedSyncableFileSystem::DoWriteString,
406 base::Unretained(this), url, data)); 409 base::Unretained(this), url, data));
407 } 410 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 base::PlatformFileInfo* info, 549 base::PlatformFileInfo* info,
547 base::FilePath* platform_path, 550 base::FilePath* platform_path,
548 const StatusCallback& callback) { 551 const StatusCallback& callback) {
549 EXPECT_TRUE(is_filesystem_opened_); 552 EXPECT_TRUE(is_filesystem_opened_);
550 NewOperation()->GetMetadata( 553 NewOperation()->GetMetadata(
551 url, base::Bind(&OnGetMetadata, info, platform_path, callback)); 554 url, base::Bind(&OnGetMetadata, info, platform_path, callback));
552 } 555 }
553 556
554 void CannedSyncableFileSystem::DoWrite( 557 void CannedSyncableFileSystem::DoWrite(
555 net::URLRequestContext* url_request_context, 558 net::URLRequestContext* url_request_context,
556 const FileSystemURL& url, const GURL& blob_url, 559 const FileSystemURL& url,
560 scoped_ptr<webkit_blob::BlobDataHandle> blob_data_handle,
557 const WriteCallback& callback) { 561 const WriteCallback& callback) {
558 EXPECT_TRUE(is_filesystem_opened_); 562 EXPECT_TRUE(is_filesystem_opened_);
559 WriteHelper* helper = new WriteHelper; 563 WriteHelper* helper = new WriteHelper;
560 NewOperation()->Write(url_request_context, url, blob_url, 0, 564 NewOperation()->Write(url_request_context, url, blob_data_handle.Pass(), 0,
561 base::Bind(&WriteHelper::DidWrite, 565 base::Bind(&WriteHelper::DidWrite,
562 base::Owned(helper), callback)); 566 base::Owned(helper), callback));
563 } 567 }
564 568
565 void CannedSyncableFileSystem::DoWriteString( 569 void CannedSyncableFileSystem::DoWriteString(
566 const FileSystemURL& url, 570 const FileSystemURL& url,
567 const std::string& data, 571 const std::string& data,
568 const WriteCallback& callback) { 572 const WriteCallback& callback) {
569 MockBlobURLRequestContext* url_request_context( 573 MockBlobURLRequestContext* url_request_context(
570 new MockBlobURLRequestContext(file_system_context_)); 574 new MockBlobURLRequestContext(file_system_context_));
571 const GURL blob_url(std::string("blob:") + data); 575 const std::string blob_id(std::string("blob:") + data);
572 WriteHelper* helper = new WriteHelper(url_request_context, blob_url, data); 576 WriteHelper* helper = new WriteHelper(url_request_context, blob_id, data);
573 NewOperation()->Write(url_request_context, url, blob_url, 0, 577 NewOperation()->Write(url_request_context, url,
578 helper->scoped_text_blob()->GetBlobDataHandle(), 0,
574 base::Bind(&WriteHelper::DidWrite, 579 base::Bind(&WriteHelper::DidWrite,
575 base::Owned(helper), callback)); 580 base::Owned(helper), callback));
576 } 581 }
577 582
578 void CannedSyncableFileSystem::DoGetUsageAndQuota( 583 void CannedSyncableFileSystem::DoGetUsageAndQuota(
579 int64* usage, 584 int64* usage,
580 int64* quota, 585 int64* quota,
581 const quota::StatusCallback& callback) { 586 const quota::StatusCallback& callback) {
582 quota_manager_->GetUsageAndQuota( 587 quota_manager_->GetUsageAndQuota(
583 origin_, storage_type(), 588 origin_, storage_type(),
(...skipping 13 matching lines...) Expand all
597 sync_status_ = status; 602 sync_status_ = status;
598 MessageLoop::current()->Quit(); 603 MessageLoop::current()->Quit();
599 } 604 }
600 605
601 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { 606 void CannedSyncableFileSystem::InitializeSyncStatusObserver() {
602 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); 607 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
603 file_system_context_->sync_context()->sync_status()->AddObserver(this); 608 file_system_context_->sync_context()->sync_status()->AddObserver(this);
604 } 609 }
605 610
606 } // namespace sync_file_system 611 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « webkit/fileapi/syncable/canned_syncable_file_system.h ('k') | webkit/fileapi/syncable/local_file_change_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698