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 "components/sync/engine_impl/sync_scheduler_impl.h" | 5 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnblockedTypes() { | 232 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnblockedTypes() { |
233 ModelTypeSet enabled_types = cycle_context_->GetEnabledTypes(); | 233 ModelTypeSet enabled_types = cycle_context_->GetEnabledTypes(); |
234 ModelTypeSet enabled_protocol_types = | 234 ModelTypeSet enabled_protocol_types = |
235 Intersection(ProtocolTypes(), enabled_types); | 235 Intersection(ProtocolTypes(), enabled_types); |
236 ModelTypeSet blocked_types = nudge_tracker_.GetBlockedTypes(); | 236 ModelTypeSet blocked_types = nudge_tracker_.GetBlockedTypes(); |
237 return Difference(enabled_protocol_types, blocked_types); | 237 return Difference(enabled_protocol_types, blocked_types); |
238 } | 238 } |
239 | 239 |
240 void SyncSchedulerImpl::SendInitialSnapshot() { | 240 void SyncSchedulerImpl::SendInitialSnapshot() { |
241 DCHECK(CalledOnValidThread()); | 241 DCHECK(CalledOnValidThread()); |
242 std::unique_ptr<SyncCycle> dummy(SyncCycle::Build(cycle_context_, this)); | |
243 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED); | 242 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED); |
244 event.snapshot = dummy->TakeSnapshot(); | 243 event.snapshot = SyncCycle(cycle_context_, this).TakeSnapshot(); |
245 for (auto& observer : *cycle_context_->listeners()) | 244 for (auto& observer : *cycle_context_->listeners()) |
246 observer.OnSyncCycleEvent(event); | 245 observer.OnSyncCycleEvent(event); |
247 } | 246 } |
248 | 247 |
249 void SyncSchedulerImpl::ScheduleConfiguration( | 248 void SyncSchedulerImpl::ScheduleConfiguration( |
250 const ConfigurationParams& params) { | 249 const ConfigurationParams& params) { |
251 DCHECK(CalledOnValidThread()); | 250 DCHECK(CalledOnValidThread()); |
252 DCHECK(IsConfigRelatedUpdateSourceValue(params.source)); | 251 DCHECK(IsConfigRelatedUpdateSourceValue(params.source)); |
253 DCHECK_EQ(CONFIGURATION_MODE, mode_); | 252 DCHECK_EQ(CONFIGURATION_MODE, mode_); |
254 DCHECK(!params.ready_task.is_null()); | 253 DCHECK(!params.ready_task.is_null()); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 DCHECK(CalledOnValidThread()); | 421 DCHECK(CalledOnValidThread()); |
423 nudge_tracker_.SetDefaultNudgeDelay(delay_ms); | 422 nudge_tracker_.SetDefaultNudgeDelay(delay_ms); |
424 } | 423 } |
425 | 424 |
426 void SyncSchedulerImpl::DoNudgeSyncCycleJob(JobPriority priority) { | 425 void SyncSchedulerImpl::DoNudgeSyncCycleJob(JobPriority priority) { |
427 DCHECK(CalledOnValidThread()); | 426 DCHECK(CalledOnValidThread()); |
428 DCHECK(CanRunNudgeJobNow(priority)); | 427 DCHECK(CanRunNudgeJobNow(priority)); |
429 | 428 |
430 DVLOG(2) << "Will run normal mode sync cycle with types " | 429 DVLOG(2) << "Will run normal mode sync cycle with types " |
431 << ModelTypeSetToString(GetEnabledAndUnblockedTypes()); | 430 << ModelTypeSetToString(GetEnabledAndUnblockedTypes()); |
432 std::unique_ptr<SyncCycle> cycle(SyncCycle::Build(cycle_context_, this)); | 431 SyncCycle cycle(cycle_context_, this); |
433 bool success = syncer_->NormalSyncShare(GetEnabledAndUnblockedTypes(), | 432 bool success = syncer_->NormalSyncShare(GetEnabledAndUnblockedTypes(), |
434 &nudge_tracker_, cycle.get()); | 433 &nudge_tracker_, &cycle); |
435 | 434 |
436 if (success) { | 435 if (success) { |
437 // That cycle took care of any outstanding work we had. | 436 // That cycle took care of any outstanding work we had. |
438 SDVLOG(2) << "Nudge succeeded."; | 437 SDVLOG(2) << "Nudge succeeded."; |
439 nudge_tracker_.RecordSuccessfulSyncCycle(); | 438 nudge_tracker_.RecordSuccessfulSyncCycle(); |
440 HandleSuccess(); | 439 HandleSuccess(); |
441 | 440 |
442 // If this was a canary, we may need to restart the poll timer (the poll | 441 // If this was a canary, we may need to restart the poll timer (the poll |
443 // timer may have fired while the scheduler was in an error state, ignoring | 442 // timer may have fired while the scheduler was in an error state, ignoring |
444 // the poll). | 443 // the poll). |
445 if (!poll_timer_.IsRunning()) { | 444 if (!poll_timer_.IsRunning()) { |
446 SDVLOG(1) << "Canary succeeded, restarting polling."; | 445 SDVLOG(1) << "Canary succeeded, restarting polling."; |
447 AdjustPolling(UPDATE_INTERVAL); | 446 AdjustPolling(UPDATE_INTERVAL); |
448 } | 447 } |
449 } else { | 448 } else { |
450 HandleFailure(cycle->status_controller().model_neutral_state()); | 449 HandleFailure(cycle.status_controller().model_neutral_state()); |
451 } | 450 } |
452 } | 451 } |
453 | 452 |
454 void SyncSchedulerImpl::DoConfigurationSyncCycleJob(JobPriority priority) { | 453 void SyncSchedulerImpl::DoConfigurationSyncCycleJob(JobPriority priority) { |
455 DCHECK(CalledOnValidThread()); | 454 DCHECK(CalledOnValidThread()); |
456 DCHECK_EQ(mode_, CONFIGURATION_MODE); | 455 DCHECK_EQ(mode_, CONFIGURATION_MODE); |
457 DCHECK(pending_configure_params_ != nullptr); | 456 DCHECK(pending_configure_params_ != nullptr); |
458 | 457 |
459 if (!CanRunJobNow(priority)) { | 458 if (!CanRunJobNow(priority)) { |
460 SDVLOG(2) << "Unable to run configure job right now."; | 459 SDVLOG(2) << "Unable to run configure job right now."; |
461 RunAndReset(&pending_configure_params_->retry_task); | 460 RunAndReset(&pending_configure_params_->retry_task); |
462 return; | 461 return; |
463 } | 462 } |
464 | 463 |
465 SDVLOG(2) << "Will run configure SyncShare with types " | 464 SDVLOG(2) << "Will run configure SyncShare with types " |
466 << ModelTypeSetToString( | 465 << ModelTypeSetToString( |
467 pending_configure_params_->types_to_download); | 466 pending_configure_params_->types_to_download); |
468 std::unique_ptr<SyncCycle> cycle(SyncCycle::Build(cycle_context_, this)); | 467 SyncCycle cycle(cycle_context_, this); |
469 bool success = syncer_->ConfigureSyncShare( | 468 bool success = |
470 pending_configure_params_->types_to_download, | 469 syncer_->ConfigureSyncShare(pending_configure_params_->types_to_download, |
471 pending_configure_params_->source, cycle.get()); | 470 pending_configure_params_->source, &cycle); |
472 | 471 |
473 if (success) { | 472 if (success) { |
474 SDVLOG(2) << "Configure succeeded."; | 473 SDVLOG(2) << "Configure succeeded."; |
475 pending_configure_params_->ready_task.Run(); | 474 pending_configure_params_->ready_task.Run(); |
476 pending_configure_params_.reset(); | 475 pending_configure_params_.reset(); |
477 HandleSuccess(); | 476 HandleSuccess(); |
478 } else { | 477 } else { |
479 HandleFailure(cycle->status_controller().model_neutral_state()); | 478 HandleFailure(cycle.status_controller().model_neutral_state()); |
480 // Sync cycle might receive response from server that causes scheduler to | 479 // Sync cycle might receive response from server that causes scheduler to |
481 // stop and draws pending_configure_params_ invalid. | 480 // stop and draws pending_configure_params_ invalid. |
482 if (started_) | 481 if (started_) |
483 RunAndReset(&pending_configure_params_->retry_task); | 482 RunAndReset(&pending_configure_params_->retry_task); |
484 } | 483 } |
485 } | 484 } |
486 | 485 |
487 void SyncSchedulerImpl::DoClearServerDataSyncCycleJob(JobPriority priority) { | 486 void SyncSchedulerImpl::DoClearServerDataSyncCycleJob(JobPriority priority) { |
488 DCHECK(CalledOnValidThread()); | 487 DCHECK(CalledOnValidThread()); |
489 DCHECK_EQ(mode_, CLEAR_SERVER_DATA_MODE); | 488 DCHECK_EQ(mode_, CLEAR_SERVER_DATA_MODE); |
490 | 489 |
491 if (!CanRunJobNow(priority)) { | 490 if (!CanRunJobNow(priority)) { |
492 SDVLOG(2) << "Unable to run clear server data job right now."; | 491 SDVLOG(2) << "Unable to run clear server data job right now."; |
493 return; | 492 return; |
494 } | 493 } |
495 | 494 |
496 std::unique_ptr<SyncCycle> cycle(SyncCycle::Build(cycle_context_, this)); | 495 SyncCycle cycle(cycle_context_, this); |
497 const bool success = syncer_->PostClearServerData(cycle.get()); | 496 const bool success = syncer_->PostClearServerData(&cycle); |
498 if (!success) { | 497 if (!success) { |
499 HandleFailure(cycle->status_controller().model_neutral_state()); | 498 HandleFailure(cycle.status_controller().model_neutral_state()); |
500 return; | 499 return; |
501 } | 500 } |
502 | 501 |
503 SDVLOG(2) << "Clear succeeded."; | 502 SDVLOG(2) << "Clear succeeded."; |
504 pending_clear_params_->report_success_task.Run(); | 503 pending_clear_params_->report_success_task.Run(); |
505 pending_clear_params_.reset(); | 504 pending_clear_params_.reset(); |
506 HandleSuccess(); | 505 HandleSuccess(); |
507 } | 506 } |
508 | 507 |
509 void SyncSchedulerImpl::HandleSuccess() { | 508 void SyncSchedulerImpl::HandleSuccess() { |
(...skipping 21 matching lines...) Expand all Loading... |
531 WaitInterval::EXPONENTIAL_BACKOFF, length); | 530 WaitInterval::EXPONENTIAL_BACKOFF, length); |
532 SDVLOG(2) << "Sync cycle failed. Will back off for " | 531 SDVLOG(2) << "Sync cycle failed. Will back off for " |
533 << wait_interval_->length.InMilliseconds() << "ms."; | 532 << wait_interval_->length.InMilliseconds() << "ms."; |
534 } | 533 } |
535 RestartWaiting(); | 534 RestartWaiting(); |
536 } | 535 } |
537 | 536 |
538 void SyncSchedulerImpl::DoPollSyncCycleJob() { | 537 void SyncSchedulerImpl::DoPollSyncCycleJob() { |
539 SDVLOG(2) << "Polling with types " | 538 SDVLOG(2) << "Polling with types " |
540 << ModelTypeSetToString(GetEnabledAndUnblockedTypes()); | 539 << ModelTypeSetToString(GetEnabledAndUnblockedTypes()); |
541 std::unique_ptr<SyncCycle> cycle(SyncCycle::Build(cycle_context_, this)); | 540 SyncCycle cycle(cycle_context_, this); |
542 bool success = | 541 bool success = syncer_->PollSyncShare(GetEnabledAndUnblockedTypes(), &cycle); |
543 syncer_->PollSyncShare(GetEnabledAndUnblockedTypes(), cycle.get()); | |
544 | 542 |
545 // Only restart the timer if the poll succeeded. Otherwise rely on normal | 543 // Only restart the timer if the poll succeeded. Otherwise rely on normal |
546 // failure handling to retry with backoff. | 544 // failure handling to retry with backoff. |
547 if (success) { | 545 if (success) { |
548 AdjustPolling(FORCE_RESET); | 546 AdjustPolling(FORCE_RESET); |
549 HandleSuccess(); | 547 HandleSuccess(); |
550 } else { | 548 } else { |
551 HandleFailure(cycle->status_controller().model_neutral_state()); | 549 HandleFailure(cycle.status_controller().model_neutral_state()); |
552 } | 550 } |
553 } | 551 } |
554 | 552 |
555 void SyncSchedulerImpl::UpdateNudgeTimeRecords(ModelTypeSet types) { | 553 void SyncSchedulerImpl::UpdateNudgeTimeRecords(ModelTypeSet types) { |
556 DCHECK(CalledOnValidThread()); | 554 DCHECK(CalledOnValidThread()); |
557 TimeTicks now = TimeTicks::Now(); | 555 TimeTicks now = TimeTicks::Now(); |
558 // Update timing information for how often datatypes are triggering nudges. | 556 // Update timing information for how often datatypes are triggering nudges. |
559 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { | 557 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { |
560 TimeTicks previous = last_local_nudges_by_model_type_[iter.Get()]; | 558 TimeTicks previous = last_local_nudges_by_model_type_[iter.Get()]; |
561 last_local_nudges_by_model_type_[iter.Get()] = now; | 559 last_local_nudges_by_model_type_[iter.Get()] = now; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 | 927 |
930 #undef SDVLOG_LOC | 928 #undef SDVLOG_LOC |
931 | 929 |
932 #undef SDVLOG | 930 #undef SDVLOG |
933 | 931 |
934 #undef SLOG | 932 #undef SLOG |
935 | 933 |
936 #undef ENUM_CASE | 934 #undef ENUM_CASE |
937 | 935 |
938 } // namespace syncer | 936 } // namespace syncer |
OLD | NEW |