OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_IMPL_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
17 #include "chrome/browser/invalidation/invalidation_service.h" | |
18 #include "chrome/browser/sync/glue/backend_data_type_configurer.h" | 16 #include "chrome/browser/sync/glue/backend_data_type_configurer.h" |
19 #include "chrome/browser/sync/glue/extensions_activity_monitor.h" | 17 #include "chrome/browser/sync/glue/extensions_activity_monitor.h" |
| 18 #include "chrome/browser/sync/glue/sync_backend_host.h" |
20 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
22 #include "google_apis/gaia/google_service_auth_error.h" | |
23 #include "sync/internal_api/public/base/model_type.h" | 21 #include "sync/internal_api/public/base/model_type.h" |
24 #include "sync/internal_api/public/configure_reason.h" | 22 #include "sync/internal_api/public/configure_reason.h" |
25 #include "sync/internal_api/public/engine/model_safe_worker.h" | |
26 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 23 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
27 #include "sync/internal_api/public/sync_encryption_handler.h" | |
28 #include "sync/internal_api/public/sync_manager.h" | 24 #include "sync/internal_api/public/sync_manager.h" |
29 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" | 25 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" |
30 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" | 26 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" |
31 #include "sync/internal_api/public/util/weak_handle.h" | 27 #include "sync/internal_api/public/util/weak_handle.h" |
32 #include "sync/notifier/invalidation_handler.h" | 28 #include "sync/notifier/invalidation_handler.h" |
33 #include "sync/protocol/encryption.pb.h" | 29 #include "sync/protocol/encryption.pb.h" |
34 #include "sync/protocol/sync_protocol_error.h" | 30 #include "sync/protocol/sync_protocol_error.h" |
35 #include "sync/util/extensions_activity.h" | 31 #include "sync/util/extensions_activity.h" |
36 #include "url/gurl.h" | |
37 | 32 |
| 33 class GURL; |
38 class Profile; | 34 class Profile; |
39 | 35 |
40 namespace base { | 36 namespace base { |
41 class MessageLoop; | 37 class MessageLoop; |
42 } | 38 } |
43 | 39 |
| 40 namespace invalidation { |
| 41 class InvalidationService; |
| 42 } |
| 43 |
44 namespace syncer { | 44 namespace syncer { |
45 class SyncManagerFactory; | 45 class SyncManagerFactory; |
46 } | 46 } |
47 | 47 |
48 namespace browser_sync { | 48 namespace browser_sync { |
49 | 49 |
50 class ChangeProcessor; | 50 class ChangeProcessor; |
51 class InvalidatorStorage; | 51 class SyncBackendHostCore; |
52 class SyncBackendRegistrar; | 52 class SyncBackendRegistrar; |
53 class SyncPrefs; | 53 class SyncPrefs; |
54 class SyncedDeviceTracker; | 54 class SyncedDeviceTracker; |
55 struct Experiments; | 55 struct DoInitializeOptions; |
56 | |
57 // SyncFrontend is the interface used by SyncBackendHost to communicate with | |
58 // the entity that created it and, presumably, is interested in sync-related | |
59 // activity. | |
60 // NOTE: All methods will be invoked by a SyncBackendHost on the same thread | |
61 // used to create that SyncBackendHost. | |
62 class SyncFrontend { | |
63 public: | |
64 SyncFrontend() {} | |
65 | |
66 // The backend has completed initialization and it is now ready to | |
67 // accept and process changes. If success is false, initialization | |
68 // wasn't able to be completed and should be retried. | |
69 // | |
70 // |js_backend| is what about:sync interacts with; it's different | |
71 // from the 'Backend' in 'OnBackendInitialized' (unfortunately). It | |
72 // is initialized only if |success| is true. | |
73 virtual void OnBackendInitialized( | |
74 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | |
75 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | |
76 debug_info_listener, | |
77 bool success) = 0; | |
78 | |
79 // The backend queried the server recently and received some updates. | |
80 virtual void OnSyncCycleCompleted() = 0; | |
81 | |
82 // Configure ran into some kind of error. But it is scheduled to be | |
83 // retried. | |
84 virtual void OnSyncConfigureRetry() = 0; | |
85 | |
86 // The status of the connection to the sync server has changed. | |
87 virtual void OnConnectionStatusChange( | |
88 syncer::ConnectionStatus status) = 0; | |
89 | |
90 // We are no longer permitted to communicate with the server. Sync should | |
91 // be disabled and state cleaned up at once. | |
92 virtual void OnStopSyncingPermanently() = 0; | |
93 | |
94 // The syncer requires a passphrase to decrypt sensitive updates. This is | |
95 // called when the first sensitive data type is setup by the user and anytime | |
96 // the passphrase is changed by another synced client. |reason| denotes why | |
97 // the passphrase was required. |pending_keys| is a copy of the | |
98 // cryptographer's pending keys to be passed on to the frontend in order to | |
99 // be cached. | |
100 virtual void OnPassphraseRequired( | |
101 syncer::PassphraseRequiredReason reason, | |
102 const sync_pb::EncryptedData& pending_keys) = 0; | |
103 | |
104 // Called when the passphrase provided by the user is | |
105 // accepted. After this is called, updates to sensitive nodes are | |
106 // encrypted using the accepted passphrase. | |
107 virtual void OnPassphraseAccepted() = 0; | |
108 | |
109 // Called when the set of encrypted types or the encrypt everything | |
110 // flag has been changed. Note that encryption isn't complete until | |
111 // the OnEncryptionComplete() notification has been sent (see | |
112 // below). | |
113 // | |
114 // |encrypted_types| will always be a superset of | |
115 // syncer::Cryptographer::SensitiveTypes(). If |encrypt_everything| is | |
116 // true, |encrypted_types| will be the set of all known types. | |
117 // | |
118 // Until this function is called, observers can assume that the set | |
119 // of encrypted types is syncer::Cryptographer::SensitiveTypes() and that | |
120 // the encrypt everything flag is false. | |
121 virtual void OnEncryptedTypesChanged( | |
122 syncer::ModelTypeSet encrypted_types, | |
123 bool encrypt_everything) = 0; | |
124 | |
125 // Called after we finish encrypting the current set of encrypted | |
126 // types. | |
127 virtual void OnEncryptionComplete() = 0; | |
128 | |
129 // Called to perform migration of |types|. | |
130 virtual void OnMigrationNeededForTypes(syncer::ModelTypeSet types) = 0; | |
131 | |
132 // Inform the Frontend that new datatypes are available for registration. | |
133 virtual void OnExperimentsChanged( | |
134 const syncer::Experiments& experiments) = 0; | |
135 | |
136 // Called when the sync cycle returns there is an user actionable error. | |
137 virtual void OnActionableError(const syncer::SyncProtocolError& error) = 0; | |
138 | |
139 protected: | |
140 // Don't delete through SyncFrontend interface. | |
141 virtual ~SyncFrontend() { | |
142 } | |
143 private: | |
144 DISALLOW_COPY_AND_ASSIGN(SyncFrontend); | |
145 }; | |
146 | 56 |
147 // A UI-thread safe API into the sync backend that "hosts" the top-level | 57 // A UI-thread safe API into the sync backend that "hosts" the top-level |
148 // syncapi element, the SyncManager, on its own thread. This class handles | 58 // syncapi element, the SyncManager, on its own thread. This class handles |
149 // dispatch of potentially blocking calls to appropriate threads and ensures | 59 // dispatch of potentially blocking calls to appropriate threads and ensures |
150 // that the SyncFrontend is only accessed on the UI loop. | 60 // that the SyncFrontend is only accessed on the UI loop. |
151 class SyncBackendHost | 61 class SyncBackendHostImpl |
152 : public BackendDataTypeConfigurer, | 62 : public SyncBackendHost, |
153 public content::NotificationObserver, | 63 public content::NotificationObserver, |
154 public syncer::InvalidationHandler { | 64 public syncer::InvalidationHandler { |
155 public: | 65 public: |
156 typedef syncer::SyncStatus Status; | 66 typedef syncer::SyncStatus Status; |
157 | 67 |
158 // Create a SyncBackendHost with a reference to the |frontend| that | 68 // Create a SyncBackendHost with a reference to the |frontend| that |
159 // it serves and communicates to via the SyncFrontend interface (on | 69 // it serves and communicates to via the SyncFrontend interface (on |
160 // the same thread it used to call the constructor). Must outlive | 70 // the same thread it used to call the constructor). Must outlive |
161 // |sync_prefs| and |invalidator_storage|. | 71 // |sync_prefs|. |
162 SyncBackendHost( | 72 SyncBackendHostImpl( |
163 const std::string& name, | 73 const std::string& name, |
164 Profile* profile, | 74 Profile* profile, |
165 const base::WeakPtr<SyncPrefs>& sync_prefs); | 75 const base::WeakPtr<SyncPrefs>& sync_prefs); |
166 | 76 virtual ~SyncBackendHostImpl(); |
167 // For testing. | |
168 // TODO(skrul): Extract an interface so this is not needed. | |
169 explicit SyncBackendHost(Profile* profile); | |
170 virtual ~SyncBackendHost(); | |
171 | 77 |
172 // Called on |frontend_loop_| to kick off asynchronous initialization. | 78 // Called on |frontend_loop_| to kick off asynchronous initialization. |
173 // As a fallback when no cached auth information is available, try to | |
174 // bootstrap authentication using |lsid|, if it isn't empty. | |
175 // Optionally delete the Sync Data folder (if it's corrupt). | 79 // Optionally delete the Sync Data folder (if it's corrupt). |
176 // |report_unrecoverable_error_function| can be NULL. | 80 // |report_unrecoverable_error_function| can be NULL. |
177 // Note: |unrecoverable_error_handler| may be invoked from any thread. | 81 // Note: |unrecoverable_error_handler| may be invoked from any thread. |
178 void Initialize( | 82 virtual void Initialize( |
179 SyncFrontend* frontend, | 83 SyncFrontend* frontend, |
180 scoped_ptr<base::Thread> sync_thread, | 84 scoped_ptr<base::Thread> sync_thread, |
181 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 85 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
182 const GURL& service_url, | 86 const GURL& service_url, |
183 const syncer::SyncCredentials& credentials, | 87 const syncer::SyncCredentials& credentials, |
184 bool delete_sync_data_folder, | 88 bool delete_sync_data_folder, |
185 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 89 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
186 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, | 90 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, |
187 syncer::ReportUnrecoverableErrorFunction | 91 syncer::ReportUnrecoverableErrorFunction |
188 report_unrecoverable_error_function); | 92 report_unrecoverable_error_function) OVERRIDE; |
189 | 93 |
190 // Called on |frontend_loop| to update SyncCredentials. | 94 // Called on |frontend_loop| to update SyncCredentials. |
191 virtual void UpdateCredentials(const syncer::SyncCredentials& credentials); | 95 virtual void UpdateCredentials( |
| 96 const syncer::SyncCredentials& credentials) OVERRIDE; |
192 | 97 |
193 // This starts the SyncerThread running a Syncer object to communicate with | 98 // This starts the SyncerThread running a Syncer object to communicate with |
194 // sync servers. Until this is called, no changes will leave or enter this | 99 // sync servers. Until this is called, no changes will leave or enter this |
195 // browser from the cloud / sync servers. | 100 // browser from the cloud / sync servers. |
196 // Called on |frontend_loop_|. | 101 // Called on |frontend_loop_|. |
197 virtual void StartSyncingWithServer(); | 102 virtual void StartSyncingWithServer() OVERRIDE; |
198 | 103 |
199 // Called on |frontend_loop_| to asynchronously set a new passphrase for | 104 // Called on |frontend_loop_| to asynchronously set a new passphrase for |
200 // encryption. Note that it is an error to call SetEncryptionPassphrase under | 105 // encryption. Note that it is an error to call SetEncryptionPassphrase under |
201 // the following circumstances: | 106 // the following circumstances: |
202 // - An explicit passphrase has already been set | 107 // - An explicit passphrase has already been set |
203 // - |is_explicit| is true and we have pending keys. | 108 // - |is_explicit| is true and we have pending keys. |
204 // When |is_explicit| is false, a couple of things could happen: | 109 // When |is_explicit| is false, a couple of things could happen: |
205 // - If there are pending keys, we try to decrypt them. If decryption works, | 110 // - If there are pending keys, we try to decrypt them. If decryption works, |
206 // this acts like a call to SetDecryptionPassphrase. If not, the GAIA | 111 // this acts like a call to SetDecryptionPassphrase. If not, the GAIA |
207 // passphrase passed in is cached so we can re-encrypt with it in future. | 112 // passphrase passed in is cached so we can re-encrypt with it in future. |
208 // - If there are no pending keys, data is encrypted with |passphrase| (this | 113 // - If there are no pending keys, data is encrypted with |passphrase| (this |
209 // is a no-op if data was already encrypted with |passphrase|.) | 114 // is a no-op if data was already encrypted with |passphrase|.) |
210 void SetEncryptionPassphrase(const std::string& passphrase, bool is_explicit); | 115 virtual void SetEncryptionPassphrase( |
| 116 const std::string& passphrase, |
| 117 bool is_explicit) OVERRIDE; |
211 | 118 |
212 // Called on |frontend_loop_| to use the provided passphrase to asynchronously | 119 // Called on |frontend_loop_| to use the provided passphrase to asynchronously |
213 // attempt decryption. Returns false immediately if the passphrase could not | 120 // attempt decryption. Returns false immediately if the passphrase could not |
214 // be used to decrypt a locally cached copy of encrypted keys; returns true | 121 // be used to decrypt a locally cached copy of encrypted keys; returns true |
215 // otherwise. If new encrypted keys arrive during the asynchronous call, | 122 // otherwise. If new encrypted keys arrive during the asynchronous call, |
216 // OnPassphraseRequired may be triggered at a later time. It is an error to | 123 // OnPassphraseRequired may be triggered at a later time. It is an error to |
217 // call this when there are no pending keys. | 124 // call this when there are no pending keys. |
218 bool SetDecryptionPassphrase(const std::string& passphrase) | 125 virtual bool SetDecryptionPassphrase(const std::string& passphrase) |
219 WARN_UNUSED_RESULT; | 126 WARN_UNUSED_RESULT OVERRIDE; |
220 | 127 |
221 // Called on |frontend_loop_| to kick off shutdown procedure. Attempts to cut | 128 // Called on |frontend_loop_| to kick off shutdown procedure. Attempts to cut |
222 // short any long-lived or blocking sync thread tasks so that the shutdown on | 129 // short any long-lived or blocking sync thread tasks so that the shutdown on |
223 // sync thread task that we're about to post won't have to wait very long. | 130 // sync thread task that we're about to post won't have to wait very long. |
224 virtual void StopSyncingForShutdown(); | 131 virtual void StopSyncingForShutdown() OVERRIDE; |
225 | 132 |
226 // Called on |frontend_loop_| to kick off shutdown. | 133 // Called on |frontend_loop_| to kick off shutdown. |
227 // See the implementation and Core::DoShutdown for details. | 134 // See the implementation and Core::DoShutdown for details. |
228 // Must be called *after* StopSyncingForShutdown. Caller should claim sync | 135 // Must be called *after* StopSyncingForShutdown. Caller should claim sync |
229 // thread using STOP_AND_CLAIM_THREAD or DISABLE_AND_CLAIM_THREAD if sync | 136 // thread using STOP_AND_CLAIM_THREAD or DISABLE_AND_CLAIM_THREAD if sync |
230 // backend might be recreated later because otherwise: | 137 // backend might be recreated later because otherwise: |
231 // * sync loop may be stopped on main loop and cause it to be blocked. | 138 // * sync loop may be stopped on main loop and cause it to be blocked. |
232 // * new/old backend may interfere with each other if new backend is created | 139 // * new/old backend may interfere with each other if new backend is created |
233 // before old one finishes cleanup. | 140 // before old one finishes cleanup. |
234 enum ShutdownOption { | 141 virtual scoped_ptr<base::Thread> Shutdown(ShutdownOption option) OVERRIDE; |
235 STOP, // Stop syncing and let backend stop sync thread. | |
236 STOP_AND_CLAIM_THREAD, // Stop syncing and return sync thread. | |
237 DISABLE_AND_CLAIM_THREAD, // Disable sync and return sync thread. | |
238 }; | |
239 scoped_ptr<base::Thread> Shutdown(ShutdownOption option); | |
240 | 142 |
241 // Removes all current registrations from the backend on the | 143 // Removes all current registrations from the backend on the |
242 // InvalidationService. | 144 // InvalidationService. |
243 void UnregisterInvalidationIds(); | 145 virtual void UnregisterInvalidationIds() OVERRIDE; |
244 | 146 |
245 // Changes the set of data types that are currently being synced. | 147 // Changes the set of data types that are currently being synced. |
246 // The ready_task will be run when configuration is done with the | 148 // The ready_task will be run when configuration is done with the |
247 // set of all types that failed configuration (i.e., if its argument | 149 // set of all types that failed configuration (i.e., if its argument |
248 // is non-empty, then an error was encountered). | 150 // is non-empty, then an error was encountered). |
249 virtual void ConfigureDataTypes( | 151 virtual void ConfigureDataTypes( |
250 syncer::ConfigureReason reason, | 152 syncer::ConfigureReason reason, |
251 const DataTypeConfigStateMap& config_state_map, | 153 const DataTypeConfigStateMap& config_state_map, |
252 const base::Callback<void(syncer::ModelTypeSet, | 154 const base::Callback<void(syncer::ModelTypeSet, |
253 syncer::ModelTypeSet)>& ready_task, | 155 syncer::ModelTypeSet)>& ready_task, |
254 const base::Callback<void()>& retry_callback) OVERRIDE; | 156 const base::Callback<void()>& retry_callback) OVERRIDE; |
255 | 157 |
256 // Turns on encryption of all present and future sync data. | 158 // Turns on encryption of all present and future sync data. |
257 virtual void EnableEncryptEverything(); | 159 virtual void EnableEncryptEverything() OVERRIDE; |
258 | 160 |
259 // Activates change processing for the given data type. This must | 161 // Activates change processing for the given data type. This must |
260 // be called synchronously with the data type's model association so | 162 // be called synchronously with the data type's model association so |
261 // no changes are dropped between model association and change | 163 // no changes are dropped between model association and change |
262 // processor activation. | 164 // processor activation. |
263 void ActivateDataType( | 165 virtual void ActivateDataType( |
264 syncer::ModelType type, syncer::ModelSafeGroup group, | 166 syncer::ModelType type, syncer::ModelSafeGroup group, |
265 ChangeProcessor* change_processor); | 167 ChangeProcessor* change_processor) OVERRIDE; |
266 | 168 |
267 // Deactivates change processing for the given data type. | 169 // Deactivates change processing for the given data type. |
268 void DeactivateDataType(syncer::ModelType type); | 170 virtual void DeactivateDataType(syncer::ModelType type) OVERRIDE; |
269 | 171 |
270 // Called on |frontend_loop_| to obtain a handle to the UserShare needed for | 172 // Called on |frontend_loop_| to obtain a handle to the UserShare needed for |
271 // creating transactions. Should not be called before we signal | 173 // creating transactions. Should not be called before we signal |
272 // initialization is complete with OnBackendInitialized(). | 174 // initialization is complete with OnBackendInitialized(). |
273 syncer::UserShare* GetUserShare() const; | 175 virtual syncer::UserShare* GetUserShare() const OVERRIDE; |
274 | 176 |
275 // Called from any thread to obtain current status information in detailed or | 177 // Called from any thread to obtain current status information in detailed or |
276 // summarized form. | 178 // summarized form. |
277 Status GetDetailedStatus(); | 179 virtual Status GetDetailedStatus() OVERRIDE; |
278 syncer::sessions::SyncSessionSnapshot GetLastSessionSnapshot() const; | 180 virtual syncer::sessions::SyncSessionSnapshot |
| 181 GetLastSessionSnapshot() const OVERRIDE; |
279 | 182 |
280 // Determines if the underlying sync engine has made any local changes to | 183 // Determines if the underlying sync engine has made any local changes to |
281 // items that have not yet been synced with the server. | 184 // items that have not yet been synced with the server. |
282 // ONLY CALL THIS IF OnInitializationComplete was called! | 185 // ONLY CALL THIS IF OnInitializationComplete was called! |
283 bool HasUnsyncedItems() const; | 186 virtual bool HasUnsyncedItems() const OVERRIDE; |
284 | 187 |
285 // Whether or not we are syncing encryption keys. | 188 // Whether or not we are syncing encryption keys. |
286 bool IsNigoriEnabled() const; | 189 virtual bool IsNigoriEnabled() const OVERRIDE; |
287 | 190 |
288 // Returns the type of passphrase being used to encrypt data. See | 191 // Returns the type of passphrase being used to encrypt data. See |
289 // sync_encryption_handler.h. | 192 // sync_encryption_handler.h. |
290 syncer::PassphraseType GetPassphraseType() const; | 193 virtual syncer::PassphraseType GetPassphraseType() const OVERRIDE; |
291 | 194 |
292 // If an explicit passphrase is in use, returns the time at which that | 195 // If an explicit passphrase is in use, returns the time at which that |
293 // passphrase was set (if available). | 196 // passphrase was set (if available). |
294 base::Time GetExplicitPassphraseTime() const; | 197 virtual base::Time GetExplicitPassphraseTime() const OVERRIDE; |
295 | 198 |
296 // True if the cryptographer has any keys available to attempt decryption. | 199 // True if the cryptographer has any keys available to attempt decryption. |
297 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped | 200 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped |
298 // using a token previously received. | 201 // using a token previously received. |
299 bool IsCryptographerReady(const syncer::BaseTransaction* trans) const; | 202 virtual bool IsCryptographerReady( |
| 203 const syncer::BaseTransaction* trans) const OVERRIDE; |
300 | 204 |
301 void GetModelSafeRoutingInfo(syncer::ModelSafeRoutingInfo* out) const; | 205 virtual void GetModelSafeRoutingInfo( |
| 206 syncer::ModelSafeRoutingInfo* out) const OVERRIDE; |
302 | 207 |
303 // Fetches the DeviceInfo tracker. | 208 // Fetches the DeviceInfo tracker. |
304 virtual SyncedDeviceTracker* GetSyncedDeviceTracker() const; | 209 virtual SyncedDeviceTracker* GetSyncedDeviceTracker() const OVERRIDE; |
305 | 210 |
306 base::MessageLoop* GetSyncLoopForTesting(); | 211 virtual base::MessageLoop* GetSyncLoopForTesting() OVERRIDE; |
307 | 212 |
308 protected: | 213 protected: |
309 // The types and functions below are protected so that test | 214 // The types and functions below are protected so that test |
310 // subclasses can use them. | 215 // subclasses can use them. |
311 // | 216 // |
312 // TODO(akalin): Figure out a better way for tests to hook into | 217 // TODO(akalin): Figure out a better way for tests to hook into |
313 // SyncBackendHost. | 218 // SyncBackendHost. |
314 | 219 |
315 // Utility struct for holding initialization options. | |
316 struct DoInitializeOptions { | |
317 DoInitializeOptions( | |
318 base::MessageLoop* sync_loop, | |
319 SyncBackendRegistrar* registrar, | |
320 const syncer::ModelSafeRoutingInfo& routing_info, | |
321 const std::vector<syncer::ModelSafeWorker*>& workers, | |
322 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity, | |
323 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | |
324 const GURL& service_url, | |
325 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory, | |
326 const syncer::SyncCredentials& credentials, | |
327 const std::string& invalidator_client_id, | |
328 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | |
329 bool delete_sync_data_folder, | |
330 const std::string& restored_key_for_bootstrapping, | |
331 const std::string& restored_keystore_key_for_bootstrapping, | |
332 scoped_ptr<syncer::InternalComponentsFactory> | |
333 internal_components_factory, | |
334 scoped_ptr<syncer::UnrecoverableErrorHandler> | |
335 unrecoverable_error_handler, | |
336 syncer::ReportUnrecoverableErrorFunction | |
337 report_unrecoverable_error_function); | |
338 ~DoInitializeOptions(); | |
339 | |
340 base::MessageLoop* sync_loop; | |
341 SyncBackendRegistrar* registrar; | |
342 syncer::ModelSafeRoutingInfo routing_info; | |
343 std::vector<syncer::ModelSafeWorker*> workers; | |
344 scoped_refptr<syncer::ExtensionsActivity> extensions_activity; | |
345 syncer::WeakHandle<syncer::JsEventHandler> event_handler; | |
346 GURL service_url; | |
347 // Overridden by tests. | |
348 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory; | |
349 syncer::SyncCredentials credentials; | |
350 const std::string invalidator_client_id; | |
351 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory; | |
352 std::string lsid; | |
353 bool delete_sync_data_folder; | |
354 std::string restored_key_for_bootstrapping; | |
355 std::string restored_keystore_key_for_bootstrapping; | |
356 scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory; | |
357 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler; | |
358 syncer::ReportUnrecoverableErrorFunction | |
359 report_unrecoverable_error_function; | |
360 }; | |
361 | |
362 // Allows tests to perform alternate core initialization work. | 220 // Allows tests to perform alternate core initialization work. |
363 virtual void InitCore(scoped_ptr<DoInitializeOptions> options); | 221 virtual void InitCore(scoped_ptr<DoInitializeOptions> options); |
364 | 222 |
365 // Request the syncer to reconfigure with the specfied params. | 223 // Request the syncer to reconfigure with the specfied params. |
366 // Virtual for testing. | 224 // Virtual for testing. |
367 virtual void RequestConfigureSyncer( | 225 virtual void RequestConfigureSyncer( |
368 syncer::ConfigureReason reason, | 226 syncer::ConfigureReason reason, |
369 syncer::ModelTypeSet to_download, | 227 syncer::ModelTypeSet to_download, |
370 syncer::ModelTypeSet to_purge, | 228 syncer::ModelTypeSet to_purge, |
371 syncer::ModelTypeSet to_journal, | 229 syncer::ModelTypeSet to_journal, |
(...skipping 19 matching lines...) Expand all Loading... |
391 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> | 249 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener> |
392 debug_info_listener); | 250 debug_info_listener); |
393 | 251 |
394 // Downloading of control types failed and will be retried. Invokes the | 252 // Downloading of control types failed and will be retried. Invokes the |
395 // frontend's sync configure retry method. | 253 // frontend's sync configure retry method. |
396 void HandleControlTypesDownloadRetry(); | 254 void HandleControlTypesDownloadRetry(); |
397 | 255 |
398 SyncFrontend* frontend() { return frontend_; } | 256 SyncFrontend* frontend() { return frontend_; } |
399 | 257 |
400 private: | 258 private: |
401 // The real guts of SyncBackendHost, to keep the public client API clean. | 259 friend class SyncBackendHostCore; |
402 class Core; | |
403 | |
404 // An enum representing the steps to initializing the SyncBackendHost. | |
405 enum InitializationState { | |
406 NOT_ATTEMPTED, | |
407 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the | |
408 // sync thread to inform us that the sync | |
409 // manager has been created. | |
410 NOT_INITIALIZED, // Initialization hasn't completed, but we've | |
411 // constructed a SyncManager. | |
412 INITIALIZATING_CONTROL_TYPES, // Downloading control types and | |
413 // initializing their handlers. | |
414 INITIALIZED, // Initialization is complete. | |
415 }; | |
416 | 260 |
417 // Checks if we have received a notice to turn on experimental datatypes | 261 // Checks if we have received a notice to turn on experimental datatypes |
418 // (via the nigori node) and informs the frontend if that is the case. | 262 // (via the nigori node) and informs the frontend if that is the case. |
419 // Note: it is illegal to call this before the backend is initialized. | 263 // Note: it is illegal to call this before the backend is initialized. |
420 void AddExperimentalTypes(); | 264 void AddExperimentalTypes(); |
421 | 265 |
422 // Handles backend initialization failure. | 266 // Handles backend initialization failure. |
423 void HandleInitializationFailureOnFrontendLoop(); | 267 void HandleInitializationFailureOnFrontendLoop(); |
424 | 268 |
425 // Called from Core::OnSyncCycleCompleted to handle updating frontend | 269 // Called from Core::OnSyncCycleCompleted to handle updating frontend |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 base::MessageLoop* const frontend_loop_; | 360 base::MessageLoop* const frontend_loop_; |
517 | 361 |
518 Profile* const profile_; | 362 Profile* const profile_; |
519 | 363 |
520 // Name used for debugging (set from profile_->GetDebugName()). | 364 // Name used for debugging (set from profile_->GetDebugName()). |
521 const std::string name_; | 365 const std::string name_; |
522 | 366 |
523 // Our core, which communicates directly to the syncapi. Use refptr instead | 367 // Our core, which communicates directly to the syncapi. Use refptr instead |
524 // of WeakHandle because |core_| is created on UI loop but released on | 368 // of WeakHandle because |core_| is created on UI loop but released on |
525 // sync loop. | 369 // sync loop. |
526 scoped_refptr<Core> core_; | 370 scoped_refptr<SyncBackendHostCore> core_; |
527 | 371 |
528 bool initialized_; | 372 bool initialized_; |
529 | 373 |
530 const base::WeakPtr<SyncPrefs> sync_prefs_; | 374 const base::WeakPtr<SyncPrefs> sync_prefs_; |
531 | 375 |
532 ExtensionsActivityMonitor extensions_activity_monitor_; | 376 ExtensionsActivityMonitor extensions_activity_monitor_; |
533 | 377 |
534 scoped_ptr<SyncBackendRegistrar> registrar_; | 378 scoped_ptr<SyncBackendRegistrar> registrar_; |
535 | 379 |
536 // The frontend which we serve (and are owned by). | 380 // The frontend which we serve (and are owned by). |
(...skipping 18 matching lines...) Expand all Loading... |
555 // If an explicit passphrase is in use, the time at which the passphrase was | 399 // If an explicit passphrase is in use, the time at which the passphrase was |
556 // first set (if available). | 400 // first set (if available). |
557 base::Time cached_explicit_passphrase_time_; | 401 base::Time cached_explicit_passphrase_time_; |
558 | 402 |
559 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 403 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
560 syncer::sessions::SyncSessionSnapshot last_snapshot_; | 404 syncer::sessions::SyncSessionSnapshot last_snapshot_; |
561 | 405 |
562 invalidation::InvalidationService* invalidator_; | 406 invalidation::InvalidationService* invalidator_; |
563 bool invalidation_handler_registered_; | 407 bool invalidation_handler_registered_; |
564 | 408 |
565 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; | 409 base::WeakPtrFactory<SyncBackendHostImpl> weak_ptr_factory_; |
566 | 410 |
567 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 411 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostImpl); |
568 }; | 412 }; |
569 | 413 |
570 } // namespace browser_sync | 414 } // namespace browser_sync |
571 | 415 |
572 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 416 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_IMPL_H_ |
| 417 |
OLD | NEW |