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

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

Issue 1815363002: Add RetainedRef uses where needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <iterator> 9 #include <iterator>
10 #include <utility> 10 #include <utility>
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 template <typename R> 62 template <typename R>
63 R RunOnThread( 63 R RunOnThread(
64 base::SingleThreadTaskRunner* task_runner, 64 base::SingleThreadTaskRunner* task_runner,
65 const tracked_objects::Location& location, 65 const tracked_objects::Location& location,
66 const base::Callback<void(const base::Callback<void(R)>& callback)>& task) { 66 const base::Callback<void(const base::Callback<void(R)>& callback)>& task) {
67 R result; 67 R result;
68 base::RunLoop run_loop; 68 base::RunLoop run_loop;
69 task_runner->PostTask( 69 task_runner->PostTask(
70 location, 70 location,
71 base::Bind(task, base::Bind(&AssignAndQuit<R>, 71 base::Bind(task, base::Bind(&AssignAndQuit<R>,
72 base::ThreadTaskRunnerHandle::Get(), 72 base::RetainedRef(
73 run_loop.QuitClosure(), 73 base::ThreadTaskRunnerHandle::Get()),
74 &result))); 74 run_loop.QuitClosure(), &result)));
75 run_loop.Run(); 75 run_loop.Run();
76 return result; 76 return result;
77 } 77 }
78 78
79 void RunOnThread(base::SingleThreadTaskRunner* task_runner, 79 void RunOnThread(base::SingleThreadTaskRunner* task_runner,
80 const tracked_objects::Location& location, 80 const tracked_objects::Location& location,
81 const base::Closure& task) { 81 const base::Closure& task) {
82 base::RunLoop run_loop; 82 base::RunLoop run_loop;
83 task_runner->PostTaskAndReply( 83 task_runner->PostTaskAndReply(
84 location, task, 84 location, task,
85 base::Bind(base::IgnoreResult( 85 base::Bind(base::IgnoreResult(
86 base::Bind(&base::SingleThreadTaskRunner::PostTask, 86 base::Bind(&base::SingleThreadTaskRunner::PostTask,
87 base::ThreadTaskRunnerHandle::Get(), 87 base::ThreadTaskRunnerHandle::Get(),
88 FROM_HERE, run_loop.QuitClosure())))); 88 FROM_HERE, run_loop.QuitClosure()))));
89 run_loop.Run(); 89 run_loop.Run();
90 } 90 }
91 91
92 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) { 92 void EnsureRunningOn(base::SingleThreadTaskRunner* runner) {
93 EXPECT_TRUE(runner->RunsTasksOnCurrentThread()); 93 EXPECT_TRUE(runner->RunsTasksOnCurrentThread());
94 } 94 }
95 95
96 void VerifySameTaskRunner( 96 void VerifySameTaskRunner(
97 base::SingleThreadTaskRunner* runner1, 97 base::SingleThreadTaskRunner* runner1,
98 base::SingleThreadTaskRunner* runner2) { 98 base::SingleThreadTaskRunner* runner2) {
99 ASSERT_TRUE(runner1 != nullptr); 99 ASSERT_TRUE(runner1 != nullptr);
100 ASSERT_TRUE(runner2 != nullptr); 100 ASSERT_TRUE(runner2 != nullptr);
101 runner1->PostTask(FROM_HERE, 101 runner1->PostTask(FROM_HERE,
102 base::Bind(&EnsureRunningOn, make_scoped_refptr(runner2))); 102 base::Bind(&EnsureRunningOn, base::RetainedRef(runner2)));
103 } 103 }
104 104
105 void OnCreateSnapshotFileAndVerifyData( 105 void OnCreateSnapshotFileAndVerifyData(
106 const std::string& expected_data, 106 const std::string& expected_data,
107 const CannedSyncableFileSystem::StatusCallback& callback, 107 const CannedSyncableFileSystem::StatusCallback& callback,
108 base::File::Error result, 108 base::File::Error result,
109 const base::File::Info& file_info, 109 const base::File::Info& file_info,
110 const base::FilePath& platform_path, 110 const base::FilePath& platform_path,
111 const scoped_refptr<storage::ShareableFileReference>& /* file_ref */) { 111 const scoped_refptr<storage::ShareableFileReference>& /* file_ref */) {
112 if (result != base::File::FILE_OK) { 112 if (result != base::File::FILE_OK) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 GURL url(root_url_.spec() + path); 285 GURL url(root_url_.spec() + path);
286 return file_system_context_->CrackURL(url); 286 return file_system_context_->CrackURL(url);
287 } 287 }
288 288
289 File::Error CannedSyncableFileSystem::OpenFileSystem() { 289 File::Error CannedSyncableFileSystem::OpenFileSystem() {
290 EXPECT_TRUE(is_filesystem_set_up_); 290 EXPECT_TRUE(is_filesystem_set_up_);
291 291
292 base::RunLoop run_loop; 292 base::RunLoop run_loop;
293 io_task_runner_->PostTask( 293 io_task_runner_->PostTask(
294 FROM_HERE, 294 FROM_HERE,
295 base::Bind(&CannedSyncableFileSystem::DoOpenFileSystem, 295 base::Bind(
296 base::Unretained(this), 296 &CannedSyncableFileSystem::DoOpenFileSystem, base::Unretained(this),
297 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, 297 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem,
298 base::Unretained(this), 298 base::Unretained(this),
299 base::ThreadTaskRunnerHandle::Get(), 299 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()),
300 run_loop.QuitClosure()))); 300 run_loop.QuitClosure())));
301 run_loop.Run(); 301 run_loop.Run();
302 302
303 if (backend()->sync_context()) { 303 if (backend()->sync_context()) {
304 // Register 'this' as a sync status observer. 304 // Register 'this' as a sync status observer.
305 RunOnThread( 305 RunOnThread(
306 io_task_runner_.get(), 306 io_task_runner_.get(),
307 FROM_HERE, 307 FROM_HERE,
308 base::Bind(&CannedSyncableFileSystem::InitializeSyncStatusObserver, 308 base::Bind(&CannedSyncableFileSystem::InitializeSyncStatusObserver,
309 base::Unretained(this))); 309 base::Unretained(this)));
310 } 310 }
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 const GURL& root, 731 const GURL& root,
732 const std::string& name, 732 const std::string& name,
733 File::Error result) { 733 File::Error result) {
734 if (io_task_runner_->RunsTasksOnCurrentThread()) { 734 if (io_task_runner_->RunsTasksOnCurrentThread()) {
735 EXPECT_FALSE(is_filesystem_opened_); 735 EXPECT_FALSE(is_filesystem_opened_);
736 is_filesystem_opened_ = true; 736 is_filesystem_opened_ = true;
737 } 737 }
738 if (!original_task_runner->RunsTasksOnCurrentThread()) { 738 if (!original_task_runner->RunsTasksOnCurrentThread()) {
739 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 739 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
740 original_task_runner->PostTask( 740 original_task_runner->PostTask(
741 FROM_HERE, 741 FROM_HERE, base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem,
742 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, 742 base::Unretained(this),
743 base::Unretained(this), 743 base::RetainedRef(original_task_runner),
744 make_scoped_refptr(original_task_runner), 744 quit_closure, root, name, result));
745 quit_closure,
746 root, name, result));
747 return; 745 return;
748 } 746 }
749 result_ = result; 747 result_ = result;
750 root_url_ = root; 748 root_url_ = root;
751 quit_closure.Run(); 749 quit_closure.Run();
752 } 750 }
753 751
754 void CannedSyncableFileSystem::DidInitializeFileSystemContext( 752 void CannedSyncableFileSystem::DidInitializeFileSystemContext(
755 const base::Closure& quit_closure, 753 const base::Closure& quit_closure,
756 SyncStatusCode status) { 754 SyncStatusCode status) {
757 sync_status_ = status; 755 sync_status_ = status;
758 quit_closure.Run(); 756 quit_closure.Run();
759 } 757 }
760 758
761 void CannedSyncableFileSystem::InitializeSyncStatusObserver() { 759 void CannedSyncableFileSystem::InitializeSyncStatusObserver() {
762 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread()); 760 ASSERT_TRUE(io_task_runner_->RunsTasksOnCurrentThread());
763 backend()->sync_context()->sync_status()->AddObserver(this); 761 backend()->sync_context()->sync_status()->AddObserver(this);
764 } 762 }
765 763
766 } // namespace sync_file_system 764 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698