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

Side by Side Diff: sync/engine/sync_scheduler_unittest.cc

Issue 2033933002: Remove use of deprecated MessageLoop methods in sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/location.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h"
13 #include "base/test/test_timeouts.h" 15 #include "base/test/test_timeouts.h"
16 #include "base/threading/thread_task_runner_handle.h"
14 #include "sync/engine/backoff_delay_provider.h" 17 #include "sync/engine/backoff_delay_provider.h"
15 #include "sync/engine/sync_scheduler_impl.h" 18 #include "sync/engine/sync_scheduler_impl.h"
16 #include "sync/engine/syncer.h" 19 #include "sync/engine/syncer.h"
17 #include "sync/internal_api/public/base/cancelation_signal.h" 20 #include "sync/internal_api/public/base/cancelation_signal.h"
18 #include "sync/internal_api/public/base/model_type_test_util.h" 21 #include "sync/internal_api/public/base/model_type_test_util.h"
19 #include "sync/sessions/test_util.h" 22 #include "sync/sessions/test_util.h"
20 #include "sync/test/callback_counter.h" 23 #include "sync/test/callback_counter.h"
21 #include "sync/test/engine/fake_model_worker.h" 24 #include "sync/test/engine/fake_model_worker.h"
22 #include "sync/test/engine/mock_connection_manager.h" 25 #include "sync/test/engine/mock_connection_manager.h"
23 #include "sync/test/engine/mock_nudge_handler.h" 26 #include "sync/test/engine/mock_nudge_handler.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 75 }
73 76
74 void RunLoop() { 77 void RunLoop() {
75 base::MessageLoop::current()->Run(); 78 base::MessageLoop::current()->Run();
76 } 79 }
77 80
78 void PumpLoop() { 81 void PumpLoop() {
79 // Do it this way instead of RunAllPending to pump loop exactly once 82 // Do it this way instead of RunAllPending to pump loop exactly once
80 // (necessary in the presence of timers; see comment in 83 // (necessary in the presence of timers; see comment in
81 // QuitLoopNow). 84 // QuitLoopNow).
82 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow)); 85 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
86 base::Bind(&QuitLoopNow));
83 RunLoop(); 87 RunLoop();
84 } 88 }
85 89
86 void PumpLoopFor(base::TimeDelta time) { 90 void PumpLoopFor(base::TimeDelta time) {
87 // Allow the loop to run for the specified amount of time. 91 // Allow the loop to run for the specified amount of time.
88 base::MessageLoop::current()->PostDelayedTask( 92 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
89 FROM_HERE, base::Bind(&QuitLoopNow), time); 93 FROM_HERE, base::Bind(&QuitLoopNow), time);
90 RunLoop(); 94 RunLoop();
91 } 95 }
92 96
93 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { 97 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) {
94 ModelSafeRoutingInfo routes; 98 ModelSafeRoutingInfo routes;
95 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { 99 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) {
96 routes[iter.Get()] = GROUP_PASSIVE; 100 routes[iter.Get()] = GROUP_PASSIVE;
97 } 101 }
98 return routes; 102 return routes;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 void StartSyncConfiguration() { 204 void StartSyncConfiguration() {
201 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); 205 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE, base::Time());
202 } 206 }
203 207
204 void StartSyncScheduler(base::Time last_poll_time) { 208 void StartSyncScheduler(base::Time last_poll_time) {
205 scheduler()->Start(SyncScheduler::NORMAL_MODE, last_poll_time); 209 scheduler()->Start(SyncScheduler::NORMAL_MODE, last_poll_time);
206 } 210 }
207 211
208 // This stops the scheduler synchronously. 212 // This stops the scheduler synchronously.
209 void StopSyncScheduler() { 213 void StopSyncScheduler() {
210 base::MessageLoop::current()->PostTask( 214 base::ThreadTaskRunnerHandle::Get()->PostTask(
211 FROM_HERE, 215 FROM_HERE, base::Bind(&SyncSchedulerTest::DoQuitLoopNow,
212 base::Bind(&SyncSchedulerTest::DoQuitLoopNow, 216 weak_ptr_factory_.GetWeakPtr()));
213 weak_ptr_factory_.GetWeakPtr()));
214 RunLoop(); 217 RunLoop();
215 } 218 }
216 219
217 bool RunAndGetBackoff() { 220 bool RunAndGetBackoff() {
218 ModelTypeSet nudge_types(THEMES); 221 ModelTypeSet nudge_types(THEMES);
219 StartSyncScheduler(base::Time()); 222 StartSyncScheduler(base::Time());
220 223
221 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); 224 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE);
222 RunLoop(); 225 RunLoop();
223 226
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 ASSERT_TRUE(scheduler()->IsBackingOff()); 1470 ASSERT_TRUE(scheduler()->IsBackingOff());
1468 1471
1469 // Now succeed. 1472 // Now succeed.
1470 connection()->SetServerReachable(); 1473 connection()->SetServerReachable();
1471 PumpLoopFor(2 * delta); 1474 PumpLoopFor(2 * delta);
1472 ASSERT_EQ(1, success_counter.times_called()); 1475 ASSERT_EQ(1, success_counter.times_called());
1473 ASSERT_FALSE(scheduler()->IsBackingOff()); 1476 ASSERT_FALSE(scheduler()->IsBackingOff());
1474 } 1477 }
1475 1478
1476 } // namespace syncer 1479 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698