Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: sync/engine/sync_scheduler_impl.cc

Issue 146113003: sync: GU retry with less explicit TimeTicks logic (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more comment update Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 227 }
228 228
229 DCHECK(!session_context_->account_name().empty()); 229 DCHECK(!session_context_->account_name().empty());
230 DCHECK(syncer_.get()); 230 DCHECK(syncer_.get());
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_ && 235 if (old_mode != mode_ &&
236 mode_ == NORMAL_MODE && 236 mode_ == NORMAL_MODE &&
237 (nudge_tracker_.IsSyncRequired() || 237 (nudge_tracker_.IsSyncRequired() || nudge_tracker_.IsRetryRequired()) &&
238 nudge_tracker_.IsRetryRequired(base::TimeTicks::Now())) &&
239 CanRunNudgeJobNow(NORMAL_PRIORITY)) { 238 CanRunNudgeJobNow(NORMAL_PRIORITY)) {
240 // We just got back to normal mode. Let's try to run the work that was 239 // We just got back to normal mode. Let's try to run the work that was
241 // queued up while we were configuring. 240 // queued up while we were configuring.
242 TrySyncSessionJob(); 241 TrySyncSessionJob();
243 } 242 }
244 } 243 }
245 244
246 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() { 245 ModelTypeSet SyncSchedulerImpl::GetEnabledAndUnthrottledTypes() {
247 ModelTypeSet enabled_types = session_context_->enabled_types(); 246 ModelTypeSet enabled_types = session_context_->enabled_types();
248 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes(); 247 ModelTypeSet throttled_types = nudge_tracker_.GetThrottledTypes();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // Don't run poll job till the next time poll timer fires. 462 // Don't run poll job till the next time poll timer fires.
464 do_poll_after_credentials_updated_ = false; 463 do_poll_after_credentials_updated_ = false;
465 464
466 bool success = !premature_exit 465 bool success = !premature_exit
467 && !sessions::HasSyncerError( 466 && !sessions::HasSyncerError(
468 session->status_controller().model_neutral_state()); 467 session->status_controller().model_neutral_state());
469 468
470 if (success) { 469 if (success) {
471 // That cycle took care of any outstanding work we had. 470 // That cycle took care of any outstanding work we had.
472 SDVLOG(2) << "Nudge succeeded."; 471 SDVLOG(2) << "Nudge succeeded.";
473 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); 472 nudge_tracker_.RecordSuccessfulSyncCycle();
474 scheduled_nudge_time_ = base::TimeTicks(); 473 scheduled_nudge_time_ = base::TimeTicks();
475 474
476 // If we're here, then we successfully reached the server. End all backoff. 475 // If we're here, then we successfully reached the server. End all backoff.
477 wait_interval_.reset(); 476 wait_interval_.reset();
478 NotifyRetryTime(base::Time()); 477 NotifyRetryTime(base::Time());
479 return;
480 } else { 478 } else {
481 HandleFailure(session->status_controller().model_neutral_state()); 479 HandleFailure(session->status_controller().model_neutral_state());
482 } 480 }
483 } 481 }
484 482
485 void SyncSchedulerImpl::DoConfigurationSyncSessionJob(JobPriority priority) { 483 void SyncSchedulerImpl::DoConfigurationSyncSessionJob(JobPriority priority) {
486 DCHECK(CalledOnValidThread()); 484 DCHECK(CalledOnValidThread());
487 DCHECK_EQ(mode_, CONFIGURATION_MODE); 485 DCHECK_EQ(mode_, CONFIGURATION_MODE);
488 DCHECK(pending_configure_params_ != NULL); 486 DCHECK(pending_configure_params_ != NULL);
489 487
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 571
574 base::AutoReset<bool> protector(&no_scheduling_allowed_, true); 572 base::AutoReset<bool> protector(&no_scheduling_allowed_, true);
575 573
576 SDVLOG(2) << "Retrying with types " 574 SDVLOG(2) << "Retrying with types "
577 << ModelTypeSetToString(GetEnabledAndUnthrottledTypes()); 575 << ModelTypeSetToString(GetEnabledAndUnthrottledTypes());
578 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); 576 scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this));
579 if (syncer_->RetrySyncShare(GetEnabledAndUnthrottledTypes(), 577 if (syncer_->RetrySyncShare(GetEnabledAndUnthrottledTypes(),
580 session.get()) && 578 session.get()) &&
581 !sessions::HasSyncerError( 579 !sessions::HasSyncerError(
582 session->status_controller().model_neutral_state())) { 580 session->status_controller().model_neutral_state())) {
583 nudge_tracker_.RecordSuccessfulSyncCycle(base::TimeTicks::Now()); 581 nudge_tracker_.RecordSuccessfulSyncCycle();
584 } else { 582 } else {
585 HandleFailure(session->status_controller().model_neutral_state()); 583 HandleFailure(session->status_controller().model_neutral_state());
586 } 584 }
587 } 585 }
588 586
589 void SyncSchedulerImpl::UpdateNudgeTimeRecords(ModelTypeSet types) { 587 void SyncSchedulerImpl::UpdateNudgeTimeRecords(ModelTypeSet types) {
590 DCHECK(CalledOnValidThread()); 588 DCHECK(CalledOnValidThread());
591 base::TimeTicks now = TimeTicks::Now(); 589 base::TimeTicks now = TimeTicks::Now();
592 // Update timing information for how often datatypes are triggering nudges. 590 // Update timing information for how often datatypes are triggering nudges.
593 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { 591 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 // access token will be here. 678 // access token will be here.
681 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 679 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
682 &SyncSchedulerImpl::TrySyncSessionJobImpl, 680 &SyncSchedulerImpl::TrySyncSessionJobImpl,
683 weak_ptr_factory_.GetWeakPtr())); 681 weak_ptr_factory_.GetWeakPtr()));
684 } 682 }
685 683
686 void SyncSchedulerImpl::TrySyncSessionJobImpl() { 684 void SyncSchedulerImpl::TrySyncSessionJobImpl() {
687 JobPriority priority = next_sync_session_job_priority_; 685 JobPriority priority = next_sync_session_job_priority_;
688 next_sync_session_job_priority_ = NORMAL_PRIORITY; 686 next_sync_session_job_priority_ = NORMAL_PRIORITY;
689 687
688 nudge_tracker_.SetSyncCycleStartTime(base::TimeTicks::Now());
689
690 DCHECK(CalledOnValidThread()); 690 DCHECK(CalledOnValidThread());
691 if (mode_ == CONFIGURATION_MODE) { 691 if (mode_ == CONFIGURATION_MODE) {
692 if (pending_configure_params_) { 692 if (pending_configure_params_) {
693 SDVLOG(2) << "Found pending configure job"; 693 SDVLOG(2) << "Found pending configure job";
694 DoConfigurationSyncSessionJob(priority); 694 DoConfigurationSyncSessionJob(priority);
695 } 695 }
696 } else if (CanRunNudgeJobNow(priority)) { 696 } else if (CanRunNudgeJobNow(priority)) {
697 if (nudge_tracker_.IsSyncRequired()) { 697 if (nudge_tracker_.IsSyncRequired()) {
698 SDVLOG(2) << "Found pending nudge job"; 698 SDVLOG(2) << "Found pending nudge job";
699 DoNudgeSyncSessionJob(priority); 699 DoNudgeSyncSessionJob(priority);
700 } else if (nudge_tracker_.IsRetryRequired(base::TimeTicks::Now())) { 700 } else if (nudge_tracker_.IsRetryRequired()) {
701 DoRetrySyncSessionJob(); 701 DoRetrySyncSessionJob();
702 } else if (do_poll_after_credentials_updated_ || 702 } else if (do_poll_after_credentials_updated_ ||
703 ((base::TimeTicks::Now() - last_poll_reset_) >= GetPollInterval())) { 703 ((base::TimeTicks::Now() - last_poll_reset_) >= GetPollInterval())) {
704 DoPollSyncSessionJob(); 704 DoPollSyncSessionJob();
705 // Poll timer fires infrequently. Usually by this time access token is 705 // Poll timer fires infrequently. Usually by this time access token is
706 // already expired and poll job will fail with auth error. Set flag to 706 // already expired and poll job will fail with auth error. Set flag to
707 // retry poll once ProfileSyncService gets new access token, TryCanaryJob 707 // retry poll once ProfileSyncService gets new access token, TryCanaryJob
708 // will be called after access token is retrieved. 708 // will be called after access token is retrieved.
709 if (HttpResponse::SYNC_AUTH_ERROR == 709 if (HttpResponse::SYNC_AUTH_ERROR ==
710 session_context_->connection_manager()->server_status()) { 710 session_context_->connection_manager()->server_status()) {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 if (ShouldRequestEarlyExit( 899 if (ShouldRequestEarlyExit(
900 snapshot.model_neutral_state().sync_protocol_error)) { 900 snapshot.model_neutral_state().sync_protocol_error)) {
901 SDVLOG(2) << "Sync Scheduler requesting early exit."; 901 SDVLOG(2) << "Sync Scheduler requesting early exit.";
902 Stop(); 902 Stop();
903 } 903 }
904 if (IsActionableError(snapshot.model_neutral_state().sync_protocol_error)) 904 if (IsActionableError(snapshot.model_neutral_state().sync_protocol_error))
905 OnActionableError(snapshot); 905 OnActionableError(snapshot);
906 } 906 }
907 907
908 void SyncSchedulerImpl::OnReceivedGuRetryDelay(const base::TimeDelta& delay) { 908 void SyncSchedulerImpl::OnReceivedGuRetryDelay(const base::TimeDelta& delay) {
909 nudge_tracker_.set_next_retry_time(base::TimeTicks::Now() + delay); 909 nudge_tracker_.SetNextRetryTime(TimeTicks::Now() + delay);
910 retry_timer_.Start(FROM_HERE, delay, this, 910 retry_timer_.Start(FROM_HERE, delay, this,
911 &SyncSchedulerImpl::RetryTimerCallback); 911 &SyncSchedulerImpl::RetryTimerCallback);
912 } 912 }
913 913
914 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { 914 void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) {
915 DCHECK(CalledOnValidThread()); 915 DCHECK(CalledOnValidThread());
916 session_context_->set_notifications_enabled(notifications_enabled); 916 session_context_->set_notifications_enabled(notifications_enabled);
917 if (notifications_enabled) 917 if (notifications_enabled)
918 nudge_tracker_.OnInvalidationsEnabled(); 918 nudge_tracker_.OnInvalidationsEnabled();
919 else 919 else
920 nudge_tracker_.OnInvalidationsDisabled(); 920 nudge_tracker_.OnInvalidationsDisabled();
921 } 921 }
922 922
923 base::TimeDelta SyncSchedulerImpl::GetSessionsCommitDelay() const { 923 base::TimeDelta SyncSchedulerImpl::GetSessionsCommitDelay() const {
924 DCHECK(CalledOnValidThread()); 924 DCHECK(CalledOnValidThread());
925 return sessions_commit_delay_; 925 return sessions_commit_delay_;
926 } 926 }
927 927
928 #undef SDVLOG_LOC 928 #undef SDVLOG_LOC
929 929
930 #undef SDVLOG 930 #undef SDVLOG
931 931
932 #undef SLOG 932 #undef SLOG
933 933
934 #undef ENUM_CASE 934 #undef ENUM_CASE
935 935
936 } // namespace syncer 936 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698