| 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 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 if (old_mode != mode_ && | 230 if (old_mode != mode_ && |
| 231 mode_ == NORMAL_MODE && | 231 mode_ == NORMAL_MODE && |
| 232 nudge_tracker_.IsSyncRequired() && | 232 nudge_tracker_.IsSyncRequired() && |
| 233 CanRunNudgeJobNow(NORMAL_PRIORITY)) { | 233 CanRunNudgeJobNow(NORMAL_PRIORITY)) { |
| 234 // We just got back to normal mode. Let's try to run the work that was | 234 // We just got back to normal mode. Let's try to run the work that was |
| 235 // queued up while we were configuring. | 235 // queued up while we were configuring. |
| 236 DoNudgeSyncSessionJob(NORMAL_PRIORITY); | 236 DoNudgeSyncSessionJob(NORMAL_PRIORITY); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { |
| 241 ModelTypeSet enabled_types = |
| 242 GetRoutingInfoTypes(session_context_->routing_info()); |
| 243 ModelTypeSet throttled_types = |
| 244 nudge_tracker_.GetThrottledTypes(); |
| 245 return Difference(enabled_types, throttled_types); |
| 246 } |
| 247 |
| 240 void SyncSchedulerImpl::SendInitialSnapshot() { | 248 void SyncSchedulerImpl::SendInitialSnapshot() { |
| 241 DCHECK(CalledOnValidThread()); | 249 DCHECK(CalledOnValidThread()); |
| 242 scoped_ptr<SyncSession> dummy( | 250 scoped_ptr<SyncSession> dummy( |
| 243 SyncSession::Build(session_context_, this, SyncSourceInfo())); | 251 SyncSession::Build(session_context_, this, SyncSourceInfo())); |
| 244 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); | 252 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); |
| 245 event.snapshot = dummy->TakeSnapshot(); | 253 event.snapshot = dummy->TakeSnapshot(); |
| 246 session_context_->NotifyListeners(event); | 254 session_context_->NotifyListeners(event); |
| 247 } | 255 } |
| 248 | 256 |
| 249 namespace { | 257 namespace { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 return ""; | 462 return ""; |
| 455 } | 463 } |
| 456 | 464 |
| 457 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) { | 465 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) { |
| 458 DCHECK(CalledOnValidThread()); | 466 DCHECK(CalledOnValidThread()); |
| 459 DCHECK(CanRunNudgeJobNow(priority)); | 467 DCHECK(CanRunNudgeJobNow(priority)); |
| 460 | 468 |
| 461 DVLOG(2) << "Will run normal mode sync cycle with routing info " | 469 DVLOG(2) << "Will run normal mode sync cycle with routing info " |
| 462 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 470 << ModelSafeRoutingInfoToString(session_context_->routing_info()); |
| 463 scoped_ptr<SyncSession> session( | 471 scoped_ptr<SyncSession> session( |
| 464 SyncSession::BuildForNudge( | 472 SyncSession::Build( |
| 465 session_context_, | 473 session_context_, |
| 466 this, | 474 this, |
| 467 nudge_tracker_.GetSourceInfo(), | 475 nudge_tracker_.GetSourceInfo())); |
| 468 &nudge_tracker_)); | 476 bool premature_exit = !syncer_->NormalSyncShare( |
| 469 bool premature_exit = !syncer_->SyncShare(session.get(), | 477 GetEnabledAndUnthrottledTypes(), |
| 470 SYNCER_BEGIN, | 478 nudge_tracker_, |
| 471 SYNCER_END); | 479 session.get()); |
| 472 AdjustPolling(FORCE_RESET); | 480 AdjustPolling(FORCE_RESET); |
| 473 | 481 |
| 474 bool success = !premature_exit | 482 bool success = !premature_exit |
| 475 && !sessions::HasSyncerError( | 483 && !sessions::HasSyncerError( |
| 476 session->status_controller().model_neutral_state()); | 484 session->status_controller().model_neutral_state()); |
| 477 | 485 |
| 478 if (success) { | 486 if (success) { |
| 479 // That cycle took care of any outstanding work we had. | 487 // That cycle took care of any outstanding work we had. |
| 480 SDVLOG(2) << "Nudge succeeded."; | 488 SDVLOG(2) << "Nudge succeeded."; |
| 481 nudge_tracker_.RecordSuccessfulSyncCycle(); | 489 nudge_tracker_.RecordSuccessfulSyncCycle(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 500 } | 508 } |
| 501 | 509 |
| 502 SDVLOG(2) << "Will run configure SyncShare with routes " | 510 SDVLOG(2) << "Will run configure SyncShare with routes " |
| 503 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 511 << ModelSafeRoutingInfoToString(session_context_->routing_info()); |
| 504 SyncSourceInfo source_info(pending_configure_params_->source, | 512 SyncSourceInfo source_info(pending_configure_params_->source, |
| 505 ModelSafeRoutingInfoToInvalidationMap( | 513 ModelSafeRoutingInfoToInvalidationMap( |
| 506 session_context_->routing_info(), | 514 session_context_->routing_info(), |
| 507 std::string())); | 515 std::string())); |
| 508 scoped_ptr<SyncSession> session( | 516 scoped_ptr<SyncSession> session( |
| 509 SyncSession::Build(session_context_, this, source_info)); | 517 SyncSession::Build(session_context_, this, source_info)); |
| 510 bool premature_exit = !syncer_->SyncShare(session.get(), | 518 bool premature_exit = !syncer_->ConfigureSyncShare( |
| 511 DOWNLOAD_UPDATES, | 519 GetRoutingInfoTypes(session_context_->routing_info()), |
| 512 APPLY_UPDATES); | 520 session.get()); |
| 513 AdjustPolling(FORCE_RESET); | 521 AdjustPolling(FORCE_RESET); |
| 514 | 522 |
| 515 bool success = !premature_exit | 523 bool success = !premature_exit |
| 516 && !sessions::HasSyncerError( | 524 && !sessions::HasSyncerError( |
| 517 session->status_controller().model_neutral_state()); | 525 session->status_controller().model_neutral_state()); |
| 518 | 526 |
| 519 if (success) { | 527 if (success) { |
| 520 SDVLOG(2) << "Configure succeeded."; | 528 SDVLOG(2) << "Configure succeeded."; |
| 521 pending_configure_params_->ready_task.Run(); | 529 pending_configure_params_->ready_task.Run(); |
| 522 pending_configure_params_.reset(); | 530 pending_configure_params_.reset(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 | 570 |
| 563 if (mode_ != NORMAL_MODE) { | 571 if (mode_ != NORMAL_MODE) { |
| 564 SDVLOG(2) << "Not running poll job in configure mode."; | 572 SDVLOG(2) << "Not running poll job in configure mode."; |
| 565 return; | 573 return; |
| 566 } | 574 } |
| 567 | 575 |
| 568 SDVLOG(2) << "Polling with routes " | 576 SDVLOG(2) << "Polling with routes " |
| 569 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 577 << ModelSafeRoutingInfoToString(session_context_->routing_info()); |
| 570 scoped_ptr<SyncSession> session( | 578 scoped_ptr<SyncSession> session( |
| 571 SyncSession::Build(session_context_, this, info)); | 579 SyncSession::Build(session_context_, this, info)); |
| 572 syncer_->SyncShare(session.get(), DOWNLOAD_UPDATES, APPLY_UPDATES); | 580 syncer_->PollSyncShare( |
| 581 GetEnabledAndUnthrottledTypes(), |
| 582 session.get()); |
| 573 | 583 |
| 574 AdjustPolling(UPDATE_INTERVAL); | 584 AdjustPolling(UPDATE_INTERVAL); |
| 575 | 585 |
| 576 if (IsCurrentlyThrottled()) { | 586 if (IsCurrentlyThrottled()) { |
| 577 SDVLOG(2) << "Poll request got us throttled."; | 587 SDVLOG(2) << "Poll request got us throttled."; |
| 578 // The OnSilencedUntil() call set up the WaitInterval for us. All we need | 588 // The OnSilencedUntil() call set up the WaitInterval for us. All we need |
| 579 // to do is start the timer. | 589 // to do is start the timer. |
| 580 RestartWaiting(); | 590 RestartWaiting(); |
| 581 } | 591 } |
| 582 } | 592 } |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 | 897 |
| 888 #undef SDVLOG_LOC | 898 #undef SDVLOG_LOC |
| 889 | 899 |
| 890 #undef SDVLOG | 900 #undef SDVLOG |
| 891 | 901 |
| 892 #undef SLOG | 902 #undef SLOG |
| 893 | 903 |
| 894 #undef ENUM_CASE | 904 #undef ENUM_CASE |
| 895 | 905 |
| 896 } // namespace syncer | 906 } // namespace syncer |
| OLD | NEW |