| OLD | NEW |
| 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/engine/sync_scheduler.h" | 5 #include "sync/engine/sync_scheduler_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 const base::Closure& ready_task) | 76 const base::Closure& ready_task) |
| 77 : source(source), | 77 : source(source), |
| 78 types_to_download(types_to_download), | 78 types_to_download(types_to_download), |
| 79 routing_info(routing_info), | 79 routing_info(routing_info), |
| 80 keystore_key_status(keystore_key_status), | 80 keystore_key_status(keystore_key_status), |
| 81 ready_task(ready_task) { | 81 ready_task(ready_task) { |
| 82 DCHECK(!ready_task.is_null()); | 82 DCHECK(!ready_task.is_null()); |
| 83 } | 83 } |
| 84 ConfigurationParams::~ConfigurationParams() {} | 84 ConfigurationParams::~ConfigurationParams() {} |
| 85 | 85 |
| 86 SyncScheduler::DelayProvider::DelayProvider() {} | 86 SyncSchedulerImpl::DelayProvider::DelayProvider() {} |
| 87 SyncScheduler::DelayProvider::~DelayProvider() {} | 87 SyncSchedulerImpl::DelayProvider::~DelayProvider() {} |
| 88 | 88 |
| 89 SyncScheduler::WaitInterval::WaitInterval() | 89 SyncSchedulerImpl::WaitInterval::WaitInterval() |
| 90 : mode(UNKNOWN), | 90 : mode(UNKNOWN), |
| 91 had_nudge(false) { | 91 had_nudge(false) { |
| 92 } | 92 } |
| 93 | 93 |
| 94 SyncScheduler::WaitInterval::~WaitInterval() {} | 94 SyncSchedulerImpl::WaitInterval::~WaitInterval() {} |
| 95 | 95 |
| 96 #define ENUM_CASE(x) case x: return #x; break; | 96 #define ENUM_CASE(x) case x: return #x; break; |
| 97 | 97 |
| 98 const char* SyncScheduler::WaitInterval::GetModeString(Mode mode) { | 98 const char* SyncSchedulerImpl::WaitInterval::GetModeString(Mode mode) { |
| 99 switch (mode) { | 99 switch (mode) { |
| 100 ENUM_CASE(UNKNOWN); | 100 ENUM_CASE(UNKNOWN); |
| 101 ENUM_CASE(EXPONENTIAL_BACKOFF); | 101 ENUM_CASE(EXPONENTIAL_BACKOFF); |
| 102 ENUM_CASE(THROTTLED); | 102 ENUM_CASE(THROTTLED); |
| 103 } | 103 } |
| 104 NOTREACHED(); | 104 NOTREACHED(); |
| 105 return ""; | 105 return ""; |
| 106 } | 106 } |
| 107 | 107 |
| 108 SyncScheduler::SyncSessionJob::SyncSessionJob() | 108 SyncSchedulerImpl::SyncSessionJob::SyncSessionJob() |
| 109 : purpose(UNKNOWN), | 109 : purpose(UNKNOWN), |
| 110 is_canary_job(false) { | 110 is_canary_job(false) { |
| 111 } | 111 } |
| 112 | 112 |
| 113 SyncScheduler::SyncSessionJob::~SyncSessionJob() {} | 113 SyncSchedulerImpl::SyncSessionJob::~SyncSessionJob() {} |
| 114 | 114 |
| 115 SyncScheduler::SyncSessionJob::SyncSessionJob(SyncSessionJobPurpose purpose, | 115 SyncSchedulerImpl::SyncSessionJob::SyncSessionJob(SyncSessionJobPurpose purpose, |
| 116 base::TimeTicks start, | 116 base::TimeTicks start, |
| 117 linked_ptr<sessions::SyncSession> session, | 117 linked_ptr<sessions::SyncSession> session, |
| 118 bool is_canary_job, | 118 bool is_canary_job, |
| 119 const ConfigurationParams& config_params, | 119 const ConfigurationParams& config_params, |
| 120 const tracked_objects::Location& from_here) | 120 const tracked_objects::Location& from_here) |
| 121 : purpose(purpose), | 121 : purpose(purpose), |
| 122 scheduled_start(start), | 122 scheduled_start(start), |
| 123 session(session), | 123 session(session), |
| 124 is_canary_job(is_canary_job), | 124 is_canary_job(is_canary_job), |
| 125 config_params(config_params), | 125 config_params(config_params), |
| 126 from_here(from_here) { | 126 from_here(from_here) { |
| 127 } | 127 } |
| 128 | 128 |
| 129 const char* SyncScheduler::SyncSessionJob::GetPurposeString( | 129 const char* SyncSchedulerImpl::SyncSessionJob::GetPurposeString( |
| 130 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) { | 130 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) { |
| 131 switch (purpose) { | 131 switch (purpose) { |
| 132 ENUM_CASE(UNKNOWN); | 132 ENUM_CASE(UNKNOWN); |
| 133 ENUM_CASE(POLL); | 133 ENUM_CASE(POLL); |
| 134 ENUM_CASE(NUDGE); | 134 ENUM_CASE(NUDGE); |
| 135 ENUM_CASE(CONFIGURATION); | 135 ENUM_CASE(CONFIGURATION); |
| 136 ENUM_CASE(CLEANUP_DISABLED_TYPES); | 136 ENUM_CASE(CLEANUP_DISABLED_TYPES); |
| 137 } | 137 } |
| 138 NOTREACHED(); | 138 NOTREACHED(); |
| 139 return ""; | 139 return ""; |
| 140 } | 140 } |
| 141 | 141 |
| 142 TimeDelta SyncScheduler::DelayProvider::GetDelay( | 142 TimeDelta SyncSchedulerImpl::DelayProvider::GetDelay( |
| 143 const base::TimeDelta& last_delay) { | 143 const base::TimeDelta& last_delay) { |
| 144 return SyncScheduler::GetRecommendedDelay(last_delay); | 144 return SyncSchedulerImpl::GetRecommendedDelay(last_delay); |
| 145 } | 145 } |
| 146 | 146 |
| 147 GetUpdatesCallerInfo::GetUpdatesSource GetUpdatesFromNudgeSource( | 147 GetUpdatesCallerInfo::GetUpdatesSource GetUpdatesFromNudgeSource( |
| 148 NudgeSource source) { | 148 NudgeSource source) { |
| 149 switch (source) { | 149 switch (source) { |
| 150 case NUDGE_SOURCE_NOTIFICATION: | 150 case NUDGE_SOURCE_NOTIFICATION: |
| 151 return GetUpdatesCallerInfo::NOTIFICATION; | 151 return GetUpdatesCallerInfo::NOTIFICATION; |
| 152 case NUDGE_SOURCE_LOCAL: | 152 case NUDGE_SOURCE_LOCAL: |
| 153 return GetUpdatesCallerInfo::LOCAL; | 153 return GetUpdatesCallerInfo::LOCAL; |
| 154 case NUDGE_SOURCE_CONTINUATION: | 154 case NUDGE_SOURCE_CONTINUATION: |
| 155 return GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; | 155 return GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; |
| 156 case NUDGE_SOURCE_LOCAL_REFRESH: | 156 case NUDGE_SOURCE_LOCAL_REFRESH: |
| 157 return GetUpdatesCallerInfo::DATATYPE_REFRESH; | 157 return GetUpdatesCallerInfo::DATATYPE_REFRESH; |
| 158 case NUDGE_SOURCE_UNKNOWN: | 158 case NUDGE_SOURCE_UNKNOWN: |
| 159 return GetUpdatesCallerInfo::UNKNOWN; | 159 return GetUpdatesCallerInfo::UNKNOWN; |
| 160 default: | 160 default: |
| 161 NOTREACHED(); | 161 NOTREACHED(); |
| 162 return GetUpdatesCallerInfo::UNKNOWN; | 162 return GetUpdatesCallerInfo::UNKNOWN; |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 SyncScheduler::WaitInterval::WaitInterval(Mode mode, TimeDelta length) | 166 SyncSchedulerImpl::WaitInterval::WaitInterval(Mode mode, TimeDelta length) |
| 167 : mode(mode), had_nudge(false), length(length) { } | 167 : mode(mode), had_nudge(false), length(length) { } |
| 168 | 168 |
| 169 // Helper macros to log with the syncer thread name; useful when there | 169 // Helper macros to log with the syncer thread name; useful when there |
| 170 // are multiple syncer threads involved. | 170 // are multiple syncer threads involved. |
| 171 | 171 |
| 172 #define SLOG(severity) LOG(severity) << name_ << ": " | 172 #define SLOG(severity) LOG(severity) << name_ << ": " |
| 173 | 173 |
| 174 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 174 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
| 175 | 175 |
| 176 #define SDVLOG_LOC(from_here, verbose_level) \ | 176 #define SDVLOG_LOC(from_here, verbose_level) \ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 188 case GetUpdatesCallerInfo::NEW_CLIENT: | 188 case GetUpdatesCallerInfo::NEW_CLIENT: |
| 189 case GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE: | 189 case GetUpdatesCallerInfo::NEWLY_SUPPORTED_DATATYPE: |
| 190 return true; | 190 return true; |
| 191 default: | 191 default: |
| 192 return false; | 192 return false; |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 } // namespace | 196 } // namespace |
| 197 | 197 |
| 198 SyncScheduler::SyncScheduler(const std::string& name, | 198 SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name, |
| 199 sessions::SyncSessionContext* context, | 199 sessions::SyncSessionContext* context, |
| 200 Syncer* syncer) | 200 Syncer* syncer) |
| 201 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 201 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 202 weak_ptr_factory_for_weak_handle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 202 weak_ptr_factory_for_weak_handle_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 203 weak_handle_this_(MakeWeakHandle( | 203 weak_handle_this_(MakeWeakHandle( |
| 204 weak_ptr_factory_for_weak_handle_.GetWeakPtr())), | 204 weak_ptr_factory_for_weak_handle_.GetWeakPtr())), |
| 205 name_(name), | 205 name_(name), |
| 206 sync_loop_(MessageLoop::current()), | 206 sync_loop_(MessageLoop::current()), |
| 207 started_(false), | 207 started_(false), |
| 208 syncer_short_poll_interval_seconds_( | 208 syncer_short_poll_interval_seconds_( |
| 209 TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds)), | 209 TimeDelta::FromSeconds(kDefaultShortPollIntervalSeconds)), |
| 210 syncer_long_poll_interval_seconds_( | 210 syncer_long_poll_interval_seconds_( |
| 211 TimeDelta::FromSeconds(kDefaultLongPollIntervalSeconds)), | 211 TimeDelta::FromSeconds(kDefaultLongPollIntervalSeconds)), |
| 212 sessions_commit_delay_( | 212 sessions_commit_delay_( |
| 213 TimeDelta::FromSeconds(kDefaultSessionsCommitDelaySeconds)), | 213 TimeDelta::FromSeconds(kDefaultSessionsCommitDelaySeconds)), |
| 214 mode_(NORMAL_MODE), | 214 mode_(NORMAL_MODE), |
| 215 // Start with assuming everything is fine with the connection. | 215 // Start with assuming everything is fine with the connection. |
| 216 // At the end of the sync cycle we would have the correct status. | 216 // At the end of the sync cycle we would have the correct status. |
| 217 connection_code_(HttpResponse::SERVER_CONNECTION_OK), | 217 connection_code_(HttpResponse::SERVER_CONNECTION_OK), |
| 218 delay_provider_(new DelayProvider()), | 218 delay_provider_(new DelayProvider()), |
| 219 syncer_(syncer), | 219 syncer_(syncer), |
| 220 session_context_(context) { | 220 session_context_(context) { |
| 221 DCHECK(sync_loop_); | 221 DCHECK(sync_loop_); |
| 222 } | 222 } |
| 223 | 223 |
| 224 SyncScheduler::~SyncScheduler() { | 224 SyncSchedulerImpl::~SyncSchedulerImpl() { |
| 225 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 225 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 226 StopImpl(base::Closure()); | 226 StopImpl(base::Closure()); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void SyncScheduler::OnCredentialsUpdated() { | 229 void SyncSchedulerImpl::OnCredentialsUpdated() { |
| 230 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 230 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 231 | 231 |
| 232 // TODO(lipalani): crbug.com/106262. One issue here is that if after | 232 // TODO(lipalani): crbug.com/106262. One issue here is that if after |
| 233 // the auth error we happened to do gettime and it succeeded then | 233 // the auth error we happened to do gettime and it succeeded then |
| 234 // the |connection_code_| would be briefly OK however it would revert | 234 // the |connection_code_| would be briefly OK however it would revert |
| 235 // back to SYNC_AUTH_ERROR at the end of the sync cycle. The | 235 // back to SYNC_AUTH_ERROR at the end of the sync cycle. The |
| 236 // referenced bug explores the option of removing gettime calls | 236 // referenced bug explores the option of removing gettime calls |
| 237 // altogethere | 237 // altogethere |
| 238 if (HttpResponse::SYNC_AUTH_ERROR == connection_code_) { | 238 if (HttpResponse::SYNC_AUTH_ERROR == connection_code_) { |
| 239 OnServerConnectionErrorFixed(); | 239 OnServerConnectionErrorFixed(); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 void SyncScheduler::OnConnectionStatusChange() { | 243 void SyncSchedulerImpl::OnConnectionStatusChange() { |
| 244 if (HttpResponse::CONNECTION_UNAVAILABLE == connection_code_) { | 244 if (HttpResponse::CONNECTION_UNAVAILABLE == connection_code_) { |
| 245 // Optimistically assume that the connection is fixed and try | 245 // Optimistically assume that the connection is fixed and try |
| 246 // connecting. | 246 // connecting. |
| 247 OnServerConnectionErrorFixed(); | 247 OnServerConnectionErrorFixed(); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 void SyncScheduler::OnServerConnectionErrorFixed() { | 251 void SyncSchedulerImpl::OnServerConnectionErrorFixed() { |
| 252 connection_code_ = HttpResponse::SERVER_CONNECTION_OK; | 252 connection_code_ = HttpResponse::SERVER_CONNECTION_OK; |
| 253 PostTask(FROM_HERE, "DoCanaryJob", | 253 PostTask(FROM_HERE, "DoCanaryJob", |
| 254 base::Bind(&SyncScheduler::DoCanaryJob, | 254 base::Bind(&SyncSchedulerImpl::DoCanaryJob, |
| 255 weak_ptr_factory_.GetWeakPtr())); | 255 weak_ptr_factory_.GetWeakPtr())); |
| 256 | 256 |
| 257 } | 257 } |
| 258 | 258 |
| 259 void SyncScheduler::UpdateServerConnectionManagerStatus( | 259 void SyncSchedulerImpl::UpdateServerConnectionManagerStatus( |
| 260 HttpResponse::ServerConnectionCode code) { | 260 HttpResponse::ServerConnectionCode code) { |
| 261 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 261 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 262 SDVLOG(2) << "New server connection code: " | 262 SDVLOG(2) << "New server connection code: " |
| 263 << HttpResponse::GetServerConnectionCodeString(code); | 263 << HttpResponse::GetServerConnectionCodeString(code); |
| 264 | 264 |
| 265 connection_code_ = code; | 265 connection_code_ = code; |
| 266 } | 266 } |
| 267 | 267 |
| 268 void SyncScheduler::Start(Mode mode) { | 268 void SyncSchedulerImpl::Start(Mode mode) { |
| 269 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 269 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 270 std::string thread_name = MessageLoop::current()->thread_name(); | 270 std::string thread_name = MessageLoop::current()->thread_name(); |
| 271 if (thread_name.empty()) | 271 if (thread_name.empty()) |
| 272 thread_name = "<Main thread>"; | 272 thread_name = "<Main thread>"; |
| 273 SDVLOG(2) << "Start called from thread " | 273 SDVLOG(2) << "Start called from thread " |
| 274 << thread_name << " with mode " << GetModeString(mode); | 274 << thread_name << " with mode " << GetModeString(mode); |
| 275 if (!started_) { | 275 if (!started_) { |
| 276 started_ = true; | 276 started_ = true; |
| 277 SendInitialSnapshot(); | 277 SendInitialSnapshot(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 DCHECK(!session_context_->account_name().empty()); | 280 DCHECK(!session_context_->account_name().empty()); |
| 281 DCHECK(syncer_.get()); | 281 DCHECK(syncer_.get()); |
| 282 Mode old_mode = mode_; | 282 Mode old_mode = mode_; |
| 283 mode_ = mode; | 283 mode_ = mode; |
| 284 AdjustPolling(NULL); // Will kick start poll timer if needed. | 284 AdjustPolling(NULL); // Will kick start poll timer if needed. |
| 285 | 285 |
| 286 if (old_mode != mode_) { | 286 if (old_mode != mode_) { |
| 287 // We just changed our mode. See if there are any pending jobs that we could | 287 // We just changed our mode. See if there are any pending jobs that we could |
| 288 // execute in the new mode. | 288 // execute in the new mode. |
| 289 DoPendingJobIfPossible(false); | 289 DoPendingJobIfPossible(false); |
| 290 } | 290 } |
| 291 } | 291 } |
| 292 | 292 |
| 293 void SyncScheduler::SendInitialSnapshot() { | 293 void SyncSchedulerImpl::SendInitialSnapshot() { |
| 294 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 294 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 295 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this, | 295 scoped_ptr<SyncSession> dummy(new SyncSession(session_context_, this, |
| 296 SyncSourceInfo(), ModelSafeRoutingInfo(), | 296 SyncSourceInfo(), ModelSafeRoutingInfo(), |
| 297 std::vector<ModelSafeWorker*>())); | 297 std::vector<ModelSafeWorker*>())); |
| 298 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); | 298 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); |
| 299 event.snapshot = dummy->TakeSnapshot(); | 299 event.snapshot = dummy->TakeSnapshot(); |
| 300 session_context_->NotifyListeners(event); | 300 session_context_->NotifyListeners(event); |
| 301 } | 301 } |
| 302 | 302 |
| 303 namespace { | 303 namespace { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 324 | 324 |
| 325 for(std::vector<ModelSafeWorker*>::const_iterator iter = | 325 for(std::vector<ModelSafeWorker*>::const_iterator iter = |
| 326 current_workers.begin(); iter != current_workers.end(); ++iter) { | 326 current_workers.begin(); iter != current_workers.end(); ++iter) { |
| 327 if (active_groups.count((*iter)->GetModelSafeGroup()) > 0) | 327 if (active_groups.count((*iter)->GetModelSafeGroup()) > 0) |
| 328 result_workers->push_back(*iter); | 328 result_workers->push_back(*iter); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace. | 332 } // namespace. |
| 333 | 333 |
| 334 bool SyncScheduler::ScheduleConfiguration(const ConfigurationParams& params) { | 334 bool SyncSchedulerImpl::ScheduleConfiguration( |
| 335 const ConfigurationParams& params) { |
| 335 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 336 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 336 DCHECK(IsConfigRelatedUpdateSourceValue(params.source)); | 337 DCHECK(IsConfigRelatedUpdateSourceValue(params.source)); |
| 337 DCHECK_EQ(CONFIGURATION_MODE, mode_); | 338 DCHECK_EQ(CONFIGURATION_MODE, mode_); |
| 338 DCHECK(!params.ready_task.is_null()); | 339 DCHECK(!params.ready_task.is_null()); |
| 339 SDVLOG(2) << "Reconfiguring syncer."; | 340 SDVLOG(2) << "Reconfiguring syncer."; |
| 340 | 341 |
| 341 // Only one configuration is allowed at a time. Verify we're not waiting | 342 // Only one configuration is allowed at a time. Verify we're not waiting |
| 342 // for a pending configure job. | 343 // for a pending configure job. |
| 343 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job.get()); | 344 DCHECK(!wait_interval_.get() || !wait_interval_->pending_configure_job.get()); |
| 344 | 345 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 return false; | 400 return false; |
| 400 } | 401 } |
| 401 } else { | 402 } else { |
| 402 SDVLOG(2) << "No change in routing info, calling ready task directly."; | 403 SDVLOG(2) << "No change in routing info, calling ready task directly."; |
| 403 params.ready_task.Run(); | 404 params.ready_task.Run(); |
| 404 } | 405 } |
| 405 | 406 |
| 406 return true; | 407 return true; |
| 407 } | 408 } |
| 408 | 409 |
| 409 SyncScheduler::JobProcessDecision SyncScheduler::DecideWhileInWaitInterval( | 410 SyncSchedulerImpl::JobProcessDecision |
| 411 SyncSchedulerImpl::DecideWhileInWaitInterval( |
| 410 const SyncSessionJob& job) { | 412 const SyncSessionJob& job) { |
| 411 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 413 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 412 DCHECK(wait_interval_.get()); | 414 DCHECK(wait_interval_.get()); |
| 413 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); | 415 DCHECK_NE(job.purpose, SyncSessionJob::CLEANUP_DISABLED_TYPES); |
| 414 | 416 |
| 415 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " | 417 SDVLOG(2) << "DecideWhileInWaitInterval with WaitInterval mode " |
| 416 << WaitInterval::GetModeString(wait_interval_->mode) | 418 << WaitInterval::GetModeString(wait_interval_->mode) |
| 417 << (wait_interval_->had_nudge ? " (had nudge)" : "") | 419 << (wait_interval_->had_nudge ? " (had nudge)" : "") |
| 418 << (job.is_canary_job ? " (canary)" : ""); | 420 << (job.is_canary_job ? " (canary)" : ""); |
| 419 | 421 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 433 // If we already had one nudge then just drop this nudge. We will retry | 435 // If we already had one nudge then just drop this nudge. We will retry |
| 434 // later when the timer runs out. | 436 // later when the timer runs out. |
| 435 if (!job.is_canary_job) | 437 if (!job.is_canary_job) |
| 436 return wait_interval_->had_nudge ? DROP : CONTINUE; | 438 return wait_interval_->had_nudge ? DROP : CONTINUE; |
| 437 else // We are here because timer ran out. So retry. | 439 else // We are here because timer ran out. So retry. |
| 438 return CONTINUE; | 440 return CONTINUE; |
| 439 } | 441 } |
| 440 return job.is_canary_job ? CONTINUE : SAVE; | 442 return job.is_canary_job ? CONTINUE : SAVE; |
| 441 } | 443 } |
| 442 | 444 |
| 443 SyncScheduler::JobProcessDecision SyncScheduler::DecideOnJob( | 445 SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( |
| 444 const SyncSessionJob& job) { | 446 const SyncSessionJob& job) { |
| 445 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 447 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 446 if (job.purpose == SyncSessionJob::CLEANUP_DISABLED_TYPES) | 448 if (job.purpose == SyncSessionJob::CLEANUP_DISABLED_TYPES) |
| 447 return CONTINUE; | 449 return CONTINUE; |
| 448 | 450 |
| 449 // See if our type is throttled. | 451 // See if our type is throttled. |
| 450 syncer::ModelTypeSet throttled_types = | 452 syncer::ModelTypeSet throttled_types = |
| 451 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); | 453 session_context_->throttled_data_type_tracker()->GetThrottledTypes(); |
| 452 if (job.purpose == SyncSessionJob::NUDGE && | 454 if (job.purpose == SyncSessionJob::NUDGE && |
| 453 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { | 455 job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 return DROP; | 487 return DROP; |
| 486 } | 488 } |
| 487 | 489 |
| 488 if (!session_context_->connection_manager()->HasInvalidAuthToken()) | 490 if (!session_context_->connection_manager()->HasInvalidAuthToken()) |
| 489 return CONTINUE; | 491 return CONTINUE; |
| 490 | 492 |
| 491 SDVLOG(2) << "No valid auth token. Using that to decide on job."; | 493 SDVLOG(2) << "No valid auth token. Using that to decide on job."; |
| 492 return job.purpose == SyncSessionJob::NUDGE ? SAVE : DROP; | 494 return job.purpose == SyncSessionJob::NUDGE ? SAVE : DROP; |
| 493 } | 495 } |
| 494 | 496 |
| 495 void SyncScheduler::InitOrCoalescePendingJob(const SyncSessionJob& job) { | 497 void SyncSchedulerImpl::InitOrCoalescePendingJob(const SyncSessionJob& job) { |
| 496 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 498 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 497 DCHECK(job.purpose != SyncSessionJob::CONFIGURATION); | 499 DCHECK(job.purpose != SyncSessionJob::CONFIGURATION); |
| 498 if (pending_nudge_.get() == NULL) { | 500 if (pending_nudge_.get() == NULL) { |
| 499 SDVLOG(2) << "Creating a pending nudge job"; | 501 SDVLOG(2) << "Creating a pending nudge job"; |
| 500 SyncSession* s = job.session.get(); | 502 SyncSession* s = job.session.get(); |
| 501 scoped_ptr<SyncSession> session(new SyncSession(s->context(), | 503 scoped_ptr<SyncSession> session(new SyncSession(s->context(), |
| 502 s->delegate(), s->source(), s->routing_info(), s->workers())); | 504 s->delegate(), s->source(), s->routing_info(), s->workers())); |
| 503 | 505 |
| 504 SyncSessionJob new_job(SyncSessionJob::NUDGE, job.scheduled_start, | 506 SyncSessionJob new_job(SyncSessionJob::NUDGE, job.scheduled_start, |
| 505 make_linked_ptr(session.release()), false, | 507 make_linked_ptr(session.release()), false, |
| 506 ConfigurationParams(), job.from_here); | 508 ConfigurationParams(), job.from_here); |
| 507 pending_nudge_.reset(new SyncSessionJob(new_job)); | 509 pending_nudge_.reset(new SyncSessionJob(new_job)); |
| 508 | 510 |
| 509 return; | 511 return; |
| 510 } | 512 } |
| 511 | 513 |
| 512 SDVLOG(2) << "Coalescing a pending nudge"; | 514 SDVLOG(2) << "Coalescing a pending nudge"; |
| 513 pending_nudge_->session->Coalesce(*(job.session.get())); | 515 pending_nudge_->session->Coalesce(*(job.session.get())); |
| 514 pending_nudge_->scheduled_start = job.scheduled_start; | 516 pending_nudge_->scheduled_start = job.scheduled_start; |
| 515 | 517 |
| 516 // Unfortunately the nudge location cannot be modified. So it stores the | 518 // Unfortunately the nudge location cannot be modified. So it stores the |
| 517 // location of the first caller. | 519 // location of the first caller. |
| 518 } | 520 } |
| 519 | 521 |
| 520 bool SyncScheduler::ShouldRunJob(const SyncSessionJob& job) { | 522 bool SyncSchedulerImpl::ShouldRunJob(const SyncSessionJob& job) { |
| 521 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 523 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 522 DCHECK(started_); | 524 DCHECK(started_); |
| 523 | 525 |
| 524 JobProcessDecision decision = DecideOnJob(job); | 526 JobProcessDecision decision = DecideOnJob(job); |
| 525 SDVLOG(2) << "Should run " | 527 SDVLOG(2) << "Should run " |
| 526 << SyncSessionJob::GetPurposeString(job.purpose) | 528 << SyncSessionJob::GetPurposeString(job.purpose) |
| 527 << " job in mode " << GetModeString(mode_) | 529 << " job in mode " << GetModeString(mode_) |
| 528 << ": " << GetDecisionString(decision); | 530 << ": " << GetDecisionString(decision); |
| 529 if (decision != SAVE) | 531 if (decision != SAVE) |
| 530 return decision == CONTINUE; | 532 return decision == CONTINUE; |
| 531 | 533 |
| 532 DCHECK(job.purpose == SyncSessionJob::NUDGE || job.purpose == | 534 DCHECK(job.purpose == SyncSessionJob::NUDGE || job.purpose == |
| 533 SyncSessionJob::CONFIGURATION); | 535 SyncSessionJob::CONFIGURATION); |
| 534 | 536 |
| 535 SaveJob(job); | 537 SaveJob(job); |
| 536 return false; | 538 return false; |
| 537 } | 539 } |
| 538 | 540 |
| 539 void SyncScheduler::SaveJob(const SyncSessionJob& job) { | 541 void SyncSchedulerImpl::SaveJob(const SyncSessionJob& job) { |
| 540 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 542 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 541 // TODO(sync): Should we also check that job.purpose != | 543 // TODO(sync): Should we also check that job.purpose != |
| 542 // CLEANUP_DISABLED_TYPES? (See http://crbug.com/90868.) | 544 // CLEANUP_DISABLED_TYPES? (See http://crbug.com/90868.) |
| 543 if (job.purpose == SyncSessionJob::NUDGE) { | 545 if (job.purpose == SyncSessionJob::NUDGE) { |
| 544 SDVLOG(2) << "Saving a nudge job"; | 546 SDVLOG(2) << "Saving a nudge job"; |
| 545 InitOrCoalescePendingJob(job); | 547 InitOrCoalescePendingJob(job); |
| 546 } else if (job.purpose == SyncSessionJob::CONFIGURATION){ | 548 } else if (job.purpose == SyncSessionJob::CONFIGURATION){ |
| 547 SDVLOG(2) << "Saving a configuration job"; | 549 SDVLOG(2) << "Saving a configuration job"; |
| 548 DCHECK(wait_interval_.get()); | 550 DCHECK(wait_interval_.get()); |
| 549 DCHECK(mode_ == CONFIGURATION_MODE); | 551 DCHECK(mode_ == CONFIGURATION_MODE); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 568 | 570 |
| 569 // Functor for std::find_if to search by ModelSafeGroup. | 571 // Functor for std::find_if to search by ModelSafeGroup. |
| 570 struct ModelSafeWorkerGroupIs { | 572 struct ModelSafeWorkerGroupIs { |
| 571 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} | 573 explicit ModelSafeWorkerGroupIs(ModelSafeGroup group) : group(group) {} |
| 572 bool operator()(ModelSafeWorker* w) { | 574 bool operator()(ModelSafeWorker* w) { |
| 573 return group == w->GetModelSafeGroup(); | 575 return group == w->GetModelSafeGroup(); |
| 574 } | 576 } |
| 575 ModelSafeGroup group; | 577 ModelSafeGroup group; |
| 576 }; | 578 }; |
| 577 | 579 |
| 578 void SyncScheduler::ScheduleNudgeAsync( | 580 void SyncSchedulerImpl::ScheduleNudgeAsync( |
| 579 const TimeDelta& delay, | 581 const TimeDelta& delay, |
| 580 NudgeSource source, ModelTypeSet types, | 582 NudgeSource source, ModelTypeSet types, |
| 581 const tracked_objects::Location& nudge_location) { | 583 const tracked_objects::Location& nudge_location) { |
| 582 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 584 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 583 SDVLOG_LOC(nudge_location, 2) | 585 SDVLOG_LOC(nudge_location, 2) |
| 584 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 586 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 585 << "source " << GetNudgeSourceString(source) << ", " | 587 << "source " << GetNudgeSourceString(source) << ", " |
| 586 << "types " << ModelTypeSetToString(types); | 588 << "types " << ModelTypeSetToString(types); |
| 587 | 589 |
| 588 ModelTypePayloadMap types_with_payloads = | 590 ModelTypePayloadMap types_with_payloads = |
| 589 syncer::ModelTypePayloadMapFromEnumSet(types, std::string()); | 591 syncer::ModelTypePayloadMapFromEnumSet(types, std::string()); |
| 590 SyncScheduler::ScheduleNudgeImpl(delay, | 592 SyncSchedulerImpl::ScheduleNudgeImpl(delay, |
| 591 GetUpdatesFromNudgeSource(source), | 593 GetUpdatesFromNudgeSource(source), |
| 592 types_with_payloads, | 594 types_with_payloads, |
| 593 false, | 595 false, |
| 594 nudge_location); | 596 nudge_location); |
| 595 } | 597 } |
| 596 | 598 |
| 597 void SyncScheduler::ScheduleNudgeWithPayloadsAsync( | 599 void SyncSchedulerImpl::ScheduleNudgeWithPayloadsAsync( |
| 598 const TimeDelta& delay, | 600 const TimeDelta& delay, |
| 599 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, | 601 NudgeSource source, const ModelTypePayloadMap& types_with_payloads, |
| 600 const tracked_objects::Location& nudge_location) { | 602 const tracked_objects::Location& nudge_location) { |
| 601 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 603 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 602 SDVLOG_LOC(nudge_location, 2) | 604 SDVLOG_LOC(nudge_location, 2) |
| 603 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " | 605 << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " |
| 604 << "source " << GetNudgeSourceString(source) << ", " | 606 << "source " << GetNudgeSourceString(source) << ", " |
| 605 << "payloads " | 607 << "payloads " |
| 606 << syncer::ModelTypePayloadMapToString(types_with_payloads); | 608 << syncer::ModelTypePayloadMapToString(types_with_payloads); |
| 607 | 609 |
| 608 SyncScheduler::ScheduleNudgeImpl(delay, | 610 SyncSchedulerImpl::ScheduleNudgeImpl(delay, |
| 609 GetUpdatesFromNudgeSource(source), | 611 GetUpdatesFromNudgeSource(source), |
| 610 types_with_payloads, | 612 types_with_payloads, |
| 611 false, | 613 false, |
| 612 nudge_location); | 614 nudge_location); |
| 613 } | 615 } |
| 614 | 616 |
| 615 void SyncScheduler::ScheduleNudgeImpl( | 617 void SyncSchedulerImpl::ScheduleNudgeImpl( |
| 616 const TimeDelta& delay, | 618 const TimeDelta& delay, |
| 617 GetUpdatesCallerInfo::GetUpdatesSource source, | 619 GetUpdatesCallerInfo::GetUpdatesSource source, |
| 618 const ModelTypePayloadMap& types_with_payloads, | 620 const ModelTypePayloadMap& types_with_payloads, |
| 619 bool is_canary_job, const tracked_objects::Location& nudge_location) { | 621 bool is_canary_job, const tracked_objects::Location& nudge_location) { |
| 620 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 622 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 621 | 623 |
| 622 SDVLOG_LOC(nudge_location, 2) | 624 SDVLOG_LOC(nudge_location, 2) |
| 623 << "In ScheduleNudgeImpl with delay " | 625 << "In ScheduleNudgeImpl with delay " |
| 624 << delay.InMilliseconds() << " ms, " | 626 << delay.InMilliseconds() << " ms, " |
| 625 << "source " << GetUpdatesSourceString(source) << ", " | 627 << "source " << GetUpdatesSourceString(source) << ", " |
| (...skipping 30 matching lines...) Expand all Loading... |
| 656 job.scheduled_start = std::min(job.scheduled_start, | 658 job.scheduled_start = std::min(job.scheduled_start, |
| 657 pending_nudge_->scheduled_start); | 659 pending_nudge_->scheduled_start); |
| 658 pending_nudge_.reset(); | 660 pending_nudge_.reset(); |
| 659 } | 661 } |
| 660 | 662 |
| 661 // TODO(zea): Consider adding separate throttling/backoff for datatype | 663 // TODO(zea): Consider adding separate throttling/backoff for datatype |
| 662 // refresh requests. | 664 // refresh requests. |
| 663 ScheduleSyncSessionJob(job); | 665 ScheduleSyncSessionJob(job); |
| 664 } | 666 } |
| 665 | 667 |
| 666 const char* SyncScheduler::GetModeString(SyncScheduler::Mode mode) { | 668 const char* SyncSchedulerImpl::GetModeString(SyncScheduler::Mode mode) { |
| 667 switch (mode) { | 669 switch (mode) { |
| 668 ENUM_CASE(CONFIGURATION_MODE); | 670 ENUM_CASE(CONFIGURATION_MODE); |
| 669 ENUM_CASE(NORMAL_MODE); | 671 ENUM_CASE(NORMAL_MODE); |
| 670 } | 672 } |
| 671 return ""; | 673 return ""; |
| 672 } | 674 } |
| 673 | 675 |
| 674 const char* SyncScheduler::GetDecisionString( | 676 const char* SyncSchedulerImpl::GetDecisionString( |
| 675 SyncScheduler::JobProcessDecision mode) { | 677 SyncSchedulerImpl::JobProcessDecision mode) { |
| 676 switch (mode) { | 678 switch (mode) { |
| 677 ENUM_CASE(CONTINUE); | 679 ENUM_CASE(CONTINUE); |
| 678 ENUM_CASE(SAVE); | 680 ENUM_CASE(SAVE); |
| 679 ENUM_CASE(DROP); | 681 ENUM_CASE(DROP); |
| 680 } | 682 } |
| 681 return ""; | 683 return ""; |
| 682 } | 684 } |
| 683 | 685 |
| 684 // static | 686 // static |
| 685 void SyncScheduler::SetSyncerStepsForPurpose( | 687 void SyncSchedulerImpl::SetSyncerStepsForPurpose( |
| 686 SyncSessionJob::SyncSessionJobPurpose purpose, | 688 SyncSessionJob::SyncSessionJobPurpose purpose, |
| 687 SyncerStep* start, | 689 SyncerStep* start, |
| 688 SyncerStep* end) { | 690 SyncerStep* end) { |
| 689 switch (purpose) { | 691 switch (purpose) { |
| 690 case SyncSessionJob::CONFIGURATION: | 692 case SyncSessionJob::CONFIGURATION: |
| 691 *start = DOWNLOAD_UPDATES; | 693 *start = DOWNLOAD_UPDATES; |
| 692 *end = APPLY_UPDATES; | 694 *end = APPLY_UPDATES; |
| 693 return; | 695 return; |
| 694 case SyncSessionJob::NUDGE: | 696 case SyncSessionJob::NUDGE: |
| 695 case SyncSessionJob::POLL: | 697 case SyncSessionJob::POLL: |
| 696 *start = SYNCER_BEGIN; | 698 *start = SYNCER_BEGIN; |
| 697 *end = SYNCER_END; | 699 *end = SYNCER_END; |
| 698 return; | 700 return; |
| 699 case SyncSessionJob::CLEANUP_DISABLED_TYPES: | 701 case SyncSessionJob::CLEANUP_DISABLED_TYPES: |
| 700 *start = CLEANUP_DISABLED_TYPES; | 702 *start = CLEANUP_DISABLED_TYPES; |
| 701 *end = CLEANUP_DISABLED_TYPES; | 703 *end = CLEANUP_DISABLED_TYPES; |
| 702 return; | 704 return; |
| 703 default: | 705 default: |
| 704 NOTREACHED(); | 706 NOTREACHED(); |
| 705 *start = SYNCER_END; | 707 *start = SYNCER_END; |
| 706 *end = SYNCER_END; | 708 *end = SYNCER_END; |
| 707 return; | 709 return; |
| 708 } | 710 } |
| 709 } | 711 } |
| 710 | 712 |
| 711 void SyncScheduler::PostTask( | 713 void SyncSchedulerImpl::PostTask( |
| 712 const tracked_objects::Location& from_here, | 714 const tracked_objects::Location& from_here, |
| 713 const char* name, const base::Closure& task) { | 715 const char* name, const base::Closure& task) { |
| 714 SDVLOG_LOC(from_here, 3) << "Posting " << name << " task"; | 716 SDVLOG_LOC(from_here, 3) << "Posting " << name << " task"; |
| 715 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 717 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 716 if (!started_) { | 718 if (!started_) { |
| 717 SDVLOG(1) << "Not posting task as scheduler is stopped."; | 719 SDVLOG(1) << "Not posting task as scheduler is stopped."; |
| 718 return; | 720 return; |
| 719 } | 721 } |
| 720 sync_loop_->PostTask(from_here, task); | 722 sync_loop_->PostTask(from_here, task); |
| 721 } | 723 } |
| 722 | 724 |
| 723 void SyncScheduler::PostDelayedTask( | 725 void SyncSchedulerImpl::PostDelayedTask( |
| 724 const tracked_objects::Location& from_here, | 726 const tracked_objects::Location& from_here, |
| 725 const char* name, const base::Closure& task, base::TimeDelta delay) { | 727 const char* name, const base::Closure& task, base::TimeDelta delay) { |
| 726 SDVLOG_LOC(from_here, 3) << "Posting " << name << " task with " | 728 SDVLOG_LOC(from_here, 3) << "Posting " << name << " task with " |
| 727 << delay.InMilliseconds() << " ms delay"; | 729 << delay.InMilliseconds() << " ms delay"; |
| 728 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 730 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 729 if (!started_) { | 731 if (!started_) { |
| 730 SDVLOG(1) << "Not posting task as scheduler is stopped."; | 732 SDVLOG(1) << "Not posting task as scheduler is stopped."; |
| 731 return; | 733 return; |
| 732 } | 734 } |
| 733 sync_loop_->PostDelayedTask(from_here, task, delay); | 735 sync_loop_->PostDelayedTask(from_here, task, delay); |
| 734 } | 736 } |
| 735 | 737 |
| 736 void SyncScheduler::ScheduleSyncSessionJob(const SyncSessionJob& job) { | 738 void SyncSchedulerImpl::ScheduleSyncSessionJob(const SyncSessionJob& job) { |
| 737 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 739 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 738 TimeDelta delay = job.scheduled_start - TimeTicks::Now(); | 740 TimeDelta delay = job.scheduled_start - TimeTicks::Now(); |
| 739 if (delay < TimeDelta::FromMilliseconds(0)) | 741 if (delay < TimeDelta::FromMilliseconds(0)) |
| 740 delay = TimeDelta::FromMilliseconds(0); | 742 delay = TimeDelta::FromMilliseconds(0); |
| 741 SDVLOG_LOC(job.from_here, 2) | 743 SDVLOG_LOC(job.from_here, 2) |
| 742 << "In ScheduleSyncSessionJob with " | 744 << "In ScheduleSyncSessionJob with " |
| 743 << SyncSessionJob::GetPurposeString(job.purpose) | 745 << SyncSessionJob::GetPurposeString(job.purpose) |
| 744 << " job and " << delay.InMilliseconds() << " ms delay"; | 746 << " job and " << delay.InMilliseconds() << " ms delay"; |
| 745 | 747 |
| 746 DCHECK(job.purpose == SyncSessionJob::NUDGE || | 748 DCHECK(job.purpose == SyncSessionJob::NUDGE || |
| 747 job.purpose == SyncSessionJob::POLL); | 749 job.purpose == SyncSessionJob::POLL); |
| 748 if (job.purpose == SyncSessionJob::NUDGE) { | 750 if (job.purpose == SyncSessionJob::NUDGE) { |
| 749 SDVLOG_LOC(job.from_here, 2) << "Resetting pending_nudge"; | 751 SDVLOG_LOC(job.from_here, 2) << "Resetting pending_nudge"; |
| 750 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == | 752 DCHECK(!pending_nudge_.get() || pending_nudge_->session.get() == |
| 751 job.session); | 753 job.session); |
| 752 pending_nudge_.reset(new SyncSessionJob(job)); | 754 pending_nudge_.reset(new SyncSessionJob(job)); |
| 753 } | 755 } |
| 754 PostDelayedTask(job.from_here, "DoSyncSessionJob", | 756 PostDelayedTask(job.from_here, "DoSyncSessionJob", |
| 755 base::Bind(&SyncScheduler::DoSyncSessionJob, | 757 base::Bind(&SyncSchedulerImpl::DoSyncSessionJob, |
| 756 weak_ptr_factory_.GetWeakPtr(), | 758 weak_ptr_factory_.GetWeakPtr(), |
| 757 job), | 759 job), |
| 758 delay); | 760 delay); |
| 759 } | 761 } |
| 760 | 762 |
| 761 void SyncScheduler::DoSyncSessionJob(const SyncSessionJob& job) { | 763 void SyncSchedulerImpl::DoSyncSessionJob(const SyncSessionJob& job) { |
| 762 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 764 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 763 if (!ShouldRunJob(job)) { | 765 if (!ShouldRunJob(job)) { |
| 764 SLOG(WARNING) | 766 SLOG(WARNING) |
| 765 << "Not executing " | 767 << "Not executing " |
| 766 << SyncSessionJob::GetPurposeString(job.purpose) << " job from " | 768 << SyncSessionJob::GetPurposeString(job.purpose) << " job from " |
| 767 << GetUpdatesSourceString(job.session->source().updates_source); | 769 << GetUpdatesSourceString(job.session->source().updates_source); |
| 768 return; | 770 return; |
| 769 } | 771 } |
| 770 | 772 |
| 771 if (job.purpose == SyncSessionJob::NUDGE) { | 773 if (job.purpose == SyncSessionJob::NUDGE) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 797 syncer_->SyncShare(job.session.get(), begin, end); | 799 syncer_->SyncShare(job.session.get(), begin, end); |
| 798 has_more_to_sync = job.session->HasMoreToSync(); | 800 has_more_to_sync = job.session->HasMoreToSync(); |
| 799 if (has_more_to_sync) | 801 if (has_more_to_sync) |
| 800 job.session->PrepareForAnotherSyncCycle(); | 802 job.session->PrepareForAnotherSyncCycle(); |
| 801 } | 803 } |
| 802 SDVLOG(2) << "Done SyncShare looping."; | 804 SDVLOG(2) << "Done SyncShare looping."; |
| 803 | 805 |
| 804 FinishSyncSessionJob(job); | 806 FinishSyncSessionJob(job); |
| 805 } | 807 } |
| 806 | 808 |
| 807 void SyncScheduler::UpdateCarryoverSessionState( | 809 void SyncSchedulerImpl::UpdateCarryoverSessionState( |
| 808 const SyncSessionJob& old_job) { | 810 const SyncSessionJob& old_job) { |
| 809 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 811 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 810 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { | 812 if (old_job.purpose == SyncSessionJob::CONFIGURATION) { |
| 811 // Whatever types were part of a configuration task will have had updates | 813 // Whatever types were part of a configuration task will have had updates |
| 812 // downloaded. For that reason, we make sure they get recorded in the | 814 // downloaded. For that reason, we make sure they get recorded in the |
| 813 // event that they get disabled at a later time. | 815 // event that they get disabled at a later time. |
| 814 ModelSafeRoutingInfo r(session_context_->previous_session_routing_info()); | 816 ModelSafeRoutingInfo r(session_context_->previous_session_routing_info()); |
| 815 if (!r.empty()) { | 817 if (!r.empty()) { |
| 816 ModelSafeRoutingInfo temp_r; | 818 ModelSafeRoutingInfo temp_r; |
| 817 ModelSafeRoutingInfo old_info(old_job.session->routing_info()); | 819 ModelSafeRoutingInfo old_info(old_job.session->routing_info()); |
| 818 std::set_union(r.begin(), r.end(), old_info.begin(), old_info.end(), | 820 std::set_union(r.begin(), r.end(), old_info.begin(), old_info.end(), |
| 819 std::insert_iterator<ModelSafeRoutingInfo>(temp_r, temp_r.begin())); | 821 std::insert_iterator<ModelSafeRoutingInfo>(temp_r, temp_r.begin())); |
| 820 session_context_->set_previous_session_routing_info(temp_r); | 822 session_context_->set_previous_session_routing_info(temp_r); |
| 821 } | 823 } |
| 822 } else { | 824 } else { |
| 823 session_context_->set_previous_session_routing_info( | 825 session_context_->set_previous_session_routing_info( |
| 824 old_job.session->routing_info()); | 826 old_job.session->routing_info()); |
| 825 } | 827 } |
| 826 } | 828 } |
| 827 | 829 |
| 828 void SyncScheduler::FinishSyncSessionJob(const SyncSessionJob& job) { | 830 void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) { |
| 829 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 831 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 830 // Update timing information for how often datatypes are triggering nudges. | 832 // Update timing information for how often datatypes are triggering nudges. |
| 831 base::TimeTicks now = TimeTicks::Now(); | 833 base::TimeTicks now = TimeTicks::Now(); |
| 832 if (!last_sync_session_end_time_.is_null()) { | 834 if (!last_sync_session_end_time_.is_null()) { |
| 833 ModelTypePayloadMap::const_iterator iter; | 835 ModelTypePayloadMap::const_iterator iter; |
| 834 for (iter = job.session->source().types.begin(); | 836 for (iter = job.session->source().types.begin(); |
| 835 iter != job.session->source().types.end(); | 837 iter != job.session->source().types.end(); |
| 836 ++iter) { | 838 ++iter) { |
| 837 #define PER_DATA_TYPE_MACRO(type_str) \ | 839 #define PER_DATA_TYPE_MACRO(type_str) \ |
| 838 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \ | 840 SYNC_FREQ_HISTOGRAM("Sync.Freq" type_str, \ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 865 !job.config_params.ready_task.is_null()) { | 867 !job.config_params.ready_task.is_null()) { |
| 866 // If this was a configuration job with a ready task, invoke it now that | 868 // If this was a configuration job with a ready task, invoke it now that |
| 867 // we finished successfully. | 869 // we finished successfully. |
| 868 job.config_params.ready_task.Run(); | 870 job.config_params.ready_task.Run(); |
| 869 } | 871 } |
| 870 | 872 |
| 871 SDVLOG(2) << "Updating the next polling time after SyncMain"; | 873 SDVLOG(2) << "Updating the next polling time after SyncMain"; |
| 872 ScheduleNextSync(job); | 874 ScheduleNextSync(job); |
| 873 } | 875 } |
| 874 | 876 |
| 875 void SyncScheduler::ScheduleNextSync(const SyncSessionJob& old_job) { | 877 void SyncSchedulerImpl::ScheduleNextSync(const SyncSessionJob& old_job) { |
| 876 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 878 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 877 DCHECK(!old_job.session->HasMoreToSync()); | 879 DCHECK(!old_job.session->HasMoreToSync()); |
| 878 | 880 |
| 879 AdjustPolling(&old_job); | 881 AdjustPolling(&old_job); |
| 880 | 882 |
| 881 if (old_job.session->Succeeded()) { | 883 if (old_job.session->Succeeded()) { |
| 882 // Only reset backoff if we actually reached the server. | 884 // Only reset backoff if we actually reached the server. |
| 883 if (old_job.session->SuccessfullyReachedServer()) | 885 if (old_job.session->SuccessfullyReachedServer()) |
| 884 wait_interval_.reset(); | 886 wait_interval_.reset(); |
| 885 SDVLOG(2) << "Job succeeded so not scheduling more jobs"; | 887 SDVLOG(2) << "Job succeeded so not scheduling more jobs"; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 913 InitOrCoalescePendingJob(old_job); | 915 InitOrCoalescePendingJob(old_job); |
| 914 RestartWaiting(); | 916 RestartWaiting(); |
| 915 } else { | 917 } else { |
| 916 // Either this is the first failure or a consecutive failure after our | 918 // Either this is the first failure or a consecutive failure after our |
| 917 // backoff timer expired. We handle it the same way in either case. | 919 // backoff timer expired. We handle it the same way in either case. |
| 918 SDVLOG(2) << "Non-'backoff nudge' SyncShare job failed"; | 920 SDVLOG(2) << "Non-'backoff nudge' SyncShare job failed"; |
| 919 HandleContinuationError(old_job); | 921 HandleContinuationError(old_job); |
| 920 } | 922 } |
| 921 } | 923 } |
| 922 | 924 |
| 923 void SyncScheduler::AdjustPolling(const SyncSessionJob* old_job) { | 925 void SyncSchedulerImpl::AdjustPolling(const SyncSessionJob* old_job) { |
| 924 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 926 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 925 | 927 |
| 926 TimeDelta poll = (!session_context_->notifications_enabled()) ? | 928 TimeDelta poll = (!session_context_->notifications_enabled()) ? |
| 927 syncer_short_poll_interval_seconds_ : | 929 syncer_short_poll_interval_seconds_ : |
| 928 syncer_long_poll_interval_seconds_; | 930 syncer_long_poll_interval_seconds_; |
| 929 bool rate_changed = !poll_timer_.IsRunning() || | 931 bool rate_changed = !poll_timer_.IsRunning() || |
| 930 poll != poll_timer_.GetCurrentDelay(); | 932 poll != poll_timer_.GetCurrentDelay(); |
| 931 | 933 |
| 932 if (old_job && old_job->purpose != SyncSessionJob::POLL && !rate_changed) | 934 if (old_job && old_job->purpose != SyncSessionJob::POLL && !rate_changed) |
| 933 poll_timer_.Reset(); | 935 poll_timer_.Reset(); |
| 934 | 936 |
| 935 if (!rate_changed) | 937 if (!rate_changed) |
| 936 return; | 938 return; |
| 937 | 939 |
| 938 // Adjust poll rate. | 940 // Adjust poll rate. |
| 939 poll_timer_.Stop(); | 941 poll_timer_.Stop(); |
| 940 poll_timer_.Start(FROM_HERE, poll, this, &SyncScheduler::PollTimerCallback); | 942 poll_timer_.Start(FROM_HERE, poll, this, |
| 943 &SyncSchedulerImpl::PollTimerCallback); |
| 941 } | 944 } |
| 942 | 945 |
| 943 void SyncScheduler::RestartWaiting() { | 946 void SyncSchedulerImpl::RestartWaiting() { |
| 944 CHECK(wait_interval_.get()); | 947 CHECK(wait_interval_.get()); |
| 945 wait_interval_->timer.Stop(); | 948 wait_interval_->timer.Stop(); |
| 946 wait_interval_->timer.Start(FROM_HERE, wait_interval_->length, | 949 wait_interval_->timer.Start(FROM_HERE, wait_interval_->length, |
| 947 this, &SyncScheduler::DoCanaryJob); | 950 this, &SyncSchedulerImpl::DoCanaryJob); |
| 948 } | 951 } |
| 949 | 952 |
| 950 void SyncScheduler::HandleContinuationError( | 953 void SyncSchedulerImpl::HandleContinuationError( |
| 951 const SyncSessionJob& old_job) { | 954 const SyncSessionJob& old_job) { |
| 952 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 955 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 953 if (DCHECK_IS_ON()) { | 956 if (DCHECK_IS_ON()) { |
| 954 if (IsBackingOff()) { | 957 if (IsBackingOff()) { |
| 955 DCHECK(wait_interval_->timer.IsRunning() || old_job.is_canary_job); | 958 DCHECK(wait_interval_->timer.IsRunning() || old_job.is_canary_job); |
| 956 } | 959 } |
| 957 } | 960 } |
| 958 | 961 |
| 959 TimeDelta length = delay_provider_->GetDelay( | 962 TimeDelta length = delay_provider_->GetDelay( |
| 960 IsBackingOff() ? wait_interval_->length : TimeDelta::FromSeconds(1)); | 963 IsBackingOff() ? wait_interval_->length : TimeDelta::FromSeconds(1)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 983 // should be null. | 986 // should be null. |
| 984 DCHECK(wait_interval_->pending_configure_job.get() == NULL); | 987 DCHECK(wait_interval_->pending_configure_job.get() == NULL); |
| 985 | 988 |
| 986 // TODO(lipalani) - handle clear user data. | 989 // TODO(lipalani) - handle clear user data. |
| 987 InitOrCoalescePendingJob(old_job); | 990 InitOrCoalescePendingJob(old_job); |
| 988 } | 991 } |
| 989 RestartWaiting(); | 992 RestartWaiting(); |
| 990 } | 993 } |
| 991 | 994 |
| 992 // static | 995 // static |
| 993 TimeDelta SyncScheduler::GetRecommendedDelay(const TimeDelta& last_delay) { | 996 TimeDelta SyncSchedulerImpl::GetRecommendedDelay(const TimeDelta& last_delay) { |
| 994 if (last_delay.InSeconds() >= kMaxBackoffSeconds) | 997 if (last_delay.InSeconds() >= kMaxBackoffSeconds) |
| 995 return TimeDelta::FromSeconds(kMaxBackoffSeconds); | 998 return TimeDelta::FromSeconds(kMaxBackoffSeconds); |
| 996 | 999 |
| 997 // This calculates approx. base_delay_seconds * 2 +/- base_delay_seconds / 2 | 1000 // This calculates approx. base_delay_seconds * 2 +/- base_delay_seconds / 2 |
| 998 int64 backoff_s = | 1001 int64 backoff_s = |
| 999 std::max(static_cast<int64>(1), | 1002 std::max(static_cast<int64>(1), |
| 1000 last_delay.InSeconds() * kBackoffRandomizationFactor); | 1003 last_delay.InSeconds() * kBackoffRandomizationFactor); |
| 1001 | 1004 |
| 1002 // Flip a coin to randomize backoff interval by +/- 50%. | 1005 // Flip a coin to randomize backoff interval by +/- 50%. |
| 1003 int rand_sign = base::RandInt(0, 1) * 2 - 1; | 1006 int rand_sign = base::RandInt(0, 1) * 2 - 1; |
| 1004 | 1007 |
| 1005 // Truncation is adequate for rounding here. | 1008 // Truncation is adequate for rounding here. |
| 1006 backoff_s = backoff_s + | 1009 backoff_s = backoff_s + |
| 1007 (rand_sign * (last_delay.InSeconds() / kBackoffRandomizationFactor)); | 1010 (rand_sign * (last_delay.InSeconds() / kBackoffRandomizationFactor)); |
| 1008 | 1011 |
| 1009 // Cap the backoff interval. | 1012 // Cap the backoff interval. |
| 1010 backoff_s = std::max(static_cast<int64>(1), | 1013 backoff_s = std::max(static_cast<int64>(1), |
| 1011 std::min(backoff_s, kMaxBackoffSeconds)); | 1014 std::min(backoff_s, kMaxBackoffSeconds)); |
| 1012 | 1015 |
| 1013 return TimeDelta::FromSeconds(backoff_s); | 1016 return TimeDelta::FromSeconds(backoff_s); |
| 1014 } | 1017 } |
| 1015 | 1018 |
| 1016 void SyncScheduler::RequestStop(const base::Closure& callback) { | 1019 void SyncSchedulerImpl::RequestStop(const base::Closure& callback) { |
| 1017 syncer_->RequestEarlyExit(); // Safe to call from any thread. | 1020 syncer_->RequestEarlyExit(); // Safe to call from any thread. |
| 1018 DCHECK(weak_handle_this_.IsInitialized()); | 1021 DCHECK(weak_handle_this_.IsInitialized()); |
| 1019 SDVLOG(3) << "Posting StopImpl"; | 1022 SDVLOG(3) << "Posting StopImpl"; |
| 1020 weak_handle_this_.Call(FROM_HERE, | 1023 weak_handle_this_.Call(FROM_HERE, |
| 1021 &SyncScheduler::StopImpl, | 1024 &SyncSchedulerImpl::StopImpl, |
| 1022 callback); | 1025 callback); |
| 1023 } | 1026 } |
| 1024 | 1027 |
| 1025 void SyncScheduler::StopImpl(const base::Closure& callback) { | 1028 void SyncSchedulerImpl::StopImpl(const base::Closure& callback) { |
| 1026 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1029 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1027 SDVLOG(2) << "StopImpl called"; | 1030 SDVLOG(2) << "StopImpl called"; |
| 1028 | 1031 |
| 1029 // Kill any in-flight method calls. | 1032 // Kill any in-flight method calls. |
| 1030 weak_ptr_factory_.InvalidateWeakPtrs(); | 1033 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 1031 wait_interval_.reset(); | 1034 wait_interval_.reset(); |
| 1032 poll_timer_.Stop(); | 1035 poll_timer_.Stop(); |
| 1033 if (started_) { | 1036 if (started_) { |
| 1034 started_ = false; | 1037 started_ = false; |
| 1035 } | 1038 } |
| 1036 if (!callback.is_null()) | 1039 if (!callback.is_null()) |
| 1037 callback.Run(); | 1040 callback.Run(); |
| 1038 } | 1041 } |
| 1039 | 1042 |
| 1040 void SyncScheduler::DoCanaryJob() { | 1043 void SyncSchedulerImpl::DoCanaryJob() { |
| 1041 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1044 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1042 SDVLOG(2) << "Do canary job"; | 1045 SDVLOG(2) << "Do canary job"; |
| 1043 DoPendingJobIfPossible(true); | 1046 DoPendingJobIfPossible(true); |
| 1044 } | 1047 } |
| 1045 | 1048 |
| 1046 void SyncScheduler::DoPendingJobIfPossible(bool is_canary_job) { | 1049 void SyncSchedulerImpl::DoPendingJobIfPossible(bool is_canary_job) { |
| 1047 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1050 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1048 SyncSessionJob* job_to_execute = NULL; | 1051 SyncSessionJob* job_to_execute = NULL; |
| 1049 if (mode_ == CONFIGURATION_MODE && wait_interval_.get() | 1052 if (mode_ == CONFIGURATION_MODE && wait_interval_.get() |
| 1050 && wait_interval_->pending_configure_job.get()) { | 1053 && wait_interval_->pending_configure_job.get()) { |
| 1051 SDVLOG(2) << "Found pending configure job"; | 1054 SDVLOG(2) << "Found pending configure job"; |
| 1052 job_to_execute = wait_interval_->pending_configure_job.get(); | 1055 job_to_execute = wait_interval_->pending_configure_job.get(); |
| 1053 } else if (mode_ == NORMAL_MODE && pending_nudge_.get()) { | 1056 } else if (mode_ == NORMAL_MODE && pending_nudge_.get()) { |
| 1054 SDVLOG(2) << "Found pending nudge job"; | 1057 SDVLOG(2) << "Found pending nudge job"; |
| 1055 // Pending jobs mostly have time from the past. Reset it so this job | 1058 // Pending jobs mostly have time from the past. Reset it so this job |
| 1056 // will get executed. | 1059 // will get executed. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1068 } | 1071 } |
| 1069 | 1072 |
| 1070 if (job_to_execute != NULL) { | 1073 if (job_to_execute != NULL) { |
| 1071 SDVLOG(2) << "Executing pending job"; | 1074 SDVLOG(2) << "Executing pending job"; |
| 1072 SyncSessionJob copy = *job_to_execute; | 1075 SyncSessionJob copy = *job_to_execute; |
| 1073 copy.is_canary_job = is_canary_job; | 1076 copy.is_canary_job = is_canary_job; |
| 1074 DoSyncSessionJob(copy); | 1077 DoSyncSessionJob(copy); |
| 1075 } | 1078 } |
| 1076 } | 1079 } |
| 1077 | 1080 |
| 1078 SyncSession* SyncScheduler::CreateSyncSession(const SyncSourceInfo& source) { | 1081 SyncSession* SyncSchedulerImpl::CreateSyncSession( |
| 1082 const SyncSourceInfo& source) { |
| 1079 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1083 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1080 DVLOG(2) << "Creating sync session with routes " | 1084 DVLOG(2) << "Creating sync session with routes " |
| 1081 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 1085 << ModelSafeRoutingInfoToString(session_context_->routing_info()); |
| 1082 | 1086 |
| 1083 SyncSourceInfo info(source); | 1087 SyncSourceInfo info(source); |
| 1084 SyncSession* session(new SyncSession(session_context_, this, info, | 1088 SyncSession* session(new SyncSession(session_context_, this, info, |
| 1085 session_context_->routing_info(), session_context_->workers())); | 1089 session_context_->routing_info(), session_context_->workers())); |
| 1086 | 1090 |
| 1087 return session; | 1091 return session; |
| 1088 } | 1092 } |
| 1089 | 1093 |
| 1090 void SyncScheduler::PollTimerCallback() { | 1094 void SyncSchedulerImpl::PollTimerCallback() { |
| 1091 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1095 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1092 ModelSafeRoutingInfo r; | 1096 ModelSafeRoutingInfo r; |
| 1093 ModelTypePayloadMap types_with_payloads = | 1097 ModelTypePayloadMap types_with_payloads = |
| 1094 ModelSafeRoutingInfoToPayloadMap(r, std::string()); | 1098 ModelSafeRoutingInfoToPayloadMap(r, std::string()); |
| 1095 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); | 1099 SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); |
| 1096 SyncSession* s = CreateSyncSession(info); | 1100 SyncSession* s = CreateSyncSession(info); |
| 1097 | 1101 |
| 1098 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), | 1102 SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), |
| 1099 make_linked_ptr(s), | 1103 make_linked_ptr(s), |
| 1100 false, | 1104 false, |
| 1101 ConfigurationParams(), | 1105 ConfigurationParams(), |
| 1102 FROM_HERE); | 1106 FROM_HERE); |
| 1103 | 1107 |
| 1104 ScheduleSyncSessionJob(job); | 1108 ScheduleSyncSessionJob(job); |
| 1105 } | 1109 } |
| 1106 | 1110 |
| 1107 void SyncScheduler::Unthrottle() { | 1111 void SyncSchedulerImpl::Unthrottle() { |
| 1108 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1112 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1109 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); | 1113 DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); |
| 1110 SDVLOG(2) << "Unthrottled."; | 1114 SDVLOG(2) << "Unthrottled."; |
| 1111 DoCanaryJob(); | 1115 DoCanaryJob(); |
| 1112 wait_interval_.reset(); | 1116 wait_interval_.reset(); |
| 1113 } | 1117 } |
| 1114 | 1118 |
| 1115 void SyncScheduler::Notify(SyncEngineEvent::EventCause cause) { | 1119 void SyncSchedulerImpl::Notify(SyncEngineEvent::EventCause cause) { |
| 1116 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1120 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1117 session_context_->NotifyListeners(SyncEngineEvent(cause)); | 1121 session_context_->NotifyListeners(SyncEngineEvent(cause)); |
| 1118 } | 1122 } |
| 1119 | 1123 |
| 1120 bool SyncScheduler::IsBackingOff() const { | 1124 bool SyncSchedulerImpl::IsBackingOff() const { |
| 1121 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1125 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1122 return wait_interval_.get() && wait_interval_->mode == | 1126 return wait_interval_.get() && wait_interval_->mode == |
| 1123 WaitInterval::EXPONENTIAL_BACKOFF; | 1127 WaitInterval::EXPONENTIAL_BACKOFF; |
| 1124 } | 1128 } |
| 1125 | 1129 |
| 1126 void SyncScheduler::OnSilencedUntil(const base::TimeTicks& silenced_until) { | 1130 void SyncSchedulerImpl::OnSilencedUntil( |
| 1131 const base::TimeTicks& silenced_until) { |
| 1127 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1132 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1128 wait_interval_.reset(new WaitInterval(WaitInterval::THROTTLED, | 1133 wait_interval_.reset(new WaitInterval(WaitInterval::THROTTLED, |
| 1129 silenced_until - TimeTicks::Now())); | 1134 silenced_until - TimeTicks::Now())); |
| 1130 wait_interval_->timer.Start(FROM_HERE, wait_interval_->length, this, | 1135 wait_interval_->timer.Start(FROM_HERE, wait_interval_->length, this, |
| 1131 &SyncScheduler::Unthrottle); | 1136 &SyncSchedulerImpl::Unthrottle); |
| 1132 } | 1137 } |
| 1133 | 1138 |
| 1134 bool SyncScheduler::IsSyncingCurrentlySilenced() { | 1139 bool SyncSchedulerImpl::IsSyncingCurrentlySilenced() { |
| 1135 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1140 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1136 return wait_interval_.get() && wait_interval_->mode == | 1141 return wait_interval_.get() && wait_interval_->mode == |
| 1137 WaitInterval::THROTTLED; | 1142 WaitInterval::THROTTLED; |
| 1138 } | 1143 } |
| 1139 | 1144 |
| 1140 void SyncScheduler::OnReceivedShortPollIntervalUpdate( | 1145 void SyncSchedulerImpl::OnReceivedShortPollIntervalUpdate( |
| 1141 const base::TimeDelta& new_interval) { | 1146 const base::TimeDelta& new_interval) { |
| 1142 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1147 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1143 syncer_short_poll_interval_seconds_ = new_interval; | 1148 syncer_short_poll_interval_seconds_ = new_interval; |
| 1144 } | 1149 } |
| 1145 | 1150 |
| 1146 void SyncScheduler::OnReceivedLongPollIntervalUpdate( | 1151 void SyncSchedulerImpl::OnReceivedLongPollIntervalUpdate( |
| 1147 const base::TimeDelta& new_interval) { | 1152 const base::TimeDelta& new_interval) { |
| 1148 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1153 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1149 syncer_long_poll_interval_seconds_ = new_interval; | 1154 syncer_long_poll_interval_seconds_ = new_interval; |
| 1150 } | 1155 } |
| 1151 | 1156 |
| 1152 void SyncScheduler::OnReceivedSessionsCommitDelay( | 1157 void SyncSchedulerImpl::OnReceivedSessionsCommitDelay( |
| 1153 const base::TimeDelta& new_delay) { | 1158 const base::TimeDelta& new_delay) { |
| 1154 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1159 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1155 sessions_commit_delay_ = new_delay; | 1160 sessions_commit_delay_ = new_delay; |
| 1156 } | 1161 } |
| 1157 | 1162 |
| 1158 void SyncScheduler::OnShouldStopSyncingPermanently() { | 1163 void SyncSchedulerImpl::OnShouldStopSyncingPermanently() { |
| 1159 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1164 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1160 SDVLOG(2) << "OnShouldStopSyncingPermanently"; | 1165 SDVLOG(2) << "OnShouldStopSyncingPermanently"; |
| 1161 syncer_->RequestEarlyExit(); // Thread-safe. | 1166 syncer_->RequestEarlyExit(); // Thread-safe. |
| 1162 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); | 1167 Notify(SyncEngineEvent::STOP_SYNCING_PERMANENTLY); |
| 1163 } | 1168 } |
| 1164 | 1169 |
| 1165 void SyncScheduler::OnActionableError( | 1170 void SyncSchedulerImpl::OnActionableError( |
| 1166 const sessions::SyncSessionSnapshot& snap) { | 1171 const sessions::SyncSessionSnapshot& snap) { |
| 1167 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1172 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1168 SDVLOG(2) << "OnActionableError"; | 1173 SDVLOG(2) << "OnActionableError"; |
| 1169 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); | 1174 SyncEngineEvent event(SyncEngineEvent::ACTIONABLE_ERROR); |
| 1170 event.snapshot = snap; | 1175 event.snapshot = snap; |
| 1171 session_context_->NotifyListeners(event); | 1176 session_context_->NotifyListeners(event); |
| 1172 } | 1177 } |
| 1173 | 1178 |
| 1174 void SyncScheduler::OnSyncProtocolError( | 1179 void SyncSchedulerImpl::OnSyncProtocolError( |
| 1175 const sessions::SyncSessionSnapshot& snapshot) { | 1180 const sessions::SyncSessionSnapshot& snapshot) { |
| 1176 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1181 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1177 if (ShouldRequestEarlyExit( | 1182 if (ShouldRequestEarlyExit( |
| 1178 snapshot.model_neutral_state().sync_protocol_error)) { | 1183 snapshot.model_neutral_state().sync_protocol_error)) { |
| 1179 SDVLOG(2) << "Sync Scheduler requesting early exit."; | 1184 SDVLOG(2) << "Sync Scheduler requesting early exit."; |
| 1180 syncer_->RequestEarlyExit(); // Thread-safe. | 1185 syncer_->RequestEarlyExit(); // Thread-safe. |
| 1181 } | 1186 } |
| 1182 if (IsActionableError(snapshot.model_neutral_state().sync_protocol_error)) | 1187 if (IsActionableError(snapshot.model_neutral_state().sync_protocol_error)) |
| 1183 OnActionableError(snapshot); | 1188 OnActionableError(snapshot); |
| 1184 } | 1189 } |
| 1185 | 1190 |
| 1186 void SyncScheduler::set_notifications_enabled(bool notifications_enabled) { | 1191 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { |
| 1187 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1192 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1188 session_context_->set_notifications_enabled(notifications_enabled); | 1193 session_context_->set_notifications_enabled(notifications_enabled); |
| 1189 } | 1194 } |
| 1190 | 1195 |
| 1191 base::TimeDelta SyncScheduler::sessions_commit_delay() const { | 1196 base::TimeDelta SyncSchedulerImpl::GetSessionsCommitDelay() const { |
| 1192 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1197 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1193 return sessions_commit_delay_; | 1198 return sessions_commit_delay_; |
| 1194 } | 1199 } |
| 1195 | 1200 |
| 1196 #undef SDVLOG_LOC | 1201 #undef SDVLOG_LOC |
| 1197 | 1202 |
| 1198 #undef SDVLOG | 1203 #undef SDVLOG |
| 1199 | 1204 |
| 1200 #undef SLOG | 1205 #undef SLOG |
| 1201 | 1206 |
| 1202 #undef ENUM_CASE | 1207 #undef ENUM_CASE |
| 1203 | 1208 |
| 1204 } // namespace syncer | 1209 } // namespace syncer |
| OLD | NEW |