Make sure webview uses embedder display DPI.
[chromium-blink-merge.git] / sync / engine / sync_scheduler.h
blobb2ebbe3f0484862b9f0c50a6d82e54b61f7dee36
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.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"
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 any running syncer task stop as soon as possible and
79 // cancel all scheduled tasks. This function can be called from any thread,
80 // and should in fact be called from a thread that isn't the sync loop to
81 // allow preempting ongoing sync cycles.
82 // Invokes |callback| from the sync loop once syncer is idle and all tasks
83 // are cancelled.
84 virtual void RequestStop(const base::Closure& callback) = 0;
86 // The meat and potatoes. Both of these methods will post a delayed task
87 // to attempt the actual nudge (see ScheduleNudgeImpl).
88 // NOTE: |desired_delay| is best-effort. If a nudge is already scheduled to
89 // depart earlier than Now() + delay, the scheduler can and will prefer to
90 // batch the two so that only one nudge is sent (at the earlier time). Also,
91 // as always with delayed tasks and timers, it's possible the task gets run
92 // any time after |desired_delay|.
93 virtual void ScheduleNudgeAsync(
94 const base::TimeDelta& desired_delay,
95 NudgeSource source,
96 ModelTypeSet types,
97 const tracked_objects::Location& nudge_location) = 0;
98 virtual void ScheduleNudgeWithStatesAsync(
99 const base::TimeDelta& desired_delay, NudgeSource source,
100 const ModelTypeInvalidationMap& invalidation_map,
101 const tracked_objects::Location& nudge_location) = 0;
103 // Change status of notifications in the SyncSessionContext.
104 virtual void SetNotificationsEnabled(bool notifications_enabled) = 0;
106 virtual base::TimeDelta GetSessionsCommitDelay() const = 0;
108 // Called when credentials are updated by the user.
109 virtual void OnCredentialsUpdated() = 0;
111 // Called when the network layer detects a connection status change.
112 virtual void OnConnectionStatusChange() = 0;
115 } // namespace syncer
117 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_