1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // A class to schedule syncer tasks intelligently.
6 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_H_
7 #define SYNC_ENGINE_SYNC_SCHEDULER_H_
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/time.h"
14 #include "sync/base/sync_export.h"
15 #include "sync/engine/nudge_source.h"
16 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
17 #include "sync/sessions/sync_session.h"
21 namespace tracked_objects
{
23 } // namespace tracked_objects
27 struct ServerConnectionEvent
;
29 struct SYNC_EXPORT_PRIVATE ConfigurationParams
{
30 ConfigurationParams();
32 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource
& source
,
33 ModelTypeSet types_to_download
,
34 const ModelSafeRoutingInfo
& routing_info
,
35 const base::Closure
& ready_task
);
36 ~ConfigurationParams();
38 // Source for the configuration.
39 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source
;
40 // The types that should be downloaded.
41 ModelTypeSet types_to_download
;
42 // The new routing info (superset of types to be downloaded).
43 ModelSafeRoutingInfo routing_info
;
44 // Callback to invoke on configuration completion.
45 base::Closure ready_task
;
48 class SYNC_EXPORT_PRIVATE SyncScheduler
49 : public sessions::SyncSession::Delegate
{
52 // In this mode, the thread only performs configuration tasks. This is
53 // designed to make the case where we want to download updates for a
54 // specific type only, and not continue syncing until we are moved into
57 // Resumes polling and allows nudges, drops configuration tasks. Runs
58 // through entire sync cycle.
62 // All methods of SyncScheduler must be called on the same thread
63 // (except for RequestEarlyExit()).
66 virtual ~SyncScheduler();
68 // Start the scheduler with the given mode. If the scheduler is
69 // already started, switch to the given mode, although some
70 // scheduled tasks from the old mode may still run.
71 virtual void Start(Mode mode
) = 0;
73 // Schedules the configuration task specified by |params|. Returns true if
74 // the configuration task executed immediately, false if it had to be
75 // scheduled for a later attempt. |params.ready_task| is invoked whenever the
76 // configuration task executes.
77 // Note: must already be in CONFIGURATION mode.
78 virtual bool ScheduleConfiguration(const ConfigurationParams
& params
) = 0;
80 // Request that any running syncer task stop as soon as possible and
81 // cancel all scheduled tasks. This function can be called from any thread,
82 // and should in fact be called from a thread that isn't the sync loop to
83 // allow preempting ongoing sync cycles.
84 // Invokes |callback| from the sync loop once syncer is idle and all tasks
86 virtual void RequestStop(const base::Closure
& callback
) = 0;
88 // The meat and potatoes. Both of these methods will post a delayed task
89 // to attempt the actual nudge (see ScheduleNudgeImpl).
90 // NOTE: |desired_delay| is best-effort. If a nudge is already scheduled to
91 // depart earlier than Now() + delay, the scheduler can and will prefer to
92 // batch the two so that only one nudge is sent (at the earlier time). Also,
93 // as always with delayed tasks and timers, it's possible the task gets run
94 // any time after |desired_delay|.
95 virtual void ScheduleNudgeAsync(
96 const base::TimeDelta
& desired_delay
,
99 const tracked_objects::Location
& nudge_location
) = 0;
100 virtual void ScheduleNudgeWithStatesAsync(
101 const base::TimeDelta
& desired_delay
, NudgeSource source
,
102 const ModelTypeInvalidationMap
& invalidation_map
,
103 const tracked_objects::Location
& nudge_location
) = 0;
105 // Change status of notifications in the SyncSessionContext.
106 virtual void SetNotificationsEnabled(bool notifications_enabled
) = 0;
108 virtual base::TimeDelta
GetSessionsCommitDelay() const = 0;
110 // Called when credentials are updated by the user.
111 virtual void OnCredentialsUpdated() = 0;
113 // Called when the network layer detects a connection status change.
114 virtual void OnConnectionStatusChange() = 0;
117 } // namespace syncer
119 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_