Follow-up for: Disable inline autocompletion for IME in Omnibox by default.
[chromium-blink-merge.git] / sync / engine / sync_scheduler.h
blobb31af82791353e6154cc295c95be217fc26c309a
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.
4 //
5 // A class to schedule syncer tasks intelligently.
6 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_H_
7 #define SYNC_ENGINE_SYNC_SCHEDULER_H_
9 #include <string>
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/time/time.h"
14 #include "sync/base/sync_export.h"
15 #include "sync/engine/nudge_source.h"
16 #include "sync/notifier/object_id_invalidation_map.h"
17 #include "sync/sessions/sync_session.h"
19 namespace tracked_objects {
20 class Location;
21 } // namespace tracked_objects
23 namespace syncer {
25 struct ServerConnectionEvent;
27 struct SYNC_EXPORT_PRIVATE ConfigurationParams {
28 ConfigurationParams();
29 ConfigurationParams(
30 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source,
31 ModelTypeSet types_to_download,
32 const ModelSafeRoutingInfo& routing_info,
33 const base::Closure& ready_task);
34 ~ConfigurationParams();
36 // Source for the configuration.
37 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source;
38 // The types that should be downloaded.
39 ModelTypeSet types_to_download;
40 // The new routing info (superset of types to be downloaded).
41 ModelSafeRoutingInfo routing_info;
42 // Callback to invoke on configuration completion.
43 base::Closure ready_task;
46 class SYNC_EXPORT_PRIVATE SyncScheduler
47 : public sessions::SyncSession::Delegate {
48 public:
49 enum Mode {
50 // In this mode, the thread only performs configuration tasks. This is
51 // designed to make the case where we want to download updates for a
52 // specific type only, and not continue syncing until we are moved into
53 // normal mode.
54 CONFIGURATION_MODE,
55 // Resumes polling and allows nudges, drops configuration tasks. Runs
56 // through entire sync cycle.
57 NORMAL_MODE,
60 // All methods of SyncScheduler must be called on the same thread
61 // (except for RequestEarlyExit()).
63 SyncScheduler();
64 virtual ~SyncScheduler();
66 // Start the scheduler with the given mode. If the scheduler is
67 // already started, switch to the given mode, although some
68 // scheduled tasks from the old mode may still run.
69 virtual void Start(Mode mode) = 0;
71 // Schedules the configuration task specified by |params|. Returns true if
72 // the configuration task executed immediately, false if it had to be
73 // scheduled for a later attempt. |params.ready_task| is invoked whenever the
74 // configuration task executes.
75 // Note: must already be in CONFIGURATION mode.
76 virtual bool ScheduleConfiguration(const ConfigurationParams& params) = 0;
78 // Request that the syncer avoid starting any new tasks and prepare for
79 // shutdown.
80 virtual void Stop() = 0;
82 // The meat and potatoes. All three of the following methods will post a
83 // delayed task to attempt the actual nudge (see ScheduleNudgeImpl).
85 // NOTE: |desired_delay| is best-effort. If a nudge is already scheduled to
86 // depart earlier than Now() + delay, the scheduler can and will prefer to
87 // batch the two so that only one nudge is sent (at the earlier time). Also,
88 // as always with delayed tasks and timers, it's possible the task gets run
89 // any time after |desired_delay|.
91 // The LocalNudge indicates that we've made a local change, and that the
92 // syncer should plan to commit this to the server some time soon.
93 virtual void ScheduleLocalNudge(
94 const base::TimeDelta& desired_delay,
95 ModelTypeSet types,
96 const tracked_objects::Location& nudge_location) = 0;
98 // The LocalRefreshRequest occurs when we decide for some reason to manually
99 // request updates. This should be used sparingly. For example, one of its
100 // uses is to fetch the latest tab sync data when it's relevant to the UI on
101 // platforms where tab sync is not registered for invalidations.
102 virtual void ScheduleLocalRefreshRequest(
103 const base::TimeDelta& desired_delay,
104 ModelTypeSet types,
105 const tracked_objects::Location& nudge_location) = 0;
107 // Invalidations are notifications the server sends to let us know when other
108 // clients have committed data. We need to contact the sync server (being
109 // careful to pass along the "hints" delivered with those invalidations) in
110 // order to fetch the update.
111 virtual void ScheduleInvalidationNudge(
112 const base::TimeDelta& desired_delay,
113 const ObjectIdInvalidationMap& invalidations,
114 const tracked_objects::Location& nudge_location) = 0;
116 // Change status of notifications in the SyncSessionContext.
117 virtual void SetNotificationsEnabled(bool notifications_enabled) = 0;
119 virtual base::TimeDelta GetSessionsCommitDelay() const = 0;
121 // Called when credentials are updated by the user.
122 virtual void OnCredentialsUpdated() = 0;
124 // Called when the network layer detects a connection status change.
125 virtual void OnConnectionStatusChange() = 0;
128 } // namespace syncer
130 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_