| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 mode_ == NORMAL_MODE && | 232 mode_ == NORMAL_MODE && |
| 233 nudge_tracker_.IsSyncRequired() && | 233 nudge_tracker_.IsSyncRequired() && |
| 234 CanRunNudgeJobNow(NORMAL_PRIORITY)) { | 234 CanRunNudgeJobNow(NORMAL_PRIORITY)) { |
| 235 // We just got back to normal mode. Let's try to run the work that was | 235 // We just got back to normal mode. Let's try to run the work that was |
| 236 // queued up while we were configuring. | 236 // queued up while we were configuring. |
| 237 DoNudgeSyncSessionJob(NORMAL_PRIORITY); | 237 DoNudgeSyncSessionJob(NORMAL_PRIORITY); |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 | 240 |
| 241 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { | 241 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { |
| 242 ModelTypeSet enabled_types = | 242 ModelTypeSet enabled_types = session_context_->enabled_types(); |
| 243 GetRoutingInfoTypes(session_context_->routing_info()); | 243 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); |
| 244 ModelTypeSet throttled_types = | |
| 245 nudge_tracker_.GetThrottledTypes(); | |
| 246 return Difference(enabled_types, throttled_types); | 244 return Difference(enabled_types, throttled_types); |
| 247 } | 245 } |
| 248 | 246 |
| 249 void SyncSchedulerImpl::SendInitialSnapshot() { | 247 void SyncSchedulerImpl::SendInitialSnapshot() { |
| 250 DCHECK(CalledOnValidThread()); | 248 DCHECK(CalledOnValidThread()); |
| 251 scoped_ptr<SyncSession> dummy(SyncSession::Build(session_context_, this)); | 249 scoped_ptr<SyncSession> dummy(SyncSession::Build(session_context_, this)); |
| 252 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); | 250 SyncEngineEvent event(SyncEngineEvent::STATUS_CHANGED); |
| 253 event.snapshot = dummy->TakeSnapshot(); | 251 event.snapshot = dummy->TakeSnapshot(); |
| 254 session_context_->NotifyListeners(event); | 252 session_context_->NotifyListeners(event); |
| 255 } | 253 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 335 } |
| 338 | 336 |
| 339 bool SyncSchedulerImpl::CanRunNudgeJobNow(JobPriority priority) { | 337 bool SyncSchedulerImpl::CanRunNudgeJobNow(JobPriority priority) { |
| 340 DCHECK(CalledOnValidThread()); | 338 DCHECK(CalledOnValidThread()); |
| 341 | 339 |
| 342 if (!CanRunJobNow(priority)) { | 340 if (!CanRunJobNow(priority)) { |
| 343 SDVLOG(1) << "Unable to run a nudge job right now"; | 341 SDVLOG(1) << "Unable to run a nudge job right now"; |
| 344 return false; | 342 return false; |
| 345 } | 343 } |
| 346 | 344 |
| 347 const ModelTypeSet enabled_types = | 345 const ModelTypeSet enabled_types = session_context_->enabled_types(); |
| 348 GetRoutingInfoTypes(session_context_->routing_info()); | |
| 349 if (nudge_tracker_.GetThrottledTypes().HasAll(enabled_types)) { | 346 if (nudge_tracker_.GetThrottledTypes().HasAll(enabled_types)) { |
| 350 SDVLOG(1) << "Not running a nudge because we're fully type throttled."; | 347 SDVLOG(1) << "Not running a nudge because we're fully type throttled."; |
| 351 return false; | 348 return false; |
| 352 } | 349 } |
| 353 | 350 |
| 354 if (mode_ == CONFIGURATION_MODE) { | 351 if (mode_ == CONFIGURATION_MODE) { |
| 355 SDVLOG(1) << "Not running nudge because we're in configuration mode."; | 352 SDVLOG(1) << "Not running nudge because we're in configuration mode."; |
| 356 return false; | 353 return false; |
| 357 } | 354 } |
| 358 | 355 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 ENUM_CASE(CONFIGURATION_MODE); | 457 ENUM_CASE(CONFIGURATION_MODE); |
| 461 ENUM_CASE(NORMAL_MODE); | 458 ENUM_CASE(NORMAL_MODE); |
| 462 } | 459 } |
| 463 return ""; | 460 return ""; |
| 464 } | 461 } |
| 465 | 462 |
| 466 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) { | 463 void SyncSchedulerImpl::DoNudgeSyncSessionJob(JobPriority priority) { |
| 467 DCHECK(CalledOnValidThread()); | 464 DCHECK(CalledOnValidThread()); |
| 468 DCHECK(CanRunNudgeJobNow(priority)); | 465 DCHECK(CanRunNudgeJobNow(priority)); |
| 469 | 466 |
| 470 DVLOG(2) << "Will run normal mode sync cycle with routing info " | 467 DVLOG(2) << "Will run normal mode sync cycle with types " |
| 471 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 468 << ModelTypeSetToString(session_context_->enabled_types()); |
| 472 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 469 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); |
| 473 bool premature_exit = !syncer_->NormalSyncShare( | 470 bool premature_exit = !syncer_->NormalSyncShare( |
| 474 GetEnabledAndUnthrottledTypes(), | 471 GetEnabledAndUnthrottledTypes(), |
| 475 nudge_tracker_, | 472 nudge_tracker_, |
| 476 session.get()); | 473 session.get()); |
| 477 AdjustPolling(FORCE_RESET); | 474 AdjustPolling(FORCE_RESET); |
| 478 // Don't run poll job till the next time poll timer fires. | 475 // Don't run poll job till the next time poll timer fires. |
| 479 do_poll_after_credentials_updated_ = false; | 476 do_poll_after_credentials_updated_ = false; |
| 480 | 477 |
| 481 bool success = !premature_exit | 478 bool success = !premature_exit |
| (...skipping 17 matching lines...) Expand all Loading... |
| 499 | 496 |
| 500 bool SyncSchedulerImpl::DoConfigurationSyncSessionJob(JobPriority priority) { | 497 bool SyncSchedulerImpl::DoConfigurationSyncSessionJob(JobPriority priority) { |
| 501 DCHECK(CalledOnValidThread()); | 498 DCHECK(CalledOnValidThread()); |
| 502 DCHECK_EQ(mode_, CONFIGURATION_MODE); | 499 DCHECK_EQ(mode_, CONFIGURATION_MODE); |
| 503 | 500 |
| 504 if (!CanRunJobNow(priority)) { | 501 if (!CanRunJobNow(priority)) { |
| 505 SDVLOG(2) << "Unable to run configure job right now."; | 502 SDVLOG(2) << "Unable to run configure job right now."; |
| 506 return false; | 503 return false; |
| 507 } | 504 } |
| 508 | 505 |
| 509 SDVLOG(2) << "Will run configure SyncShare with routes " | 506 SDVLOG(2) << "Will run configure SyncShare with types " |
| 510 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 507 << ModelTypeSetToString(session_context_->enabled_types()); |
| 511 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 508 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); |
| 512 bool premature_exit = !syncer_->ConfigureSyncShare( | 509 bool premature_exit = !syncer_->ConfigureSyncShare( |
| 513 GetRoutingInfoTypes(session_context_->routing_info()), | 510 session_context_->enabled_types(), |
| 514 pending_configure_params_->source, | 511 pending_configure_params_->source, |
| 515 session.get()); | 512 session.get()); |
| 516 AdjustPolling(FORCE_RESET); | 513 AdjustPolling(FORCE_RESET); |
| 517 // Don't run poll job till the next time poll timer fires. | 514 // Don't run poll job till the next time poll timer fires. |
| 518 do_poll_after_credentials_updated_ = false; | 515 do_poll_after_credentials_updated_ = false; |
| 519 | 516 |
| 520 bool success = !premature_exit | 517 bool success = !premature_exit |
| 521 && !sessions::HasSyncerError( | 518 && !sessions::HasSyncerError( |
| 522 session->status_controller().model_neutral_state()); | 519 session->status_controller().model_neutral_state()); |
| 523 | 520 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 if (!CanRunJobNow(NORMAL_PRIORITY)) { | 556 if (!CanRunJobNow(NORMAL_PRIORITY)) { |
| 560 SDVLOG(2) << "Unable to run a poll job right now."; | 557 SDVLOG(2) << "Unable to run a poll job right now."; |
| 561 return; | 558 return; |
| 562 } | 559 } |
| 563 | 560 |
| 564 if (mode_ != NORMAL_MODE) { | 561 if (mode_ != NORMAL_MODE) { |
| 565 SDVLOG(2) << "Not running poll job in configure mode."; | 562 SDVLOG(2) << "Not running poll job in configure mode."; |
| 566 return; | 563 return; |
| 567 } | 564 } |
| 568 | 565 |
| 569 SDVLOG(2) << "Polling with routes " | 566 SDVLOG(2) << "Polling with types " |
| 570 << ModelSafeRoutingInfoToString(session_context_->routing_info()); | 567 << ModelTypeSetToString(session_context_->enabled_types()); |
| 571 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | 568 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); |
| 572 syncer_->PollSyncShare( | 569 syncer_->PollSyncShare( |
| 573 GetEnabledAndUnthrottledTypes(), | 570 GetEnabledAndUnthrottledTypes(), |
| 574 session.get()); | 571 session.get()); |
| 575 | 572 |
| 576 AdjustPolling(UPDATE_INTERVAL); | 573 AdjustPolling(UPDATE_INTERVAL); |
| 577 | 574 |
| 578 if (IsCurrentlyThrottled()) { | 575 if (IsCurrentlyThrottled()) { |
| 579 SDVLOG(2) << "Poll request got us throttled."; | 576 SDVLOG(2) << "Poll request got us throttled."; |
| 580 // The OnSilencedUntil() call set up the WaitInterval for us. All we need | 577 // The OnSilencedUntil() call set up the WaitInterval for us. All we need |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 | 891 |
| 895 #undef SDVLOG_LOC | 892 #undef SDVLOG_LOC |
| 896 | 893 |
| 897 #undef SDVLOG | 894 #undef SDVLOG |
| 898 | 895 |
| 899 #undef SLOG | 896 #undef SLOG |
| 900 | 897 |
| 901 #undef ENUM_CASE | 898 #undef ENUM_CASE |
| 902 | 899 |
| 903 } // namespace syncer | 900 } // namespace syncer |
| OLD | NEW |