| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/invalidation/impl/sync_system_resources.h" | 5 #include "components/invalidation/impl/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 #include <utility> | 10 #include <utility> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 logging::LogMessage(file, line, log_severity).stream() << result; | 61 logging::LogMessage(file, line, log_severity).stream() << result; |
| 62 va_end(ap); | 62 va_end(ap); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void SyncLogger::SetSystemResources(invalidation::SystemResources* resources) { | 66 void SyncLogger::SetSystemResources(invalidation::SystemResources* resources) { |
| 67 // Do nothing. | 67 // Do nothing. |
| 68 } | 68 } |
| 69 | 69 |
| 70 SyncInvalidationScheduler::SyncInvalidationScheduler() | 70 SyncInvalidationScheduler::SyncInvalidationScheduler() |
| 71 : created_on_loop_(base::MessageLoop::current()), | 71 : created_on_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 72 is_started_(false), | 72 is_started_(false), |
| 73 is_stopped_(false), | 73 is_stopped_(false), |
| 74 weak_factory_(this) { | 74 weak_factory_(this) { |
| 75 CHECK(created_on_loop_); | 75 CHECK(!!created_on_task_runner_); |
| 76 } | 76 } |
| 77 | 77 |
| 78 SyncInvalidationScheduler::~SyncInvalidationScheduler() { | 78 SyncInvalidationScheduler::~SyncInvalidationScheduler() { |
| 79 CHECK_EQ(created_on_loop_, base::MessageLoop::current()); | 79 CHECK(IsRunningOnThread()); |
| 80 CHECK(is_stopped_); | 80 CHECK(is_stopped_); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void SyncInvalidationScheduler::Start() { | 83 void SyncInvalidationScheduler::Start() { |
| 84 CHECK_EQ(created_on_loop_, base::MessageLoop::current()); | 84 CHECK(IsRunningOnThread()); |
| 85 CHECK(!is_started_); | 85 CHECK(!is_started_); |
| 86 is_started_ = true; | 86 is_started_ = true; |
| 87 is_stopped_ = false; | 87 is_stopped_ = false; |
| 88 weak_factory_.InvalidateWeakPtrs(); | 88 weak_factory_.InvalidateWeakPtrs(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void SyncInvalidationScheduler::Stop() { | 91 void SyncInvalidationScheduler::Stop() { |
| 92 CHECK_EQ(created_on_loop_, base::MessageLoop::current()); | 92 CHECK(IsRunningOnThread()); |
| 93 is_stopped_ = true; | 93 is_stopped_ = true; |
| 94 is_started_ = false; | 94 is_started_ = false; |
| 95 weak_factory_.InvalidateWeakPtrs(); | 95 weak_factory_.InvalidateWeakPtrs(); |
| 96 STLDeleteElements(&posted_tasks_); | 96 STLDeleteElements(&posted_tasks_); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void SyncInvalidationScheduler::Schedule(invalidation::TimeDelta delay, | 99 void SyncInvalidationScheduler::Schedule(invalidation::TimeDelta delay, |
| 100 invalidation::Closure* task) { | 100 invalidation::Closure* task) { |
| 101 DCHECK(invalidation::IsCallbackRepeatable(task)); | 101 DCHECK(invalidation::IsCallbackRepeatable(task)); |
| 102 CHECK_EQ(created_on_loop_, base::MessageLoop::current()); | 102 CHECK(IsRunningOnThread()); |
| 103 | 103 |
| 104 if (!is_started_) { | 104 if (!is_started_) { |
| 105 delete task; | 105 delete task; |
| 106 return; | 106 return; |
| 107 } | 107 } |
| 108 | 108 |
| 109 posted_tasks_.insert(task); | 109 posted_tasks_.insert(task); |
| 110 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 110 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 111 FROM_HERE, base::Bind(&SyncInvalidationScheduler::RunPostedTask, | 111 FROM_HERE, base::Bind(&SyncInvalidationScheduler::RunPostedTask, |
| 112 weak_factory_.GetWeakPtr(), task), | 112 weak_factory_.GetWeakPtr(), task), |
| 113 delay); | 113 delay); |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool SyncInvalidationScheduler::IsRunningOnThread() const { | 116 bool SyncInvalidationScheduler::IsRunningOnThread() const { |
| 117 return created_on_loop_ == base::MessageLoop::current(); | 117 return created_on_task_runner_->BelongsToCurrentThread(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 invalidation::Time SyncInvalidationScheduler::GetCurrentTime() const { | 120 invalidation::Time SyncInvalidationScheduler::GetCurrentTime() const { |
| 121 CHECK_EQ(created_on_loop_, base::MessageLoop::current()); | 121 CHECK(IsRunningOnThread()); |
| 122 return base::Time::Now(); | 122 return base::Time::Now(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void SyncInvalidationScheduler::SetSystemResources( | 125 void SyncInvalidationScheduler::SetSystemResources( |
| 126 invalidation::SystemResources* resources) { | 126 invalidation::SystemResources* resources) { |
| 127 // Do nothing. | 127 // Do nothing. |
| 128 } | 128 } |
| 129 | 129 |
| 130 void SyncInvalidationScheduler::RunPostedTask(invalidation::Closure* task) { | 130 void SyncInvalidationScheduler::RunPostedTask(invalidation::Closure* task) { |
| 131 CHECK_EQ(created_on_loop_, base::MessageLoop::current()); | 131 CHECK(IsRunningOnThread()); |
| 132 task->Run(); | 132 task->Run(); |
| 133 posted_tasks_.erase(task); | 133 posted_tasks_.erase(task); |
| 134 delete task; | 134 delete task; |
| 135 } | 135 } |
| 136 | 136 |
| 137 SyncNetworkChannel::SyncNetworkChannel() | 137 SyncNetworkChannel::SyncNetworkChannel() |
| 138 : last_network_status_(false), | 138 : last_network_status_(false), |
| 139 received_messages_count_(0) {} | 139 received_messages_count_(0) {} |
| 140 | 140 |
| 141 SyncNetworkChannel::~SyncNetworkChannel() { | 141 SyncNetworkChannel::~SyncNetworkChannel() { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 329 |
| 330 SyncInvalidationScheduler* SyncSystemResources::internal_scheduler() { | 330 SyncInvalidationScheduler* SyncSystemResources::internal_scheduler() { |
| 331 return internal_scheduler_.get(); | 331 return internal_scheduler_.get(); |
| 332 } | 332 } |
| 333 | 333 |
| 334 SyncInvalidationScheduler* SyncSystemResources::listener_scheduler() { | 334 SyncInvalidationScheduler* SyncSystemResources::listener_scheduler() { |
| 335 return listener_scheduler_.get(); | 335 return listener_scheduler_.get(); |
| 336 } | 336 } |
| 337 | 337 |
| 338 } // namespace syncer | 338 } // namespace syncer |
| OLD | NEW |