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_impl.h" | 5 #include "sync/engine/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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { | 272 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { |
273 ModelTypeSet enabled_types = session_context_->GetEnabledTypes(); | 273 ModelTypeSet enabled_types = session_context_->GetEnabledTypes(); |
274 ModelTypeSet enabled_protocol_types = | 274 ModelTypeSet enabled_protocol_types = |
275 Intersection(ProtocolTypes(), enabled_types); | 275 Intersection(ProtocolTypes(), enabled_types); |
276 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); | 276 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); |
277 return Difference(enabled_protocol_types, throttled_types); | 277 return Difference(enabled_protocol_types, throttled_types); |
278 } | 278 } |
279 | 279 |
280 void SyncSchedulerImpl::SendInitialSnapshot() { | 280 void SyncSchedulerImpl::SendInitialSnapshot() { |
281 DCHECK(CalledOnValidThread()); | 281 DCHECK(CalledOnValidThread()); |
282 scoped_ptr<SyncSession> dummy(SyncSession::Build(session_context_, this)); | 282 std::unique_ptr<SyncSession> dummy( |
| 283 SyncSession::Build(session_context_, this)); |
283 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED); | 284 SyncCycleEvent event(SyncCycleEvent::STATUS_CHANGED); |
284 event.snapshot = dummy->TakeSnapshot(); | 285 event.snapshot = dummy->TakeSnapshot(); |
285 FOR_EACH_OBSERVER(SyncEngineEventListener, | 286 FOR_EACH_OBSERVER(SyncEngineEventListener, |
286 *session_context_->listeners(), | 287 *session_context_->listeners(), |
287 OnSyncCycleEvent(event)); | 288 OnSyncCycleEvent(event)); |
288 } | 289 } |
289 | 290 |
290 namespace { | 291 namespace { |
291 | 292 |
292 // Helper to extract the routing info corresponding to types in | 293 // Helper to extract the routing info corresponding to types in |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 411 |
411 SDVLOG_LOC(nudge_location, 2) | 412 SDVLOG_LOC(nudge_location, 2) |
412 << "Scheduling sync because of local refresh request for " | 413 << "Scheduling sync because of local refresh request for " |
413 << ModelTypeSetToString(types); | 414 << ModelTypeSetToString(types); |
414 base::TimeDelta nudge_delay = nudge_tracker_.RecordLocalRefreshRequest(types); | 415 base::TimeDelta nudge_delay = nudge_tracker_.RecordLocalRefreshRequest(types); |
415 ScheduleNudgeImpl(nudge_delay, nudge_location); | 416 ScheduleNudgeImpl(nudge_delay, nudge_location); |
416 } | 417 } |
417 | 418 |
418 void SyncSchedulerImpl::ScheduleInvalidationNudge( | 419 void SyncSchedulerImpl::ScheduleInvalidationNudge( |
419 syncer::ModelType model_type, | 420 syncer::ModelType model_type, |
420 scoped_ptr<InvalidationInterface> invalidation, | 421 std::unique_ptr<InvalidationInterface> invalidation, |
421 const tracked_objects::Location& nudge_location) { | 422 const tracked_objects::Location& nudge_location) { |
422 DCHECK(CalledOnValidThread()); | 423 DCHECK(CalledOnValidThread()); |
423 | 424 |
424 SDVLOG_LOC(nudge_location, 2) | 425 SDVLOG_LOC(nudge_location, 2) |
425 << "Scheduling sync because we received invalidation for " | 426 << "Scheduling sync because we received invalidation for " |
426 << ModelTypeToString(model_type); | 427 << ModelTypeToString(model_type); |
427 base::TimeDelta nudge_delay = nudge_tracker_.RecordRemoteInvalidation( | 428 base::TimeDelta nudge_delay = nudge_tracker_.RecordRemoteInvalidation( |
428 model_type, std::move(invalidation)); | 429 model_type, std::move(invalidation)); |
429 ScheduleNudgeImpl(nudge_delay, nudge_location); | 430 ScheduleNudgeImpl(nudge_delay, nudge_location); |
430 } | 431 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 DCHECK(CalledOnValidThread()); | 494 DCHECK(CalledOnValidThread()); |
494 nudge_tracker_.SetDefaultNudgeDelay(delay_ms); | 495 nudge_tracker_.SetDefaultNudgeDelay(delay_ms); |
495 } | 496 } |
496 | 497 |
497 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) { | 498 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) { |
498 DCHECK(CalledOnValidThread()); | 499 DCHECK(CalledOnValidThread()); |
499 DCHECK(CanRunNudgeJobNow(priority)); | 500 DCHECK(CanRunNudgeJobNow(priority)); |
500 | 501 |
501 DVLOG(2) << "Will run normal mode sync cycle with types " | 502 DVLOG(2) << "Will run normal mode sync cycle with types " |
502 << ModelTypeSetToString(session_context_->GetEnabledTypes()); | 503 << ModelTypeSetToString(session_context_->GetEnabledTypes()); |
503 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 504 std::unique_ptr<SyncSession> session( |
| 505 SyncSession::Build(session_context_, this)); |
504 bool success = syncer_->NormalSyncShare( | 506 bool success = syncer_->NormalSyncShare( |
505 GetEnabledAndUnthrottledTypes(), &nudge_tracker_, session.get()); | 507 GetEnabledAndUnthrottledTypes(), &nudge_tracker_, session.get()); |
506 | 508 |
507 if (success) { | 509 if (success) { |
508 // That cycle took care of any outstanding work we had. | 510 // That cycle took care of any outstanding work we had. |
509 SDVLOG(2) << "Nudge succeeded."; | 511 SDVLOG(2) << "Nudge succeeded."; |
510 nudge_tracker_.RecordSuccessfulSyncCycle(); | 512 nudge_tracker_.RecordSuccessfulSyncCycle(); |
511 scheduled_nudge_time_ = base::TimeTicks(); | 513 scheduled_nudge_time_ = base::TimeTicks(); |
512 HandleSuccess(); | 514 HandleSuccess(); |
513 | 515 |
(...skipping 15 matching lines...) Expand all Loading... |
529 DCHECK(pending_configure_params_ != NULL); | 531 DCHECK(pending_configure_params_ != NULL); |
530 | 532 |
531 if (!CanRunJobNow(priority)) { | 533 if (!CanRunJobNow(priority)) { |
532 SDVLOG(2) << "Unable to run configure job right now."; | 534 SDVLOG(2) << "Unable to run configure job right now."; |
533 RunAndReset(&pending_configure_params_->retry_task); | 535 RunAndReset(&pending_configure_params_->retry_task); |
534 return; | 536 return; |
535 } | 537 } |
536 | 538 |
537 SDVLOG(2) << "Will run configure SyncShare with types " | 539 SDVLOG(2) << "Will run configure SyncShare with types " |
538 << ModelTypeSetToString(session_context_->GetEnabledTypes()); | 540 << ModelTypeSetToString(session_context_->GetEnabledTypes()); |
539 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 541 std::unique_ptr<SyncSession> session( |
| 542 SyncSession::Build(session_context_, this)); |
540 bool success = syncer_->ConfigureSyncShare( | 543 bool success = syncer_->ConfigureSyncShare( |
541 pending_configure_params_->types_to_download, | 544 pending_configure_params_->types_to_download, |
542 pending_configure_params_->source, | 545 pending_configure_params_->source, |
543 session.get()); | 546 session.get()); |
544 | 547 |
545 if (success) { | 548 if (success) { |
546 SDVLOG(2) << "Configure succeeded."; | 549 SDVLOG(2) << "Configure succeeded."; |
547 pending_configure_params_->ready_task.Run(); | 550 pending_configure_params_->ready_task.Run(); |
548 pending_configure_params_.reset(); | 551 pending_configure_params_.reset(); |
549 HandleSuccess(); | 552 HandleSuccess(); |
550 } else { | 553 } else { |
551 HandleFailure(session->status_controller().model_neutral_state()); | 554 HandleFailure(session->status_controller().model_neutral_state()); |
552 // Sync cycle might receive response from server that causes scheduler to | 555 // Sync cycle might receive response from server that causes scheduler to |
553 // stop and draws pending_configure_params_ invalid. | 556 // stop and draws pending_configure_params_ invalid. |
554 if (started_) | 557 if (started_) |
555 RunAndReset(&pending_configure_params_->retry_task); | 558 RunAndReset(&pending_configure_params_->retry_task); |
556 } | 559 } |
557 } | 560 } |
558 | 561 |
559 void SyncSchedulerImpl::DoClearServerDataSyncSessionJob(JobPriority priority) { | 562 void SyncSchedulerImpl::DoClearServerDataSyncSessionJob(JobPriority priority) { |
560 DCHECK(CalledOnValidThread()); | 563 DCHECK(CalledOnValidThread()); |
561 DCHECK_EQ(mode_, CLEAR_SERVER_DATA_MODE); | 564 DCHECK_EQ(mode_, CLEAR_SERVER_DATA_MODE); |
562 | 565 |
563 if (!CanRunJobNow(priority)) { | 566 if (!CanRunJobNow(priority)) { |
564 SDVLOG(2) << "Unable to run clear server data job right now."; | 567 SDVLOG(2) << "Unable to run clear server data job right now."; |
565 RunAndReset(&pending_configure_params_->retry_task); | 568 RunAndReset(&pending_configure_params_->retry_task); |
566 return; | 569 return; |
567 } | 570 } |
568 | 571 |
569 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 572 std::unique_ptr<SyncSession> session( |
| 573 SyncSession::Build(session_context_, this)); |
570 const bool success = syncer_->PostClearServerData(session.get()); | 574 const bool success = syncer_->PostClearServerData(session.get()); |
571 if (!success) { | 575 if (!success) { |
572 HandleFailure(session->status_controller().model_neutral_state()); | 576 HandleFailure(session->status_controller().model_neutral_state()); |
573 return; | 577 return; |
574 } | 578 } |
575 | 579 |
576 SDVLOG(2) << "Clear succeeded."; | 580 SDVLOG(2) << "Clear succeeded."; |
577 pending_clear_params_->report_success_task.Run(); | 581 pending_clear_params_->report_success_task.Run(); |
578 pending_clear_params_.reset(); | 582 pending_clear_params_.reset(); |
579 HandleSuccess(); | 583 HandleSuccess(); |
(...skipping 24 matching lines...) Expand all Loading... |
604 new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, length)); | 608 new WaitInterval(WaitInterval::EXPONENTIAL_BACKOFF, length)); |
605 SDVLOG(2) << "Sync cycle failed. Will back off for " | 609 SDVLOG(2) << "Sync cycle failed. Will back off for " |
606 << wait_interval_->length.InMilliseconds() << "ms."; | 610 << wait_interval_->length.InMilliseconds() << "ms."; |
607 } | 611 } |
608 RestartWaiting(); | 612 RestartWaiting(); |
609 } | 613 } |
610 | 614 |
611 void SyncSchedulerImpl::DoPollSyncSessionJob() { | 615 void SyncSchedulerImpl::DoPollSyncSessionJob() { |
612 SDVLOG(2) << "Polling with types " | 616 SDVLOG(2) << "Polling with types " |
613 << ModelTypeSetToString(GetEnabledAndUnthrottledTypes()); | 617 << ModelTypeSetToString(GetEnabledAndUnthrottledTypes()); |
614 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 618 std::unique_ptr<SyncSession> session( |
| 619 SyncSession::Build(session_context_, this)); |
615 bool success = syncer_->PollSyncShare( | 620 bool success = syncer_->PollSyncShare( |
616 GetEnabledAndUnthrottledTypes(), | 621 GetEnabledAndUnthrottledTypes(), |
617 session.get()); | 622 session.get()); |
618 | 623 |
619 // Only restart the timer if the poll succeeded. Otherwise rely on normal | 624 // Only restart the timer if the poll succeeded. Otherwise rely on normal |
620 // failure handling to retry with backoff. | 625 // failure handling to retry with backoff. |
621 if (success) { | 626 if (success) { |
622 AdjustPolling(FORCE_RESET); | 627 AdjustPolling(FORCE_RESET); |
623 HandleSuccess(); | 628 HandleSuccess(); |
624 } else { | 629 } else { |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 | 988 |
984 #undef SDVLOG_LOC | 989 #undef SDVLOG_LOC |
985 | 990 |
986 #undef SDVLOG | 991 #undef SDVLOG |
987 | 992 |
988 #undef SLOG | 993 #undef SLOG |
989 | 994 |
990 #undef ENUM_CASE | 995 #undef ENUM_CASE |
991 | 996 |
992 } // namespace syncer | 997 } // namespace syncer |
OLD | NEW |