OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // A class to schedule syncer tasks intelligently. | 5 // A class to schedule syncer tasks intelligently. |
6 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_H_ | 6 #ifndef SYNC_ENGINE_SYNC_SCHEDULER_H_ |
7 #define SYNC_ENGINE_SYNC_SCHEDULER_H_ | 7 #define SYNC_ENGINE_SYNC_SCHEDULER_H_ |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 // The types that should be downloaded. | 39 // The types that should be downloaded. |
40 ModelTypeSet types_to_download; | 40 ModelTypeSet types_to_download; |
41 // The new routing info (superset of types to be downloaded). | 41 // The new routing info (superset of types to be downloaded). |
42 ModelSafeRoutingInfo routing_info; | 42 ModelSafeRoutingInfo routing_info; |
43 // Callback to invoke on configuration completion. | 43 // Callback to invoke on configuration completion. |
44 base::Closure ready_task; | 44 base::Closure ready_task; |
45 // Callback to invoke on configuration failure. | 45 // Callback to invoke on configuration failure. |
46 base::Closure retry_task; | 46 base::Closure retry_task; |
47 }; | 47 }; |
48 | 48 |
| 49 struct SYNC_EXPORT_PRIVATE ClearParams { |
| 50 ClearParams(const base::Closure& report_success_task); |
| 51 ~ClearParams(); |
| 52 |
| 53 // Callback to invoke on successful completion. |
| 54 base::Closure report_success_task; |
| 55 }; |
| 56 |
49 class SYNC_EXPORT_PRIVATE SyncScheduler | 57 class SYNC_EXPORT_PRIVATE SyncScheduler |
50 : public sessions::SyncSession::Delegate { | 58 : public sessions::SyncSession::Delegate { |
51 public: | 59 public: |
52 enum Mode { | 60 enum Mode { |
53 // In this mode, the thread only performs configuration tasks. This is | 61 // In this mode, the thread only performs configuration tasks. This is |
54 // designed to make the case where we want to download updates for a | 62 // designed to make the case where we want to download updates for a |
55 // specific type only, and not continue syncing until we are moved into | 63 // specific type only, and not continue syncing until we are moved into |
56 // normal mode. | 64 // normal mode. |
57 CONFIGURATION_MODE, | 65 CONFIGURATION_MODE, |
| 66 // This mode is used to issue a clear server data command. The scheduler |
| 67 // may only transition to this mode from the CONFIGURATION_MODE. When in |
| 68 // this mode, the only schedulable operation is |SchedulerClearServerData|. |
| 69 CLEAR_SERVER_DATA_MODE, |
58 // Resumes polling and allows nudges, drops configuration tasks. Runs | 70 // Resumes polling and allows nudges, drops configuration tasks. Runs |
59 // through entire sync cycle. | 71 // through entire sync cycle. |
60 NORMAL_MODE, | 72 NORMAL_MODE, |
61 }; | 73 }; |
62 | 74 |
63 // All methods of SyncScheduler must be called on the same thread | 75 // All methods of SyncScheduler must be called on the same thread |
64 // (except for RequestEarlyExit()). | 76 // (except for RequestEarlyExit()). |
65 | 77 |
66 SyncScheduler(); | 78 SyncScheduler(); |
67 ~SyncScheduler() override; | 79 ~SyncScheduler() override; |
68 | 80 |
69 // Start the scheduler with the given mode. If the scheduler is | 81 // Start the scheduler with the given mode. If the scheduler is |
70 // already started, switch to the given mode, although some | 82 // already started, switch to the given mode, although some |
71 // scheduled tasks from the old mode may still run. |last_poll_time| will | 83 // scheduled tasks from the old mode may still run. |last_poll_time| will |
72 // be used to decide what the poll timer should be initialized with. | 84 // be used to decide what the poll timer should be initialized with. |
73 virtual void Start(Mode mode, base::Time last_poll_time) = 0; | 85 virtual void Start(Mode mode, base::Time last_poll_time) = 0; |
74 | 86 |
75 // Schedules the configuration task specified by |params|. Returns true if | 87 // Schedules the configuration task specified by |params|. Returns true if |
76 // the configuration task executed immediately, false if it had to be | 88 // the configuration task executed immediately, false if it had to be |
77 // scheduled for a later attempt. |params.ready_task| is invoked whenever the | 89 // scheduled for a later attempt. |params.ready_task| is invoked whenever the |
78 // configuration task executes. |params.retry_task| is invoked once if the | 90 // configuration task executes. |params.retry_task| is invoked once if the |
79 // configuration task could not execute. |params.ready_task| will still be | 91 // configuration task could not execute. |params.ready_task| will still be |
80 // called when configuration finishes. | 92 // called when configuration finishes. |
81 // Note: must already be in CONFIGURATION mode. | 93 // Note: must already be in CONFIGURATION mode. |
82 virtual void ScheduleConfiguration(const ConfigurationParams& params) = 0; | 94 virtual void ScheduleConfiguration(const ConfigurationParams& params) = 0; |
83 | 95 |
| 96 // Schedules clear of server data in preparation for transitioning to |
| 97 // passphrase encryption. The scheduler must be in CLEAR_SERVER_DATA_MODE |
| 98 // before calling this method. |
| 99 virtual void ScheduleClearServerData(const ClearParams& params) = 0; |
| 100 |
84 // Request that the syncer avoid starting any new tasks and prepare for | 101 // Request that the syncer avoid starting any new tasks and prepare for |
85 // shutdown. | 102 // shutdown. |
86 virtual void Stop() = 0; | 103 virtual void Stop() = 0; |
87 | 104 |
88 // The meat and potatoes. All three of the following methods will post a | 105 // The meat and potatoes. All three of the following methods will post a |
89 // delayed task to attempt the actual nudge (see ScheduleNudgeImpl). | 106 // delayed task to attempt the actual nudge (see ScheduleNudgeImpl). |
90 // | 107 // |
91 // NOTE: |desired_delay| is best-effort. If a nudge is already scheduled to | 108 // NOTE: |desired_delay| is best-effort. If a nudge is already scheduled to |
92 // depart earlier than Now() + delay, the scheduler can and will prefer to | 109 // depart earlier than Now() + delay, the scheduler can and will prefer to |
93 // batch the two so that only one nudge is sent (at the earlier time). Also, | 110 // batch the two so that only one nudge is sent (at the earlier time). Also, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // Called when credentials are updated by the user. | 148 // Called when credentials are updated by the user. |
132 virtual void OnCredentialsUpdated() = 0; | 149 virtual void OnCredentialsUpdated() = 0; |
133 | 150 |
134 // Called when the network layer detects a connection status change. | 151 // Called when the network layer detects a connection status change. |
135 virtual void OnConnectionStatusChange() = 0; | 152 virtual void OnConnectionStatusChange() = 0; |
136 }; | 153 }; |
137 | 154 |
138 } // namespace syncer | 155 } // namespace syncer |
139 | 156 |
140 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ | 157 #endif // SYNC_ENGINE_SYNC_SCHEDULER_H_ |
OLD | NEW |