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

Side by Side Diff: sync/notifier/sync_system_resources.cc

Issue 14113050: sync: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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
« no previous file with comments | « sync/notifier/sync_system_resources.h ('k') | sync/notifier/sync_system_resources_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "sync/notifier/sync_system_resources.h" 5 #include "sync/notifier/sync_system_resources.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <cstring> 8 #include <cstring>
9 #include <string> 9 #include <string>
10 10
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 va_end(ap); 55 va_end(ap);
56 } 56 }
57 } 57 }
58 58
59 void SyncLogger::SetSystemResources(invalidation::SystemResources* resources) { 59 void SyncLogger::SetSystemResources(invalidation::SystemResources* resources) {
60 // Do nothing. 60 // Do nothing.
61 } 61 }
62 62
63 SyncInvalidationScheduler::SyncInvalidationScheduler() 63 SyncInvalidationScheduler::SyncInvalidationScheduler()
64 : weak_factory_(this), 64 : weak_factory_(this),
65 created_on_loop_(MessageLoop::current()), 65 created_on_loop_(base::MessageLoop::current()),
66 is_started_(false), 66 is_started_(false),
67 is_stopped_(false) { 67 is_stopped_(false) {
68 CHECK(created_on_loop_); 68 CHECK(created_on_loop_);
69 } 69 }
70 70
71 SyncInvalidationScheduler::~SyncInvalidationScheduler() { 71 SyncInvalidationScheduler::~SyncInvalidationScheduler() {
72 CHECK_EQ(created_on_loop_, MessageLoop::current()); 72 CHECK_EQ(created_on_loop_, base::MessageLoop::current());
73 CHECK(is_stopped_); 73 CHECK(is_stopped_);
74 } 74 }
75 75
76 void SyncInvalidationScheduler::Start() { 76 void SyncInvalidationScheduler::Start() {
77 CHECK_EQ(created_on_loop_, MessageLoop::current()); 77 CHECK_EQ(created_on_loop_, base::MessageLoop::current());
78 CHECK(!is_started_); 78 CHECK(!is_started_);
79 is_started_ = true; 79 is_started_ = true;
80 is_stopped_ = false; 80 is_stopped_ = false;
81 weak_factory_.InvalidateWeakPtrs(); 81 weak_factory_.InvalidateWeakPtrs();
82 } 82 }
83 83
84 void SyncInvalidationScheduler::Stop() { 84 void SyncInvalidationScheduler::Stop() {
85 CHECK_EQ(created_on_loop_, MessageLoop::current()); 85 CHECK_EQ(created_on_loop_, base::MessageLoop::current());
86 is_stopped_ = true; 86 is_stopped_ = true;
87 is_started_ = false; 87 is_started_ = false;
88 weak_factory_.InvalidateWeakPtrs(); 88 weak_factory_.InvalidateWeakPtrs();
89 STLDeleteElements(&posted_tasks_); 89 STLDeleteElements(&posted_tasks_);
90 posted_tasks_.clear(); 90 posted_tasks_.clear();
91 } 91 }
92 92
93 void SyncInvalidationScheduler::Schedule(invalidation::TimeDelta delay, 93 void SyncInvalidationScheduler::Schedule(invalidation::TimeDelta delay,
94 invalidation::Closure* task) { 94 invalidation::Closure* task) {
95 DCHECK(invalidation::IsCallbackRepeatable(task)); 95 DCHECK(invalidation::IsCallbackRepeatable(task));
96 CHECK_EQ(created_on_loop_, MessageLoop::current()); 96 CHECK_EQ(created_on_loop_, base::MessageLoop::current());
97 97
98 if (!is_started_) { 98 if (!is_started_) {
99 delete task; 99 delete task;
100 return; 100 return;
101 } 101 }
102 102
103 posted_tasks_.insert(task); 103 posted_tasks_.insert(task);
104 MessageLoop::current()->PostDelayedTask( 104 base::MessageLoop::current()->PostDelayedTask(
105 FROM_HERE, base::Bind(&SyncInvalidationScheduler::RunPostedTask, 105 FROM_HERE, base::Bind(&SyncInvalidationScheduler::RunPostedTask,
106 weak_factory_.GetWeakPtr(), task), 106 weak_factory_.GetWeakPtr(), task),
107 delay); 107 delay);
108 } 108 }
109 109
110 bool SyncInvalidationScheduler::IsRunningOnThread() const { 110 bool SyncInvalidationScheduler::IsRunningOnThread() const {
111 return created_on_loop_ == MessageLoop::current(); 111 return created_on_loop_ == base::MessageLoop::current();
112 } 112 }
113 113
114 invalidation::Time SyncInvalidationScheduler::GetCurrentTime() const { 114 invalidation::Time SyncInvalidationScheduler::GetCurrentTime() const {
115 CHECK_EQ(created_on_loop_, MessageLoop::current()); 115 CHECK_EQ(created_on_loop_, base::MessageLoop::current());
116 return base::Time::Now(); 116 return base::Time::Now();
117 } 117 }
118 118
119 void SyncInvalidationScheduler::SetSystemResources( 119 void SyncInvalidationScheduler::SetSystemResources(
120 invalidation::SystemResources* resources) { 120 invalidation::SystemResources* resources) {
121 // Do nothing. 121 // Do nothing.
122 } 122 }
123 123
124 void SyncInvalidationScheduler::RunPostedTask(invalidation::Closure* task) { 124 void SyncInvalidationScheduler::RunPostedTask(invalidation::Closure* task) {
125 CHECK_EQ(created_on_loop_, MessageLoop::current()); 125 CHECK_EQ(created_on_loop_, base::MessageLoop::current());
126 task->Run(); 126 task->Run();
127 posted_tasks_.erase(task); 127 posted_tasks_.erase(task);
128 delete task; 128 delete task;
129 } 129 }
130 130
131 SyncStorage::SyncStorage(StateWriter* state_writer, 131 SyncStorage::SyncStorage(StateWriter* state_writer,
132 invalidation::Scheduler* scheduler) 132 invalidation::Scheduler* scheduler)
133 : state_writer_(state_writer), 133 : state_writer_(state_writer),
134 scheduler_(scheduler) { 134 scheduler_(scheduler) {
135 DCHECK(state_writer_); 135 DCHECK(state_writer_);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 246
247 SyncInvalidationScheduler* SyncSystemResources::internal_scheduler() { 247 SyncInvalidationScheduler* SyncSystemResources::internal_scheduler() {
248 return internal_scheduler_.get(); 248 return internal_scheduler_.get();
249 } 249 }
250 250
251 SyncInvalidationScheduler* SyncSystemResources::listener_scheduler() { 251 SyncInvalidationScheduler* SyncSystemResources::listener_scheduler() {
252 return listener_scheduler_.get(); 252 return listener_scheduler_.get();
253 } 253 }
254 254
255 } // namespace syncer 255 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/sync_system_resources.h ('k') | sync/notifier/sync_system_resources_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698