Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

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

Issue 14520026: webkit: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 7 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"
(...skipping 22 matching lines...) Expand all
33 using fileapi::FileSystemURL; 33 using fileapi::FileSystemURL;
34 using fileapi::FileSystemURLSet; 34 using fileapi::FileSystemURLSet;
35 using quota::QuotaManager; 35 using quota::QuotaManager;
36 using webkit_blob::MockBlobURLRequestContext; 36 using webkit_blob::MockBlobURLRequestContext;
37 using webkit_blob::ScopedTextBlob; 37 using webkit_blob::ScopedTextBlob;
38 38
39 namespace sync_file_system { 39 namespace sync_file_system {
40 40
41 namespace { 41 namespace {
42 42
43 void Quit() { MessageLoop::current()->Quit(); } 43 void Quit() { base::MessageLoop::current()->Quit(); }
44 44
45 template <typename R> 45 template <typename R>
46 void AssignAndQuit(base::TaskRunner* original_task_runner, 46 void AssignAndQuit(base::TaskRunner* original_task_runner,
47 R* result_out, R result) { 47 R* result_out, R result) {
48 DCHECK(result_out); 48 DCHECK(result_out);
49 *result_out = result; 49 *result_out = result;
50 original_task_runner->PostTask(FROM_HERE, base::Bind(&Quit)); 50 original_task_runner->PostTask(FROM_HERE, base::Bind(&Quit));
51 } 51 }
52 52
53 template <typename R> 53 template <typename R>
54 R RunOnThread( 54 R RunOnThread(
55 base::SingleThreadTaskRunner* task_runner, 55 base::SingleThreadTaskRunner* task_runner,
56 const tracked_objects::Location& location, 56 const tracked_objects::Location& location,
57 const base::Callback<void(const base::Callback<void(R)>& callback)>& task) { 57 const base::Callback<void(const base::Callback<void(R)>& callback)>& task) {
58 R result; 58 R result;
59 task_runner->PostTask( 59 task_runner->PostTask(
60 location, 60 location,
61 base::Bind(task, base::Bind(&AssignAndQuit<R>, 61 base::Bind(task, base::Bind(&AssignAndQuit<R>,
62 base::MessageLoopProxy::current(), 62 base::MessageLoopProxy::current(),
63 &result))); 63 &result)));
64 MessageLoop::current()->Run(); 64 base::MessageLoop::current()->Run();
65 return result; 65 return result;
66 } 66 }
67 67
68 void RunOnThread(base::SingleThreadTaskRunner* task_runner, 68 void RunOnThread(base::SingleThreadTaskRunner* task_runner,
69 const tracked_objects::Location& location, 69 const tracked_objects::Location& location,
70 const base::Closure& task) { 70 const base::Closure& task) {
71 task_runner->PostTaskAndReply( 71 task_runner->PostTaskAndReply(
72 location, task, 72 location, task,
73 base::Bind(base::IgnoreResult( 73 base::Bind(base::IgnoreResult(
74 base::Bind(&base::MessageLoopProxy::PostTask, 74 base::Bind(&base::MessageLoopProxy::PostTask,
75 base::MessageLoopProxy::current(), 75 base::MessageLoopProxy::current(),
76 FROM_HERE, base::Bind(&Quit))))); 76 FROM_HERE, base::Bind(&Quit)))));
77 MessageLoop::current()->Run(); 77 base::MessageLoop::current()->Run();
78 } 78 }
79 79
80 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) { 80 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) {
81 EXPECT_TRUE(runner->RunsTasksOnCurrentThread()); 81 EXPECT_TRUE(runner->RunsTasksOnCurrentThread());
82 } 82 }
83 83
84 void VerifySameTaskRunner( 84 void VerifySameTaskRunner(
85 base::SingleThreadTaskRunner* runner1, 85 base::SingleThreadTaskRunner* runner1,
86 base::SingleThreadTaskRunner* runner2) { 86 base::SingleThreadTaskRunner* runner2) {
87 ASSERT_TRUE(runner1 != NULL); 87 ASSERT_TRUE(runner1 != NULL);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 public: 126 public:
127 WriteHelper() : bytes_written_(0) {} 127 WriteHelper() : bytes_written_(0) {}
128 WriteHelper(MockBlobURLRequestContext* request_context, 128 WriteHelper(MockBlobURLRequestContext* request_context,
129 const GURL& blob_url, 129 const GURL& blob_url,
130 const std::string& blob_data) 130 const std::string& blob_data)
131 : bytes_written_(0), 131 : bytes_written_(0),
132 request_context_(request_context), 132 request_context_(request_context),
133 blob_data_(new ScopedTextBlob(*request_context, blob_url, blob_data)) {} 133 blob_data_(new ScopedTextBlob(*request_context, blob_url, blob_data)) {}
134 134
135 ~WriteHelper() { 135 ~WriteHelper() {
136 if (request_context_) 136 if (request_context_)
brettw 2013/05/06 17:43:33 Can you add {} for this (since it's multi-line)?
xhwang 2013/05/07 00:11:07 Done.
137 MessageLoop::current()->DeleteSoon(FROM_HERE, request_context_.release()); 137 base::MessageLoop::current()->DeleteSoon(FROM_HERE,
138 request_context_.release());
138 } 139 }
139 140
140 void DidWrite(const base::Callback<void(int64 result)>& completion_callback, 141 void DidWrite(const base::Callback<void(int64 result)>& completion_callback,
141 PlatformFileError error, int64 bytes, bool complete) { 142 PlatformFileError error, int64 bytes, bool complete) {
142 if (error == base::PLATFORM_FILE_OK) { 143 if (error == base::PLATFORM_FILE_OK) {
143 bytes_written_ += bytes; 144 bytes_written_ += bytes;
144 if (!complete) 145 if (!complete)
145 return; 146 return;
146 } 147 }
147 completion_callback.Run(error == base::PLATFORM_FILE_OK 148 completion_callback.Run(error == base::PLATFORM_FILE_OK
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return file_system_context_->CrackURL(url); 244 return file_system_context_->CrackURL(url);
244 } 245 }
245 246
246 PlatformFileError CannedSyncableFileSystem::OpenFileSystem() { 247 PlatformFileError CannedSyncableFileSystem::OpenFileSystem() {
247 EXPECT_TRUE(is_filesystem_set_up_); 248 EXPECT_TRUE(is_filesystem_set_up_);
248 EXPECT_FALSE(is_filesystem_opened_); 249 EXPECT_FALSE(is_filesystem_opened_);
249 file_system_context_->OpenSyncableFileSystem( 250 file_system_context_->OpenSyncableFileSystem(
250 service_name_, origin_, type_, true /* create */, 251 service_name_, origin_, type_, true /* create */,
251 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, 252 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem,
252 base::Unretained(this))); 253 base::Unretained(this)));
253 MessageLoop::current()->Run(); 254 base::MessageLoop::current()->Run();
254 if (file_system_context_->sync_context()) { 255 if (file_system_context_->sync_context()) {
255 // Register 'this' as a sync status observer. 256 // Register 'this' as a sync status observer.
256 RunOnThread(io_task_runner_, 257 RunOnThread(io_task_runner_,
257 FROM_HERE, 258 FROM_HERE,
258 base::Bind( 259 base::Bind(
259 &CannedSyncableFileSystem::InitializeSyncStatusObserver, 260 &CannedSyncableFileSystem::InitializeSyncStatusObserver,
260 base::Unretained(this))); 261 base::Unretained(this)));
261 } 262 }
262 return result_; 263 return result_;
263 } 264 }
(...skipping 10 matching lines...) Expand all
274 275
275 SyncStatusCode CannedSyncableFileSystem::MaybeInitializeFileSystemContext( 276 SyncStatusCode CannedSyncableFileSystem::MaybeInitializeFileSystemContext(
276 LocalFileSyncContext* sync_context) { 277 LocalFileSyncContext* sync_context) {
277 DCHECK(sync_context); 278 DCHECK(sync_context);
278 sync_status_ = sync_file_system::SYNC_STATUS_UNKNOWN; 279 sync_status_ = sync_file_system::SYNC_STATUS_UNKNOWN;
279 VerifySameTaskRunner(io_task_runner_, sync_context->io_task_runner_); 280 VerifySameTaskRunner(io_task_runner_, sync_context->io_task_runner_);
280 sync_context->MaybeInitializeFileSystemContext( 281 sync_context->MaybeInitializeFileSystemContext(
281 origin_, service_name_, file_system_context_, 282 origin_, service_name_, file_system_context_,
282 base::Bind(&CannedSyncableFileSystem::DidInitializeFileSystemContext, 283 base::Bind(&CannedSyncableFileSystem::DidInitializeFileSystemContext,
283 base::Unretained(this))); 284 base::Unretained(this)));
284 MessageLoop::current()->Run(); 285 base::MessageLoop::current()->Run();
285 return sync_status_; 286 return sync_status_;
286 } 287 }
287 288
288 PlatformFileError CannedSyncableFileSystem::CreateDirectory( 289 PlatformFileError CannedSyncableFileSystem::CreateDirectory(
289 const FileSystemURL& url) { 290 const FileSystemURL& url) {
290 return RunOnThread<PlatformFileError>( 291 return RunOnThread<PlatformFileError>(
291 io_task_runner_, 292 io_task_runner_,
292 FROM_HERE, 293 FROM_HERE,
293 base::Bind(&CannedSyncableFileSystem::DoCreateDirectory, 294 base::Bind(&CannedSyncableFileSystem::DoCreateDirectory,
294 base::Unretained(this), url)); 295 base::Unretained(this), url));
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 quota_manager_->GetUsageAndQuota( 581 quota_manager_->GetUsageAndQuota(
581 origin_, storage_type(), 582 origin_, storage_type(),
582 base::Bind(&DidGetUsageAndQuota, callback, usage, quota)); 583 base::Bind(&DidGetUsageAndQuota, callback, usage, quota));
583 } 584 }
584 585
585 void CannedSyncableFileSystem::DidOpenFileSystem( 586 void CannedSyncableFileSystem::DidOpenFileSystem(
586 PlatformFileError result, const std::string& name, const GURL& root) { 587 PlatformFileError result, const std::string& name, const GURL& root) {
587 result_ = result; 588 result_ = result;
588 root_url_ = root; 589 root_url_ = root;
589 is_filesystem_opened_ = true; 590 is_filesystem_opened_ = true;
590 MessageLoop::current()->Quit(); 591 base::MessageLoop::current()->Quit();
591 } 592 }
592 593
593 void CannedSyncableFileSystem::DidInitializeFileSystemContext( 594 void CannedSyncableFileSystem::DidInitializeFileSystemContext(
594 SyncStatusCode status) { 595 SyncStatusCode status) {
595 sync_status_ = status; 596 sync_status_ = status;
596 MessageLoop::current()->Quit(); 597 base::MessageLoop::current()->Quit();
597 } 598 }
598 599
599 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { 600 void CannedSyncableFileSystem::InitializeSyncStatusObserver() {
600 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); 601 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
601 file_system_context_->sync_context()->sync_status()->AddObserver(this); 602 file_system_context_->sync_context()->sync_status()->AddObserver(this);
602 } 603 }
603 604
604 } // namespace sync_file_system 605 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698