| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 mode_ == NORMAL_MODE && | 235 mode_ == NORMAL_MODE && |
| 236 nudge_tracker_.IsSyncRequired() && | 236 nudge_tracker_.IsSyncRequired() && |
| 237 CanRunNudgeJobNow(NORMAL_PRIORITY)) { | 237 CanRunNudgeJobNow(NORMAL_PRIORITY)) { |
| 238 // We just got back to normal mode. Let's try to run the work that was | 238 // We just got back to normal mode. Let's try to run the work that was |
| 239 // queued up while we were configuring. | 239 // queued up while we were configuring. |
| 240 TrySyncSessionJob(NORMAL_PRIORITY); | 240 TrySyncSessionJob(NORMAL_PRIORITY); |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { | 244 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { |
| 245 ModelTypeSet enabled_types = | 245 ModelTypeSet enabled_types = session_context_->enabled_types(); |
| 246 GetRoutingInfoTypes(session_context_->routing_info()); | 246 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); |
| 247 ModelTypeSet throttled_types = | |
| 248 nudge_tracker_.GetThrottledTypes(); | |
| 249 return Difference(enabled_types, throttled_types); | 247 return Difference(enabled_types, throttled_types); |
| 250 } | 248 } |
| 251 | 249 |
| 252 void SyncSchedulerImpl::SendInitialSnapshot() { | 250 void SyncSchedulerImpl::SendInitialSnapshot() { |
| 253 DCHECK(CalledOnValidThread()); | 251 DCHECK(CalledOnValidThread()); |
| 254 scoped_ptr<SyncSession> dummy(SyncSession::Build(session_context_, this)); | 252 scoped_ptr<SyncSession> dummy(SyncSession::Build(session_context_, this)); |
| 255 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); | 253 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); |
| 256 event.snapshot = dummy->TakeSnapshot(); | 254 event.snapshot = dummy->TakeSnapshot(); |
| 257 session_context_->NotifyListeners(event); | 255 session_context_->NotifyListeners(event); |
| 258 } | 256 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 327 } |
| 330 | 328 |
| 331 bool SyncSchedulerImpl::CanRunNudgeJobNow(JobPriority priority) { | 329 bool SyncSchedulerImpl::CanRunNudgeJobNow(JobPriority priority) { |
| 332 DCHECK(CalledOnValidThread()); | 330 DCHECK(CalledOnValidThread()); |
| 333 | 331 |
| 334 if (!CanRunJobNow(priority)) { | 332 if (!CanRunJobNow(priority)) { |
| 335 SDVLOG(1) << "Unable to run a nudge job right now"; | 333 SDVLOG(1) << "Unable to run a nudge job right now"; |
| 336 return false; | 334 return false; |
| 337 } | 335 } |
| 338 | 336 |
| 339 const ModelTypeSet enabled_types = | 337 const ModelTypeSet enabled_types = session_context_->enabled_types(); |
| 340 GetRoutingInfoTypes(session_context_->routing_info()); | |
| 341 if (nudge_tracker_.GetThrottledTypes().HasAll(enabled_types)) { | 338 if (nudge_tracker_.GetThrottledTypes().HasAll(enabled_types)) { |
| 342 SDVLOG(1) << "Not running a nudge because we're fully type throttled."; | 339 SDVLOG(1) << "Not running a nudge because we're fully type throttled."; |
| 343 return false; | 340 return false; |
| 344 } | 341 } |
| 345 | 342 |
| 346 if (mode_ == CONFIGURATION_MODE) { | 343 if (mode_ == CONFIGURATION_MODE) { |
| 347 SDVLOG(1) << "Not running nudge because we're in configuration mode."; | 344 SDVLOG(1) << "Not running nudge because we're in configuration mode."; |
| 348 return false; | 345 return false; |
| 349 } | 346 } |
| 350 | 347 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 ENUM_CASE(CONFIGURATION_MODE); | 449 ENUM_CASE(CONFIGURATION_MODE); |
| 453 ENUM_CASE(NORMAL_MODE); | 450 ENUM_CASE(NORMAL_MODE); |
| 454 } | 451 } |
| 455 return ""; | 452 return ""; |
| 456 } | 453 } |
| 457 | 454 |
| 458 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) { | 455 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) { |
| 459 DCHECK(CalledOnValidThread()); | 456 DCHECK(CalledOnValidThread()); |
| 460 DCHECK(CanRunNudgeJobNow(priority)); | 457 DCHECK(CanRunNudgeJobNow(priority)); |
| 461 | 458 |
| 462 DVLOG(2) << "Will run normal mode sync cycle with routing info " | 459 DVLOG(2) << "Will run normal mode sync cycle with types " |
| 463 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 460 << ModelTypeSetToString(session_context_->enabled_types()); |
| 464 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 461 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); |
| 465 bool premature_exit = !syncer_->NormalSyncShare( | 462 bool premature_exit = !syncer_->NormalSyncShare( |
| 466 GetEnabledAndUnthrottledTypes(), | 463 GetEnabledAndUnthrottledTypes(), |
| 467 nudge_tracker_, | 464 nudge_tracker_, |
| 468 session.get()); | 465 session.get()); |
| 469 AdjustPolling(FORCE_RESET); | 466 AdjustPolling(FORCE_RESET); |
| 470 // Don't run poll job till the next time poll timer fires. | 467 // Don't run poll job till the next time poll timer fires. |
| 471 do_poll_after_credentials_updated_ = false; | 468 do_poll_after_credentials_updated_ = false; |
| 472 | 469 |
| 473 bool success = !premature_exit | 470 bool success = !premature_exit |
| (...skipping 22 matching lines...) Expand all Loading... |
| 496 | 493 |
| 497 if (!CanRunJobNow(priority)) { | 494 if (!CanRunJobNow(priority)) { |
| 498 SDVLOG(2) << "Unable to run configure job right now."; | 495 SDVLOG(2) << "Unable to run configure job right now."; |
| 499 if (!pending_configure_params_->retry_task.is_null()) { | 496 if (!pending_configure_params_->retry_task.is_null()) { |
| 500 pending_configure_params_->retry_task.Run(); | 497 pending_configure_params_->retry_task.Run(); |
| 501 pending_configure_params_->retry_task.Reset(); | 498 pending_configure_params_->retry_task.Reset(); |
| 502 } | 499 } |
| 503 return; | 500 return; |
| 504 } | 501 } |
| 505 | 502 |
| 506 SDVLOG(2) << "Will run configure SyncShare with routes " | 503 SDVLOG(2) << "Will run configure SyncShare with types " |
| 507 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 504 << ModelTypeSetToString(session_context_->enabled_types()); |
| 508 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 505 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); |
| 509 bool premature_exit = !syncer_->ConfigureSyncShare( | 506 bool premature_exit = !syncer_->ConfigureSyncShare( |
| 510 GetRoutingInfoTypes(session_context_->routing_info()), | 507 session_context_->enabled_types(), |
| 511 pending_configure_params_->source, | 508 pending_configure_params_->source, |
| 512 session.get()); | 509 session.get()); |
| 513 AdjustPolling(FORCE_RESET); | 510 AdjustPolling(FORCE_RESET); |
| 514 // Don't run poll job till the next time poll timer fires. | 511 // Don't run poll job till the next time poll timer fires. |
| 515 do_poll_after_credentials_updated_ = false; | 512 do_poll_after_credentials_updated_ = false; |
| 516 | 513 |
| 517 bool success = !premature_exit | 514 bool success = !premature_exit |
| 518 && !sessions::HasSyncerError( | 515 && !sessions::HasSyncerError( |
| 519 session->status_controller().model_neutral_state()); | 516 session->status_controller().model_neutral_state()); |
| 520 | 517 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 if (!CanRunJobNow(NORMAL_PRIORITY)) { | 557 if (!CanRunJobNow(NORMAL_PRIORITY)) { |
| 561 SDVLOG(2) << "Unable to run a poll job right now."; | 558 SDVLOG(2) << "Unable to run a poll job right now."; |
| 562 return; | 559 return; |
| 563 } | 560 } |
| 564 | 561 |
| 565 if (mode_ != NORMAL_MODE) { | 562 if (mode_ != NORMAL_MODE) { |
| 566 SDVLOG(2) << "Not running poll job in configure mode."; | 563 SDVLOG(2) << "Not running poll job in configure mode."; |
| 567 return; | 564 return; |
| 568 } | 565 } |
| 569 | 566 |
| 570 SDVLOG(2) << "Polling with routes " | 567 SDVLOG(2) << "Polling with types " |
| 571 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 568 << ModelTypeSetToString(session_context_->enabled_types()); |
| 572 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 569 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); |
| 573 syncer_->PollSyncShare( | 570 syncer_->PollSyncShare( |
| 574 GetEnabledAndUnthrottledTypes(), | 571 GetEnabledAndUnthrottledTypes(), |
| 575 session.get()); | 572 session.get()); |
| 576 | 573 |
| 577 AdjustPolling(FORCE_RESET); | 574 AdjustPolling(FORCE_RESET); |
| 578 | 575 |
| 579 if (IsCurrentlyThrottled()) { | 576 if (IsCurrentlyThrottled()) { |
| 580 SDVLOG(2) << "Poll request got us throttled."; | 577 SDVLOG(2) << "Poll request got us throttled."; |
| 581 // The OnSilencedUntil() call set up the WaitInterval for us. All we need | 578 // The OnSilencedUntil() call set up the WaitInterval for us. All we need |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 | 895 |
| 899 #undef SDVLOG_LOC | 896 #undef SDVLOG_LOC |
| 900 | 897 |
| 901 #undef SDVLOG | 898 #undef SDVLOG |
| 902 | 899 |
| 903 #undef SLOG | 900 #undef SLOG |
| 904 | 901 |
| 905 #undef ENUM_CASE | 902 #undef ENUM_CASE |
| 906 | 903 |
| 907 } // namespace syncer | 904 } // namespace syncer |
| OLD | NEW |