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

Side by Side Diff: components/sync/engine/browser_thread_model_worker_unittest.cc

Issue 2782573002: [Sync] Refactor ModelSafeWorker::DoWorkAndWaitUntilDone() to avoid code duplication. (Closed)
Patch Set: self-review Created 3 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
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 "components/sync/engine/browser_thread_model_worker.h" 5 #include "components/sync/engine/browser_thread_model_worker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 21 matching lines...) Expand all
32 BrowserThreadModelWorker* worker() { return worker_.get(); } 32 BrowserThreadModelWorker* worker() { return worker_.get(); }
33 base::OneShotTimer* timer() { return &timer_; } 33 base::OneShotTimer* timer() { return &timer_; }
34 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest>* factory() { 34 base::WeakPtrFactory<SyncBrowserThreadModelWorkerTest>* factory() {
35 return &weak_factory_; 35 return &weak_factory_;
36 } 36 }
37 37
38 // Schedule DoWork to be executed on the DB thread and have the test fail if 38 // Schedule DoWork to be executed on the DB thread and have the test fail if
39 // DoWork hasn't executed within action_timeout(). 39 // DoWork hasn't executed within action_timeout().
40 void ScheduleWork() { 40 void ScheduleWork() {
41 // We wait until the callback is done. So it is safe to use unretained. 41 // We wait until the callback is done. So it is safe to use unretained.
42 WorkCallback c = base::Bind(&SyncBrowserThreadModelWorkerTest::DoWork,
43 base::Unretained(this));
44 timer()->Start(FROM_HERE, TestTimeouts::action_timeout(), this, 42 timer()->Start(FROM_HERE, TestTimeouts::action_timeout(), this,
45 &SyncBrowserThreadModelWorkerTest::Timeout); 43 &SyncBrowserThreadModelWorkerTest::Timeout);
46 worker()->DoWorkAndWaitUntilDone(c); 44 worker()->DoWorkAndWaitUntilDone(base::BindOnce(
45 &SyncBrowserThreadModelWorkerTest::DoWork, base::Unretained(this)));
47 } 46 }
48 47
49 // This is the work that will be scheduled to be done on the DB thread. 48 // This is the work that will be scheduled to be done on the DB thread.
50 SyncerError DoWork() { 49 SyncerError DoWork() {
51 EXPECT_TRUE(db_thread_.task_runner()->BelongsToCurrentThread()); 50 EXPECT_TRUE(db_thread_.task_runner()->BelongsToCurrentThread());
52 main_message_loop_.task_runner()->PostTask( 51 main_message_loop_.task_runner()->PostTask(
53 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 52 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
54 did_do_work_ = true; 53 did_do_work_ = true;
55 return SYNCER_OK; 54 return SYNCER_OK;
56 } 55 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 base::ThreadTaskRunnerHandle::Get()->PostTask( 87 base::ThreadTaskRunnerHandle::Get()->PostTask(
89 FROM_HERE, base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork, 88 FROM_HERE, base::Bind(&SyncBrowserThreadModelWorkerTest::ScheduleWork,
90 factory()->GetWeakPtr())); 89 factory()->GetWeakPtr()));
91 base::RunLoop().Run(); 90 base::RunLoop().Run();
92 EXPECT_TRUE(did_do_work()); 91 EXPECT_TRUE(did_do_work());
93 } 92 }
94 93
95 } // namespace 94 } // namespace
96 95
97 } // namespace syncer 96 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine/browser_thread_model_worker.cc ('k') | components/sync/engine/model_safe_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698