| OLD | NEW |
| (Empty) |
| 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_ | |
| 8 | |
| 9 #include <memory> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/compiler_specific.h" | |
| 14 #include "base/time/time.h" | |
| 15 #include "sync/base/sync_export.h" | |
| 16 #include "sync/engine/nudge_source.h" | |
| 17 #include "sync/internal_api/public/base/invalidation_interface.h" | |
| 18 #include "sync/sessions/sync_session.h" | |
| 19 | |
| 20 namespace tracked_objects { | |
| 21 class Location; | |
| 22 } // namespace tracked_objects | |
| 23 | |
| 24 namespace syncer { | |
| 25 | |
| 26 struct ServerConnectionEvent; | |
| 27 | |
| 28 struct SYNC_EXPORT ConfigurationParams { | |
| 29 ConfigurationParams(); | |
| 30 ConfigurationParams( | |
| 31 const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& source, | |
| 32 ModelTypeSet types_to_download, | |
| 33 const ModelSafeRoutingInfo& routing_info, | |
| 34 const base::Closure& ready_task, | |
| 35 const base::Closure& retry_task); | |
| 36 ConfigurationParams(const ConfigurationParams& other); | |
| 37 ~ConfigurationParams(); | |
| 38 | |
| 39 // Source for the configuration. | |
| 40 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source; | |
| 41 // The types that should be downloaded. | |
| 42 ModelTypeSet types_to_download; | |
| 43 // The new routing info (superset of types to be downloaded). | |
| 44 ModelSafeRoutingInfo routing_info; | |
| 45 // Callback to invoke on configuration completion. | |
| 46 base::Closure ready_task; | |
| 47 // Callback to invoke on configuration failure. | |
| 48 base::Closure retry_task; | |
| 49 }; | |
| 50 | |
| 51 struct SYNC_EXPORT ClearParams { | |
| 52 explicit ClearParams(const base::Closure& report_success_task); | |
| 53 ClearParams(const ClearParams& other); | |
| 54 ~ClearParams(); | |
| 55 | |
| 56 // Callback to invoke on successful completion. | |
| 57 base::Closure report_success_task; | |
| 58 }; | |
| 59 | |
| 60 class SYNC_EXPORT SyncScheduler : public sessions::SyncSession::Delegate { | |
| 61 public: | |
| 62 enum Mode { | |
| 63 // In this mode, the thread only performs configuration tasks. This is | |
| 64 // designed to make the case where we want to download updates for a | |
| 65 // specific type only, and not continue syncing until we are moved into | |
| 66 // normal mode. | |
| 67 CONFIGURATION_MODE, | |
| 68 // This mode is used to issue a clear server data command. The scheduler | |
| 69 // may only transition to this mode from the CONFIGURATION_MODE. When in | |
| 70 // this mode, the only schedulable operation is |SchedulerClearServerData|. | |
| 71 CLEAR_SERVER_DATA_MODE, | |
| 72 // Resumes polling and allows nudges, drops configuration tasks. Runs | |
| 73 // through entire sync cycle. | |
| 74 NORMAL_MODE, | |
| 75 }; | |
| 76 | |
| 77 // All methods of SyncScheduler must be called on the same thread | |
| 78 // (except for RequestEarlyExit()). | |
| 79 | |
| 80 SyncScheduler(); | |
| 81 ~SyncScheduler() override; | |
| 82 | |
| 83 // Start the scheduler with the given mode. If the scheduler is | |
| 84 // already started, switch to the given mode, although some | |
| 85 // scheduled tasks from the old mode may still run. |last_poll_time| will | |
| 86 // be used to decide what the poll timer should be initialized with. | |
| 87 virtual void Start(Mode mode, base::Time last_poll_time) = 0; | |
| 88 | |
| 89 // Schedules the configuration task specified by |params|. Returns true if | |
| 90 // the configuration task executed immediately, false if it had to be | |
| 91 // scheduled for a later attempt. |params.ready_task| is invoked whenever the | |
| 92 // configuration task executes. |params.retry_task| is invoked once if the | |
| 93 // configuration task could not execute. |params.ready_task| will still be | |
| 94 // called when configuration finishes. | |
| 95 // Note: must already be in CONFIGURATION mode. | |
| 96 virtual void ScheduleConfiguration(const ConfigurationParams& params) = 0; | |
| 97 | |
| 98 // Schedules clear of server data in preparation for transitioning to | |
| 99 // passphrase encryption. The scheduler must be in CLEAR_SERVER_DATA_MODE | |
| 100 // before calling this method. | |
| 101 virtual void ScheduleClearServerData(const ClearParams& params) = 0; | |
| 102 | |
| 103 // Request that the syncer avoid starting any new tasks and prepare for | |
| 104 // shutdown. | |
| 105 virtual void Stop() = 0; | |
| 106 | |
| 107 // The meat and potatoes. All three of the following methods will post a | |
| 108 // delayed task to attempt the actual nudge (see ScheduleNudgeImpl). | |
| 109 // | |
| 110 // NOTE: |desired_delay| is best-effort. If a nudge is already scheduled to | |
| 111 // depart earlier than Now() + delay, the scheduler can and will prefer to | |
| 112 // batch the two so that only one nudge is sent (at the earlier time). Also, | |
| 113 // as always with delayed tasks and timers, it's possible the task gets run | |
| 114 // any time after |desired_delay|. | |
| 115 | |
| 116 // The LocalNudge indicates that we've made a local change, and that the | |
| 117 // syncer should plan to commit this to the server some time soon. | |
| 118 virtual void ScheduleLocalNudge( | |
| 119 ModelTypeSet types, | |
| 120 const tracked_objects::Location& nudge_location) = 0; | |
| 121 | |
| 122 // The LocalRefreshRequest occurs when we decide for some reason to manually | |
| 123 // request updates. This should be used sparingly. For example, one of its | |
| 124 // uses is to fetch the latest tab sync data when it's relevant to the UI on | |
| 125 // platforms where tab sync is not registered for invalidations. | |
| 126 virtual void ScheduleLocalRefreshRequest( | |
| 127 ModelTypeSet types, | |
| 128 const tracked_objects::Location& nudge_location) = 0; | |
| 129 | |
| 130 // Invalidations are notifications the server sends to let us know when other | |
| 131 // clients have committed data. We need to contact the sync server (being | |
| 132 // careful to pass along the "hints" delivered with those invalidations) in | |
| 133 // order to fetch the update. | |
| 134 virtual void ScheduleInvalidationNudge( | |
| 135 syncer::ModelType type, | |
| 136 std::unique_ptr<InvalidationInterface> invalidation, | |
| 137 const tracked_objects::Location& nudge_location) = 0; | |
| 138 | |
| 139 // Requests a non-blocking initial sync request for the specified type. | |
| 140 // | |
| 141 // Many types can only complete initial sync while the scheduler is in | |
| 142 // configure mode, but a few of them are able to perform their initial sync | |
| 143 // while the scheduler is in normal mode. This non-blocking initial sync | |
| 144 // can be requested through this function. | |
| 145 virtual void ScheduleInitialSyncNudge(syncer::ModelType model_type) = 0; | |
| 146 | |
| 147 // Change status of notifications in the SyncSessionContext. | |
| 148 virtual void SetNotificationsEnabled(bool notifications_enabled) = 0; | |
| 149 | |
| 150 // Called when credentials are updated by the user. | |
| 151 virtual void OnCredentialsUpdated() = 0; | |
| 152 | |
| 153 // Called when the network layer detects a connection status change. | |
| 154 virtual void OnConnectionStatusChange() = 0; | |
| 155 }; | |
| 156 | |
| 157 } // namespace syncer | |
| 158 | |
| 159 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ | |
| OLD | NEW |