summaryrefslogtreecommitdiffstats
path: root/sync/engine/sync_scheduler_impl.h
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 04:52:10 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 04:52:10 +0000
commit0248d9208d15bb5d7ae5bb482740e90ee62c8b2a (patch)
treebccfd80b2193bd28f921266b0530c88b84cb2ceb /sync/engine/sync_scheduler_impl.h
parent9df2d09c9b836494e8f83a2a7657ba2a9408a23b (diff)
downloadchromium_src-0248d9208d15bb5d7ae5bb482740e90ee62c8b2a.zip
chromium_src-0248d9208d15bb5d7ae5bb482740e90ee62c8b2a.tar.gz
chromium_src-0248d9208d15bb5d7ae5bb482740e90ee62c8b2a.tar.bz2
sync: Finish the SyncScheduler refactor
This change removes SyncSessionJob entirely. The first step towards this goal was to refactor all functions that depended on SyncSessionJob. All these functions have either been inlined or modified to take different parameters instead. DoSyncSessionJob was split into two separate functions, one for configure jobs and one for nudge jobs, which removes the need for SyncSessionJob's "purpose" member. The SyncScheduler's pending_configure_job_ has been replaced with a ConfigParams member, since that was the only part of the job still being referenced. The pending_nudge_job_ has been replaced with scheduled_nudge_time_ (which is similar to the old scheduled_start_ member of SyncSessionJob) and a new object called a NudgeTracker. The NudgeTracker inherits the SyncSessionJob's responsibilities with respect to coalescing nudge sources. The plan is to extend this class to support more sophisticated nudge coalescing in the future. For now it tries to emulate the old SyncSessionJob behaviour as closely as possible. Some of the refactoring does change behaviour. In particular, the decision-making logic has been updated to fix issues 179515 and 155296. BUG=175024,179515,155296 Review URL: https://chromiumcodereview.appspot.com/13743003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194766 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/engine/sync_scheduler_impl.h')
-rw-r--r--sync/engine/sync_scheduler_impl.h91
1 files changed, 38 insertions, 53 deletions
diff --git a/sync/engine/sync_scheduler_impl.h b/sync/engine/sync_scheduler_impl.h
index dfdcc80..efcccd3 100644
--- a/sync/engine/sync_scheduler_impl.h
+++ b/sync/engine/sync_scheduler_impl.h
@@ -22,11 +22,11 @@
#include "sync/engine/net/server_connection_manager.h"
#include "sync/engine/nudge_source.h"
#include "sync/engine/sync_scheduler.h"
-#include "sync/engine/sync_session_job.h"
#include "sync/engine/syncer.h"
#include "sync/internal_api/public/base/model_type_invalidation_map.h"
#include "sync/internal_api/public/engine/polling_constants.h"
#include "sync/internal_api/public/util/weak_handle.h"
+#include "sync/sessions/nudge_tracker.h"
#include "sync/sessions/sync_session.h"
#include "sync/sessions/sync_session_context.h"
@@ -34,6 +34,10 @@ namespace syncer {
class BackoffDelayProvider;
+namespace sessions {
+struct ModelNeutralState;
+}
+
class SYNC_EXPORT_PRIVATE SyncSchedulerImpl
: public SyncScheduler,
public base::NonThreadSafe {
@@ -83,15 +87,6 @@ class SYNC_EXPORT_PRIVATE SyncSchedulerImpl
const sessions::SyncSessionSnapshot& snapshot) OVERRIDE;
private:
- enum JobProcessDecision {
- // Indicates we should continue with the current job.
- CONTINUE,
- // Indicates that we should save it to be processed later.
- SAVE,
- // Indicates we should drop this job.
- DROP,
- };
-
enum JobPriority {
// Non-canary jobs respect exponential backoff.
NORMAL_PRIORITY,
@@ -99,10 +94,18 @@ class SYNC_EXPORT_PRIVATE SyncSchedulerImpl
CANARY_PRIORITY
};
+ enum PollAdjustType {
+ // Restart the poll interval.
+ FORCE_RESET,
+ // Restart the poll interval only if its length has changed.
+ UPDATE_INTERVAL,
+ };
+
friend class SyncSchedulerTest;
friend class SyncSchedulerWhiteboxTest;
friend class SyncerTest;
+ FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, NoNudgesInConfigureMode);
FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest,
DropNudgeWhileExponentialBackOff);
FRIEND_TEST_ALL_PREFIXES(SyncSchedulerWhiteboxTest, SaveNudge);
@@ -145,57 +148,37 @@ class SYNC_EXPORT_PRIVATE SyncSchedulerImpl
static const char* GetModeString(Mode mode);
- static const char* GetDecisionString(JobProcessDecision decision);
-
- // Invoke the syncer to perform a non-POLL job.
- bool DoSyncSessionJobImpl(scoped_ptr<SyncSessionJob> job,
- JobPriority priority);
-
// Invoke the syncer to perform a nudge job.
void DoNudgeSyncSessionJob(JobPriority priority);
// Invoke the syncer to perform a configuration job.
bool DoConfigurationSyncSessionJob(JobPriority priority);
- // Returns whether or not it's safe to run a poll job at this time.
- bool ShouldPoll();
+ // Helper function for Do{Nudge,Configuration}SyncSessionJob.
+ void HandleFailure(
+ const sessions::ModelNeutralState& model_neutral_state);
// Invoke the Syncer to perform a poll job.
void DoPollSyncSessionJob();
- // Called after the Syncer has performed the sync represented by |job|, to
- // reset our state. |exited_prematurely| is true if the Syncer did not
- // cycle from job.start_step() to job.end_step(), likely because the
- // scheduler was forced to quit the job mid-way through.
- bool FinishSyncSessionJob(SyncSessionJob* job,
- bool exited_prematurely,
- sessions::SyncSession* session);
-
- // Helper to schedule retries of a failed configure or nudge job.
- void ScheduleNextSync(scoped_ptr<SyncSessionJob> finished_job,
- sessions::SyncSession* session);
-
- // Helper to configure polling intervals. Used by Start and ScheduleNextSync.
- void AdjustPolling(const SyncSessionJob* old_job);
+ // Adjusts the poll timer to account for new poll interval, and possibly
+ // resets the poll interval, depedning on the flag's value.
+ void AdjustPolling(PollAdjustType type);
// Helper to restart waiting with |wait_interval_|'s timer.
void RestartWaiting();
- // Helper to ScheduleNextSync in case of consecutive sync errors.
- void HandleContinuationError(scoped_ptr<SyncSessionJob> old_job,
- sessions::SyncSession* session);
+ // Helper to adjust our wait interval when we expereince a transient failure.
+ void UpdateExponentialBackoff(
+ const sessions::ModelNeutralState& model_neutral_state);
- // Decide whether we should CONTINUE, SAVE or DROP the job.
- JobProcessDecision DecideOnJob(const SyncSessionJob& job,
- JobPriority priority);
+ // Determines if we're allowed to contact the server right now.
+ bool CanRunJobNow(JobPriority priority);
- // Decide on whether to CONTINUE, SAVE or DROP the job when we are in
- // backoff mode.
- JobProcessDecision DecideWhileInWaitInterval(const SyncSessionJob& job,
- JobPriority priority);
+ // Determines if we're allowed to contact the server right now.
+ bool CanRunNudgeJobNow(JobPriority priority);
- // 'Impl' here refers to real implementation of public functions, running on
- // |thread_|.
+ // 'Impl' here refers to real implementation of public functions.
void StopImpl(const base::Closure& callback);
// If the scheduler's current state supports it, this will create a job based
@@ -230,9 +213,9 @@ class SYNC_EXPORT_PRIVATE SyncSchedulerImpl
// Creates a session for a poll and performs the sync.
void PollTimerCallback();
- // Called once the first time thread_ is started to broadcast an initial
- // session snapshot containing data like initial_sync_ended. Important when
- // the client starts up and does not need to perform an initial sync.
+ // Called as we are started to broadcast an initial session snapshot
+ // containing data like initial_sync_ended. Important when the client starts
+ // up and does not need to perform an initial sync.
void SendInitialSnapshot();
// This is used for histogramming and analysis of ScheduleNudge* APIs.
@@ -280,13 +263,15 @@ class SYNC_EXPORT_PRIVATE SyncSchedulerImpl
// The event that will wake us up.
base::OneShotTimer<SyncSchedulerImpl> pending_wakeup_timer_;
- // Pending configure job storage. Note that
- // (mode_ != CONFIGURATION_MODE) \implies !pending_configure_job_.
- scoped_ptr<SyncSessionJob> pending_configure_job_;
+ // Storage for variables related to an in-progress configure request. Note
+ // that (mode_ != CONFIGURATION_MODE) \implies !pending_configure_params_.
+ scoped_ptr<ConfigurationParams> pending_configure_params_;
+
+ // If we have a nudge pending to run soon, it will be listed here.
+ base::TimeTicks scheduled_nudge_time_;
- // Pending nudge job storage. These jobs can exist in CONFIGURATION_MODE, but
- // they will be run only in NORMAL_MODE.
- scoped_ptr<SyncSessionJob> pending_nudge_job_;
+ // Keeps track of work that the syncer needs to handle.
+ sessions::NudgeTracker nudge_tracker_;
// Invoked to run through the sync cycle.
scoped_ptr<Syncer> syncer_;