Index: sync/engine/sync_scheduler_impl.cc |
diff --git a/sync/engine/sync_scheduler_impl.cc b/sync/engine/sync_scheduler_impl.cc |
index 6a4f1efa80a89cdec7e12a25534cbf0b772997b5..b82dcb41aed14c2df92c6f543aa6713e74bfb6b9 100644 |
--- a/sync/engine/sync_scheduler_impl.cc |
+++ b/sync/engine/sync_scheduler_impl.cc |
@@ -14,6 +14,7 @@ |
#include "base/location.h" |
#include "base/logging.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/time/default_clock.h" |
#include "sync/engine/backoff_delay_provider.h" |
#include "sync/engine/syncer.h" |
#include "sync/notifier/object_id_invalidation_map.h" |
@@ -165,6 +166,7 @@ SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name, |
TimeDelta::FromSeconds(kDefaultSessionsCommitDelaySeconds)), |
mode_(NORMAL_MODE), |
delay_provider_(delay_provider), |
+ nudge_tracker_(new base::DefaultClock), |
syncer_(syncer), |
session_context_(context), |
no_scheduling_allowed_(false), |
@@ -234,7 +236,7 @@ void SyncSchedulerImpl::Start(Mode mode) { |
if (old_mode != mode_ && |
mode_ == NORMAL_MODE && |
- nudge_tracker_.IsSyncRequired() && |
+ (nudge_tracker_.IsSyncRequired() || nudge_tracker_.IsRetryRequired()) && |
CanRunNudgeJobNow(NORMAL_PRIORITY)) { |
// We just got back to normal mode. Let's try to run the work that was |
// queued up while we were configuring. |
@@ -549,18 +551,8 @@ void SyncSchedulerImpl::HandleFailure( |
void SyncSchedulerImpl::DoPollSyncSessionJob() { |
base::AutoReset<bool> protector(&no_scheduling_allowed_, true); |
- if (!CanRunJobNow(NORMAL_PRIORITY)) { |
- SDVLOG(2) << "Unable to run a poll job right now."; |
- return; |
- } |
- |
- if (mode_ != NORMAL_MODE) { |
- SDVLOG(2) << "Not running poll job in configure mode."; |
- return; |
- } |
- |
SDVLOG(2) << "Polling with types " |
- << ModelTypeSetToString(session_context_->enabled_types()); |
+ << ModelTypeSetToString(GetEnabledAndUnthrottledTypes()); |
scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); |
syncer_->PollSyncShare( |
GetEnabledAndUnthrottledTypes(), |
@@ -576,6 +568,25 @@ void SyncSchedulerImpl::DoPollSyncSessionJob() { |
} |
} |
+void SyncSchedulerImpl::DoRetrySyncSessionJob() { |
+ DCHECK(CalledOnValidThread()); |
+ DCHECK_EQ(mode_, NORMAL_MODE); |
+ |
+ base::AutoReset<bool> protector(&no_scheduling_allowed_, true); |
+ |
+ SDVLOG(2) << "Retrying with types " |
+ << ModelTypeSetToString(GetEnabledAndUnthrottledTypes()); |
+ scoped_ptr<SyncSession> session(SyncSession::Build(session_context_, this)); |
+ if (syncer_->RetrySyncShare(GetEnabledAndUnthrottledTypes(), |
+ session.get()) && |
+ !sessions::HasSyncerError( |
+ session->status_controller().model_neutral_state())) { |
+ nudge_tracker_.RecordSuccessfulSyncCycle(); |
+ } else { |
+ HandleFailure(session->status_controller().model_neutral_state()); |
+ } |
+} |
+ |
void SyncSchedulerImpl::UpdateNudgeTimeRecords(ModelTypeSet types) { |
DCHECK(CalledOnValidThread()); |
base::TimeTicks now = TimeTicks::Now(); |
@@ -685,9 +696,14 @@ void SyncSchedulerImpl::TrySyncSessionJobImpl() { |
} |
} else { |
DCHECK(mode_ == NORMAL_MODE); |
- if (nudge_tracker_.IsSyncRequired() && CanRunNudgeJobNow(priority)) { |
+ if (!CanRunNudgeJobNow(priority)) |
+ return; |
pavely
2014/01/08 00:59:56
Please don't do early return from this function. T
haitaol1
2014/01/08 19:06:38
Done.
|
+ |
+ if (nudge_tracker_.IsSyncRequired()) { |
SDVLOG(2) << "Found pending nudge job"; |
DoNudgeSyncSessionJob(priority); |
+ } else if (nudge_tracker_.IsRetryRequired()) { |
+ DoRetrySyncSessionJob(); |
} else if (do_poll_after_credentials_updated_ || |
((base::TimeTicks::Now() - last_poll_reset_) >= GetPollInterval())) { |
DoPollSyncSessionJob(); |
@@ -737,6 +753,10 @@ void SyncSchedulerImpl::PollTimerCallback() { |
TrySyncSessionJob(); |
} |
+void SyncSchedulerImpl::RetryTimerCallback() { |
+ TrySyncSessionJob(); |
+} |
+ |
void SyncSchedulerImpl::Unthrottle() { |
DCHECK(CalledOnValidThread()); |
DCHECK_EQ(WaitInterval::THROTTLED, wait_interval_->mode); |
@@ -890,6 +910,13 @@ void SyncSchedulerImpl::OnSyncProtocolError( |
OnActionableError(snapshot); |
} |
+void SyncSchedulerImpl::OnReceivedGuRetryDelaySeconds(int delay_seconds) { |
+ nudge_tracker_.set_next_retry_time( |
+ base::Time::Now() + base::TimeDelta::FromSeconds(delay_seconds)); |
+ retry_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay_seconds), |
+ this, &SyncSchedulerImpl::RetryTimerCallback); |
+} |
+ |
void SyncSchedulerImpl::SetNotificationsEnabled(bool notifications_enabled) { |
DCHECK(CalledOnValidThread()); |
session_context_->set_notifications_enabled(notifications_enabled); |