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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 Mode old_mode = mode_; | 231 Mode old_mode = mode_; |
232 mode_ = mode; | 232 mode_ = mode; |
233 AdjustPolling(UPDATE_INTERVAL); // Will kick start poll timer if needed. | 233 AdjustPolling(UPDATE_INTERVAL); // Will kick start poll timer if needed. |
234 | 234 |
235 if (old_mode != mode_ && mode_ == NORMAL_MODE) { | 235 if (old_mode != mode_ && mode_ == NORMAL_MODE) { |
236 // We just got back to normal mode. Let's try to run the work that was | 236 // We just got back to normal mode. Let's try to run the work that was |
237 // queued up while we were configuring. | 237 // queued up while we were configuring. |
238 | 238 |
239 // Update our current time before checking IsRetryRequired(). | 239 // Update our current time before checking IsRetryRequired(). |
240 nudge_tracker_.SetSyncCycleStartTime(base::TimeTicks::Now()); | 240 nudge_tracker_.SetSyncCycleStartTime(base::TimeTicks::Now()); |
241 if ((nudge_tracker_.IsSyncRequired() || nudge_tracker_.IsRetryRequired()) && | 241 if (nudge_tracker_.IsSyncRequired() && CanRunNudgeJobNow(NORMAL_PRIORITY)) { |
242 CanRunNudgeJobNow(NORMAL_PRIORITY)) { | |
243 TrySyncSessionJob(); | 242 TrySyncSessionJob(); |
244 } | 243 } |
245 } | 244 } |
246 } | 245 } |
247 | 246 |
248 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { | 247 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { |
249 ModelTypeSet enabled_types = session_context_->enabled_types(); | 248 ModelTypeSet enabled_types = session_context_->enabled_types(); |
250 ModelTypeSet enabled_protocol_types = | 249 ModelTypeSet enabled_protocol_types = |
251 Intersection(ProtocolTypes(), enabled_types); | 250 Intersection(ProtocolTypes(), enabled_types); |
252 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); | 251 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 AdjustPolling(FORCE_RESET); | 564 AdjustPolling(FORCE_RESET); |
566 | 565 |
567 if (IsCurrentlyThrottled()) { | 566 if (IsCurrentlyThrottled()) { |
568 SDVLOG(2) << "Poll request got us throttled."; | 567 SDVLOG(2) << "Poll request got us throttled."; |
569 // The OnSilencedUntil() call set up the WaitInterval for us. All we need | 568 // The OnSilencedUntil() call set up the WaitInterval for us. All we need |
570 // to do is start the timer. | 569 // to do is start the timer. |
571 RestartWaiting(); | 570 RestartWaiting(); |
572 } | 571 } |
573 } | 572 } |
574 | 573 |
575 void SyncSchedulerImpl::DoRetrySyncSessionJob() { | |
576 DCHECK(CalledOnValidThread()); | |
577 DCHECK_EQ(mode_, NORMAL_MODE); | |
578 | |
579 base::AutoReset<bool> protector(&no_scheduling_allowed_, true); | |
580 | |
581 SDVLOG(2) << "Retrying with types " | |
582 << ModelTypeSetToString(GetEnabledAndUnthrottledTypes()); | |
583 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); | |
584 if (syncer_->RetrySyncShare(GetEnabledAndUnthrottledTypes(), | |
585 session.get()) && | |
586 !sessions::HasSyncerError( | |
587 session->status_controller().model_neutral_state())) { | |
588 nudge_tracker_.RecordSuccessfulSyncCycle(); | |
589 } else { | |
590 HandleFailure(session->status_controller().model_neutral_state()); | |
591 } | |
592 } | |
593 | |
594 void SyncSchedulerImpl::UpdateNudgeTimeRecords(ModelTypeSet types) { | 574 void SyncSchedulerImpl::UpdateNudgeTimeRecords(ModelTypeSet types) { |
595 DCHECK(CalledOnValidThread()); | 575 DCHECK(CalledOnValidThread()); |
596 base::TimeTicks now = TimeTicks::Now(); | 576 base::TimeTicks now = TimeTicks::Now(); |
597 // Update timing information for how often datatypes are triggering nudges. | 577 // Update timing information for how often datatypes are triggering nudges. |
598 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { | 578 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { |
599 base::TimeTicks previous = last_local_nudges_by_model_type_[iter.Get()]; | 579 base::TimeTicks previous = last_local_nudges_by_model_type_[iter.Get()]; |
600 last_local_nudges_by_model_type_[iter.Get()] = now; | 580 last_local_nudges_by_model_type_[iter.Get()] = now; |
601 if (previous.is_null()) | 581 if (previous.is_null()) |
602 continue; | 582 continue; |
603 | 583 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 DCHECK(CalledOnValidThread()); | 677 DCHECK(CalledOnValidThread()); |
698 if (mode_ == CONFIGURATION_MODE) { | 678 if (mode_ == CONFIGURATION_MODE) { |
699 if (pending_configure_params_) { | 679 if (pending_configure_params_) { |
700 SDVLOG(2) << "Found pending configure job"; | 680 SDVLOG(2) << "Found pending configure job"; |
701 DoConfigurationSyncSessionJob(priority); | 681 DoConfigurationSyncSessionJob(priority); |
702 } | 682 } |
703 } else if (CanRunNudgeJobNow(priority)) { | 683 } else if (CanRunNudgeJobNow(priority)) { |
704 if (nudge_tracker_.IsSyncRequired()) { | 684 if (nudge_tracker_.IsSyncRequired()) { |
705 SDVLOG(2) << "Found pending nudge job"; | 685 SDVLOG(2) << "Found pending nudge job"; |
706 DoNudgeSyncSessionJob(priority); | 686 DoNudgeSyncSessionJob(priority); |
707 } else if (nudge_tracker_.IsRetryRequired()) { | |
708 DoRetrySyncSessionJob(); | |
709 } else if (do_poll_after_credentials_updated_ || | 687 } else if (do_poll_after_credentials_updated_ || |
710 ((base::TimeTicks::Now() - last_poll_reset_) >= GetPollInterval())) { | 688 ((base::TimeTicks::Now() - last_poll_reset_) >= GetPollInterval())) { |
711 DoPollSyncSessionJob(); | 689 DoPollSyncSessionJob(); |
712 // Poll timer fires infrequently. Usually by this time access token is | 690 // Poll timer fires infrequently. Usually by this time access token is |
713 // already expired and poll job will fail with auth error. Set flag to | 691 // already expired and poll job will fail with auth error. Set flag to |
714 // retry poll once ProfileSyncService gets new access token, TryCanaryJob | 692 // retry poll once ProfileSyncService gets new access token, TryCanaryJob |
715 // will be called after access token is retrieved. | 693 // will be called after access token is retrieved. |
716 if (HttpResponse::SYNC_AUTH_ERROR == | 694 if (HttpResponse::SYNC_AUTH_ERROR == |
717 session_context_->connection_manager()->server_status()) { | 695 session_context_->connection_manager()->server_status()) { |
718 do_poll_after_credentials_updated_ = true; | 696 do_poll_after_credentials_updated_ = true; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 | 908 |
931 #undef SDVLOG_LOC | 909 #undef SDVLOG_LOC |
932 | 910 |
933 #undef SDVLOG | 911 #undef SDVLOG |
934 | 912 |
935 #undef SLOG | 913 #undef SLOG |
936 | 914 |
937 #undef ENUM_CASE | 915 #undef ENUM_CASE |
938 | 916 |
939 } // namespace syncer | 917 } // namespace syncer |
OLD | NEW |