OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // below). | 96 // below). |
97 // | 97 // |
98 // |encrypted_types| will always be a superset of | 98 // |encrypted_types| will always be a superset of |
99 // Cryptographer::SensitiveTypes(). If |encrypt_everything| is | 99 // Cryptographer::SensitiveTypes(). If |encrypt_everything| is |
100 // true, |encrypted_types| will be the set of all known types. | 100 // true, |encrypted_types| will be the set of all known types. |
101 // | 101 // |
102 // Until this function is called, observers can assume that the set | 102 // Until this function is called, observers can assume that the set |
103 // of encrypted types is Cryptographer::SensitiveTypes() and that | 103 // of encrypted types is Cryptographer::SensitiveTypes() and that |
104 // the encrypt everything flag is false. | 104 // the encrypt everything flag is false. |
105 virtual void OnEncryptedTypesChanged( | 105 virtual void OnEncryptedTypesChanged( |
106 syncable::ModelEnumSet encrypted_types, | 106 syncable::ModelTypeSet encrypted_types, |
107 bool encrypt_everything) = 0; | 107 bool encrypt_everything) = 0; |
108 | 108 |
109 // Called after we finish encrypting the current set of encrypted | 109 // Called after we finish encrypting the current set of encrypted |
110 // types. | 110 // types. |
111 virtual void OnEncryptionComplete() = 0; | 111 virtual void OnEncryptionComplete() = 0; |
112 | 112 |
113 // Called to perform migration of |types|. | 113 // Called to perform migration of |types|. |
114 virtual void OnMigrationNeededForTypes( | 114 virtual void OnMigrationNeededForTypes( |
115 syncable::ModelEnumSet types) = 0; | 115 syncable::ModelTypeSet types) = 0; |
116 | 116 |
117 // Inform the Frontend that new datatypes are available for registration. | 117 // Inform the Frontend that new datatypes are available for registration. |
118 virtual void OnDataTypesChanged(syncable::ModelEnumSet to_add) = 0; | 118 virtual void OnDataTypesChanged(syncable::ModelTypeSet to_add) = 0; |
119 | 119 |
120 // Called when the sync cycle returns there is an user actionable error. | 120 // Called when the sync cycle returns there is an user actionable error. |
121 virtual void OnActionableError( | 121 virtual void OnActionableError( |
122 const browser_sync::SyncProtocolError& error) = 0; | 122 const browser_sync::SyncProtocolError& error) = 0; |
123 | 123 |
124 protected: | 124 protected: |
125 // Don't delete through SyncFrontend interface. | 125 // Don't delete through SyncFrontend interface. |
126 virtual ~SyncFrontend() { | 126 virtual ~SyncFrontend() { |
127 } | 127 } |
128 private: | 128 private: |
(...skipping 21 matching lines...) Expand all Loading... |
150 SyncBackendHost(); | 150 SyncBackendHost(); |
151 virtual ~SyncBackendHost(); | 151 virtual ~SyncBackendHost(); |
152 | 152 |
153 // Called on |frontend_loop_| to kick off asynchronous initialization. | 153 // Called on |frontend_loop_| to kick off asynchronous initialization. |
154 // As a fallback when no cached auth information is available, try to | 154 // As a fallback when no cached auth information is available, try to |
155 // bootstrap authentication using |lsid|, if it isn't empty. | 155 // bootstrap authentication using |lsid|, if it isn't empty. |
156 // Optionally delete the Sync Data folder (if it's corrupt). | 156 // Optionally delete the Sync Data folder (if it's corrupt). |
157 void Initialize(SyncFrontend* frontend, | 157 void Initialize(SyncFrontend* frontend, |
158 const WeakHandle<JsEventHandler>& event_handler, | 158 const WeakHandle<JsEventHandler>& event_handler, |
159 const GURL& service_url, | 159 const GURL& service_url, |
160 syncable::ModelEnumSet initial_types, | 160 syncable::ModelTypeSet initial_types, |
161 const sync_api::SyncCredentials& credentials, | 161 const sync_api::SyncCredentials& credentials, |
162 bool delete_sync_data_folder); | 162 bool delete_sync_data_folder); |
163 | 163 |
164 // Called from |frontend_loop| to update SyncCredentials. | 164 // Called from |frontend_loop| to update SyncCredentials. |
165 void UpdateCredentials(const sync_api::SyncCredentials& credentials); | 165 void UpdateCredentials(const sync_api::SyncCredentials& credentials); |
166 | 166 |
167 // This starts the SyncerThread running a Syncer object to communicate with | 167 // This starts the SyncerThread running a Syncer object to communicate with |
168 // sync servers. Until this is called, no changes will leave or enter this | 168 // sync servers. Until this is called, no changes will leave or enter this |
169 // browser from the cloud / sync servers. | 169 // browser from the cloud / sync servers. |
170 // Called on |frontend_loop_|. | 170 // Called on |frontend_loop_|. |
(...skipping 15 matching lines...) Expand all Loading... |
186 // |sync_disabled| indicates if syncing is being disabled or not. | 186 // |sync_disabled| indicates if syncing is being disabled or not. |
187 // See the implementation and Core::DoShutdown for details. | 187 // See the implementation and Core::DoShutdown for details. |
188 // Must be called *after* StopSyncingForShutdown. | 188 // Must be called *after* StopSyncingForShutdown. |
189 void Shutdown(bool sync_disabled); | 189 void Shutdown(bool sync_disabled); |
190 | 190 |
191 // Changes the set of data types that are currently being synced. | 191 // Changes the set of data types that are currently being synced. |
192 // The ready_task will be run when configuration is done with the | 192 // The ready_task will be run when configuration is done with the |
193 // set of all types that failed configuration (i.e., if its argument | 193 // set of all types that failed configuration (i.e., if its argument |
194 // is non-empty, then an error was encountered). | 194 // is non-empty, then an error was encountered). |
195 virtual void ConfigureDataTypes( | 195 virtual void ConfigureDataTypes( |
196 syncable::ModelEnumSet types_to_add, | 196 syncable::ModelTypeSet types_to_add, |
197 syncable::ModelEnumSet types_to_remove, | 197 syncable::ModelTypeSet types_to_remove, |
198 sync_api::ConfigureReason reason, | 198 sync_api::ConfigureReason reason, |
199 base::Callback<void(syncable::ModelEnumSet)> ready_task, | 199 base::Callback<void(syncable::ModelTypeSet)> ready_task, |
200 bool enable_nigori); | 200 bool enable_nigori); |
201 | 201 |
202 // Makes an asynchronous call to syncer to switch to config mode. When done | 202 // Makes an asynchronous call to syncer to switch to config mode. When done |
203 // syncer will call us back on FinishConfigureDataTypes. | 203 // syncer will call us back on FinishConfigureDataTypes. |
204 virtual void StartConfiguration(const base::Closure& callback); | 204 virtual void StartConfiguration(const base::Closure& callback); |
205 | 205 |
206 // Turns on encryption of all present and future sync data. | 206 // Turns on encryption of all present and future sync data. |
207 virtual void EnableEncryptEverything(); | 207 virtual void EnableEncryptEverything(); |
208 | 208 |
209 // Activates change processing for the given data type. This must | 209 // Activates change processing for the given data type. This must |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 const GoogleServiceAuthError& auth_error) OVERRIDE; | 288 const GoogleServiceAuthError& auth_error) OVERRIDE; |
289 virtual void OnPassphraseRequired( | 289 virtual void OnPassphraseRequired( |
290 sync_api::PassphraseRequiredReason reason) OVERRIDE; | 290 sync_api::PassphraseRequiredReason reason) OVERRIDE; |
291 virtual void OnPassphraseAccepted( | 291 virtual void OnPassphraseAccepted( |
292 const std::string& bootstrap_token) OVERRIDE; | 292 const std::string& bootstrap_token) OVERRIDE; |
293 virtual void OnStopSyncingPermanently() OVERRIDE; | 293 virtual void OnStopSyncingPermanently() OVERRIDE; |
294 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; | 294 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; |
295 virtual void OnClearServerDataFailed() OVERRIDE; | 295 virtual void OnClearServerDataFailed() OVERRIDE; |
296 virtual void OnClearServerDataSucceeded() OVERRIDE; | 296 virtual void OnClearServerDataSucceeded() OVERRIDE; |
297 virtual void OnEncryptedTypesChanged( | 297 virtual void OnEncryptedTypesChanged( |
298 syncable::ModelEnumSet encrypted_types, | 298 syncable::ModelTypeSet encrypted_types, |
299 bool encrypt_everything) OVERRIDE; | 299 bool encrypt_everything) OVERRIDE; |
300 virtual void OnEncryptionComplete() OVERRIDE; | 300 virtual void OnEncryptionComplete() OVERRIDE; |
301 virtual void OnActionableError( | 301 virtual void OnActionableError( |
302 const browser_sync::SyncProtocolError& sync_error) OVERRIDE; | 302 const browser_sync::SyncProtocolError& sync_error) OVERRIDE; |
303 | 303 |
304 struct DoInitializeOptions { | 304 struct DoInitializeOptions { |
305 DoInitializeOptions( | 305 DoInitializeOptions( |
306 MessageLoop* sync_loop, | 306 MessageLoop* sync_loop, |
307 SyncBackendRegistrar* registrar, | 307 SyncBackendRegistrar* registrar, |
308 const WeakHandle<JsEventHandler>& event_handler, | 308 const WeakHandle<JsEventHandler>& event_handler, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // a blocking call). This causes syncapi thread-exit handlers | 379 // a blocking call). This causes syncapi thread-exit handlers |
380 // to run and make use of cached pointers to various components | 380 // to run and make use of cached pointers to various components |
381 // owned implicitly by us. | 381 // owned implicitly by us. |
382 // 3) Destroy this Core. That will delete syncapi components in a | 382 // 3) Destroy this Core. That will delete syncapi components in a |
383 // safe order because the thread that was using them has exited | 383 // safe order because the thread that was using them has exited |
384 // (in step 2). | 384 // (in step 2). |
385 void DoStopSyncManagerForShutdown(const base::Closure& closure); | 385 void DoStopSyncManagerForShutdown(const base::Closure& closure); |
386 void DoShutdown(bool stopping_sync); | 386 void DoShutdown(bool stopping_sync); |
387 | 387 |
388 virtual void DoRequestConfig( | 388 virtual void DoRequestConfig( |
389 syncable::ModelEnumSet types_to_config, | 389 syncable::ModelTypeSet types_to_config, |
390 sync_api::ConfigureReason reason); | 390 sync_api::ConfigureReason reason); |
391 | 391 |
392 // Start the configuration mode. |callback| is called on the sync | 392 // Start the configuration mode. |callback| is called on the sync |
393 // thread. | 393 // thread. |
394 virtual void DoStartConfiguration(const base::Closure& callback); | 394 virtual void DoStartConfiguration(const base::Closure& callback); |
395 | 395 |
396 // Set the base request context to use when making HTTP calls. | 396 // Set the base request context to use when making HTTP calls. |
397 // This method will add a reference to the context to persist it | 397 // This method will add a reference to the context to persist it |
398 // on the IO thread. Must be removed from IO thread. | 398 // on the IO thread. Must be removed from IO thread. |
399 | 399 |
(...skipping 10 matching lines...) Expand all Loading... |
410 // Called to handle updating frontend thread components whenever we may | 410 // Called to handle updating frontend thread components whenever we may |
411 // need to alert the frontend that the backend is intialized. | 411 // need to alert the frontend that the backend is intialized. |
412 void HandleInitializationCompletedOnFrontendLoop( | 412 void HandleInitializationCompletedOnFrontendLoop( |
413 const WeakHandle<JsBackend>& js_backend, | 413 const WeakHandle<JsBackend>& js_backend, |
414 bool success); | 414 bool success); |
415 | 415 |
416 // Called when configuration of the Nigori node has completed as | 416 // Called when configuration of the Nigori node has completed as |
417 // part of the initialization process. | 417 // part of the initialization process. |
418 void HandleNigoriConfigurationCompletedOnFrontendLoop( | 418 void HandleNigoriConfigurationCompletedOnFrontendLoop( |
419 const WeakHandle<JsBackend>& js_backend, | 419 const WeakHandle<JsBackend>& js_backend, |
420 syncable::ModelEnumSet failed_configuration_types); | 420 syncable::ModelTypeSet failed_configuration_types); |
421 | 421 |
422 private: | 422 private: |
423 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 423 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
424 friend class SyncBackendHostForProfileSyncTest; | 424 friend class SyncBackendHostForProfileSyncTest; |
425 | 425 |
426 virtual ~Core(); | 426 virtual ~Core(); |
427 | 427 |
428 // Invoked when initialization of syncapi is complete and we can start | 428 // Invoked when initialization of syncapi is complete and we can start |
429 // our timer. | 429 // our timer. |
430 // This must be called from the thread on which SaveChanges is intended to | 430 // This must be called from the thread on which SaveChanges is intended to |
(...skipping 23 matching lines...) Expand all Loading... |
454 | 454 |
455 // Invoked when the passphrase provided by the user has been accepted. | 455 // Invoked when the passphrase provided by the user has been accepted. |
456 void NotifyPassphraseAccepted(const std::string& bootstrap_token); | 456 void NotifyPassphraseAccepted(const std::string& bootstrap_token); |
457 | 457 |
458 // Invoked when an updated token is available from the sync server. | 458 // Invoked when an updated token is available from the sync server. |
459 void NotifyUpdatedToken(const std::string& token); | 459 void NotifyUpdatedToken(const std::string& token); |
460 | 460 |
461 // Invoked when the set of encrypted types or the encrypt | 461 // Invoked when the set of encrypted types or the encrypt |
462 // everything flag changes. | 462 // everything flag changes. |
463 void NotifyEncryptedTypesChanged( | 463 void NotifyEncryptedTypesChanged( |
464 syncable::ModelEnumSet encrypted_types, | 464 syncable::ModelTypeSet encrypted_types, |
465 bool encrypt_everything); | 465 bool encrypt_everything); |
466 | 466 |
467 // Invoked when sync finishes encrypting new datatypes. | 467 // Invoked when sync finishes encrypting new datatypes. |
468 void NotifyEncryptionComplete(); | 468 void NotifyEncryptionComplete(); |
469 | 469 |
470 // Called from Core::OnSyncCycleCompleted to handle updating frontend | 470 // Called from Core::OnSyncCycleCompleted to handle updating frontend |
471 // thread components. | 471 // thread components. |
472 void HandleSyncCycleCompletedOnFrontendLoop( | 472 void HandleSyncCycleCompletedOnFrontendLoop( |
473 sessions::SyncSessionSnapshot* snapshot); | 473 sessions::SyncSessionSnapshot* snapshot); |
474 | 474 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 InitializationState initialization_state_; | 539 InitializationState initialization_state_; |
540 | 540 |
541 private: | 541 private: |
542 struct PendingConfigureDataTypesState { | 542 struct PendingConfigureDataTypesState { |
543 PendingConfigureDataTypesState(); | 543 PendingConfigureDataTypesState(); |
544 ~PendingConfigureDataTypesState(); | 544 ~PendingConfigureDataTypesState(); |
545 | 545 |
546 // The ready_task will be run when configuration is done with the | 546 // The ready_task will be run when configuration is done with the |
547 // set of all types that failed configuration (i.e., if its | 547 // set of all types that failed configuration (i.e., if its |
548 // argument is non-empty, then an error was encountered). | 548 // argument is non-empty, then an error was encountered). |
549 base::Callback<void(syncable::ModelEnumSet)> ready_task; | 549 base::Callback<void(syncable::ModelTypeSet)> ready_task; |
550 | 550 |
551 // The set of types that we are waiting to be initially synced in a | 551 // The set of types that we are waiting to be initially synced in a |
552 // configuration cycle. | 552 // configuration cycle. |
553 syncable::ModelEnumSet types_to_add; | 553 syncable::ModelTypeSet types_to_add; |
554 | 554 |
555 // Additional details about which types were added. | 555 // Additional details about which types were added. |
556 syncable::ModelEnumSet added_types; | 556 syncable::ModelTypeSet added_types; |
557 sync_api::ConfigureReason reason; | 557 sync_api::ConfigureReason reason; |
558 }; | 558 }; |
559 | 559 |
560 // For convenience, checks if initialization state is INITIALIZED. | 560 // For convenience, checks if initialization state is INITIALIZED. |
561 bool initialized() const { return initialization_state_ == INITIALIZED; } | 561 bool initialized() const { return initialization_state_ == INITIALIZED; } |
562 | 562 |
563 // Must be called on |frontend_loop_|. |done_callback| is called on | 563 // Must be called on |frontend_loop_|. |done_callback| is called on |
564 // |frontend_loop_|. | 564 // |frontend_loop_|. |
565 void RefreshEncryption(const base::Closure& done_callback); | 565 void RefreshEncryption(const base::Closure& done_callback); |
566 | 566 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 | 600 |
601 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 601 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
602 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; | 602 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; |
603 | 603 |
604 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 604 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
605 }; | 605 }; |
606 | 606 |
607 } // namespace browser_sync | 607 } // namespace browser_sync |
608 | 608 |
609 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 609 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
OLD | NEW |