| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // dispatch of potentially blocking calls to appropriate threads and ensures | 110 // dispatch of potentially blocking calls to appropriate threads and ensures |
| 111 // that the SyncFrontend is only accessed on the UI loop. | 111 // that the SyncFrontend is only accessed on the UI loop. |
| 112 class SyncBackendHost { | 112 class SyncBackendHost { |
| 113 public: | 113 public: |
| 114 typedef sync_api::SyncManager::Status::Summary StatusSummary; | 114 typedef sync_api::SyncManager::Status::Summary StatusSummary; |
| 115 typedef sync_api::SyncManager::Status Status; | 115 typedef sync_api::SyncManager::Status Status; |
| 116 | 116 |
| 117 // Create a SyncBackendHost with a reference to the |frontend| that it serves | 117 // Create a SyncBackendHost with a reference to the |frontend| that it serves |
| 118 // and communicates to via the SyncFrontend interface (on the same thread | 118 // and communicates to via the SyncFrontend interface (on the same thread |
| 119 // it used to call the constructor). | 119 // it used to call the constructor). |
| 120 explicit SyncBackendHost(Profile* profile); | 120 SyncBackendHost(const std::string& name, Profile* profile); |
| 121 // For testing. | 121 // For testing. |
| 122 // TODO(skrul): Extract an interface so this is not needed. | 122 // TODO(skrul): Extract an interface so this is not needed. |
| 123 SyncBackendHost(); | 123 SyncBackendHost(); |
| 124 virtual ~SyncBackendHost(); | 124 virtual ~SyncBackendHost(); |
| 125 | 125 |
| 126 // Called on |frontend_loop_| to kick off asynchronous initialization. | 126 // Called on |frontend_loop_| to kick off asynchronous initialization. |
| 127 // As a fallback when no cached auth information is available, try to | 127 // As a fallback when no cached auth information is available, try to |
| 128 // bootstrap authentication using |lsid|, if it isn't empty. | 128 // bootstrap authentication using |lsid|, if it isn't empty. |
| 129 // Optionally delete the Sync Data folder (if it's corrupt). | 129 // Optionally delete the Sync Data folder (if it's corrupt). |
| 130 void Initialize(SyncFrontend* frontend, | 130 void Initialize(SyncFrontend* frontend, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 // Encrypts the specified datatypes and marks them as needing encryption on | 173 // Encrypts the specified datatypes and marks them as needing encryption on |
| 174 // other machines. This affects all machines synced to this account and all | 174 // other machines. This affects all machines synced to this account and all |
| 175 // data belonging to the specified types. | 175 // data belonging to the specified types. |
| 176 // Note: actual work is done on sync_thread_'s message loop. | 176 // Note: actual work is done on sync_thread_'s message loop. |
| 177 virtual void EncryptDataTypes( | 177 virtual void EncryptDataTypes( |
| 178 const syncable::ModelTypeSet& encrypted_types); | 178 const syncable::ModelTypeSet& encrypted_types); |
| 179 | 179 |
| 180 syncable::ModelTypeSet GetEncryptedDataTypes() const; | 180 syncable::ModelTypeSet GetEncryptedDataTypes() const; |
| 181 | 181 |
| 182 // Returns the set of types for which there is no sync data. |
| 183 // Overrideable for testing. |
| 184 virtual syncable::ModelTypeSet GetUnsyncedDataTypes() const; |
| 185 |
| 182 // Activates change processing for the given data type. This must | 186 // Activates change processing for the given data type. This must |
| 183 // be called synchronously with the data type's model association so | 187 // be called synchronously with the data type's model association so |
| 184 // no changes are dropped between model association and change | 188 // no changes are dropped between model association and change |
| 185 // processor activation. | 189 // processor activation. |
| 186 void ActivateDataType( | 190 void ActivateDataType( |
| 187 syncable::ModelType type, ModelSafeGroup group, | 191 syncable::ModelType type, ModelSafeGroup group, |
| 188 ChangeProcessor* change_processor); | 192 ChangeProcessor* change_processor); |
| 189 | 193 |
| 190 // Deactivates change processing for the given data type. | 194 // Deactivates change processing for the given data type. |
| 191 void DeactivateDataType(syncable::ModelType type); | 195 void DeactivateDataType(syncable::ModelType type); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 DOWNLOADING_NIGORI, // The SyncManager is initialized, but we're fetching | 245 DOWNLOADING_NIGORI, // The SyncManager is initialized, but we're fetching |
| 242 // encryption information before alerting the | 246 // encryption information before alerting the |
| 243 // frontend. | 247 // frontend. |
| 244 INITIALIZED, // Initialization is complete. | 248 INITIALIZED, // Initialization is complete. |
| 245 }; | 249 }; |
| 246 | 250 |
| 247 // The real guts of SyncBackendHost, to keep the public client API clean. | 251 // The real guts of SyncBackendHost, to keep the public client API clean. |
| 248 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 252 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
| 249 public sync_api::SyncManager::Observer { | 253 public sync_api::SyncManager::Observer { |
| 250 public: | 254 public: |
| 251 Core(Profile* profile, SyncBackendHost* backend); | 255 Core(const std::string& name, SyncBackendHost* backend); |
| 252 | 256 |
| 253 // SyncManager::Observer implementation. The Core just acts like an air | 257 // SyncManager::Observer implementation. The Core just acts like an air |
| 254 // traffic controller here, forwarding incoming messages to appropriate | 258 // traffic controller here, forwarding incoming messages to appropriate |
| 255 // landing threads. | 259 // landing threads. |
| 256 virtual void OnChangesApplied( | 260 virtual void OnChangesApplied( |
| 257 syncable::ModelType model_type, | 261 syncable::ModelType model_type, |
| 258 const sync_api::BaseTransaction* trans, | 262 const sync_api::BaseTransaction* trans, |
| 259 const sync_api::SyncManager::ChangeRecord* changes, | 263 const sync_api::SyncManager::ChangeRecord* changes, |
| 260 int change_count) OVERRIDE; | 264 int change_count) OVERRIDE; |
| 261 virtual void OnChangesComplete( | 265 virtual void OnChangesComplete( |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 sessions::SyncSessionSnapshot* snapshot); | 434 sessions::SyncSessionSnapshot* snapshot); |
| 431 | 435 |
| 432 void HandleStopSyncingPermanentlyOnFrontendLoop(); | 436 void HandleStopSyncingPermanentlyOnFrontendLoop(); |
| 433 | 437 |
| 434 // Called to handle success/failure of clearing server data | 438 // Called to handle success/failure of clearing server data |
| 435 void HandleClearServerDataSucceededOnFrontendLoop(); | 439 void HandleClearServerDataSucceededOnFrontendLoop(); |
| 436 void HandleClearServerDataFailedOnFrontendLoop(); | 440 void HandleClearServerDataFailedOnFrontendLoop(); |
| 437 | 441 |
| 438 void FinishConfigureDataTypesOnFrontendLoop(); | 442 void FinishConfigureDataTypesOnFrontendLoop(); |
| 439 | 443 |
| 440 Profile* profile_; | 444 // Name used for debugging. |
| 445 const std::string name_; |
| 441 | 446 |
| 442 // Our parent SyncBackendHost | 447 // Our parent SyncBackendHost |
| 443 SyncBackendHost* host_; | 448 SyncBackendHost* host_; |
| 444 | 449 |
| 445 // Our parent's registrar (not owned). Non-NULL only between | 450 // Our parent's registrar (not owned). Non-NULL only between |
| 446 // calls to DoInitialize() and DoShutdown(). | 451 // calls to DoInitialize() and DoShutdown(). |
| 447 SyncBackendRegistrar* registrar_; | 452 SyncBackendRegistrar* registrar_; |
| 448 | 453 |
| 449 // The timer used to periodically call SaveChanges. | 454 // The timer used to periodically call SaveChanges. |
| 450 base::RepeatingTimer<Core> save_changes_timer_; | 455 base::RepeatingTimer<Core> save_changes_timer_; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // For convenience, checks if initialization state is INITIALIZED. | 521 // For convenience, checks if initialization state is INITIALIZED. |
| 517 bool initialized() const { return initialization_state_ == INITIALIZED; } | 522 bool initialized() const { return initialization_state_ == INITIALIZED; } |
| 518 | 523 |
| 519 // A thread where all the sync operations happen. | 524 // A thread where all the sync operations happen. |
| 520 base::Thread sync_thread_; | 525 base::Thread sync_thread_; |
| 521 | 526 |
| 522 // A reference to the MessageLoop used to construct |this|, so we know how | 527 // A reference to the MessageLoop used to construct |this|, so we know how |
| 523 // to safely talk back to the SyncFrontend. | 528 // to safely talk back to the SyncFrontend. |
| 524 MessageLoop* const frontend_loop_; | 529 MessageLoop* const frontend_loop_; |
| 525 | 530 |
| 526 Profile* profile_; | 531 Profile* const profile_; |
| 532 |
| 533 // Name used for debugging (set from profile_->GetDebugName()). |
| 534 const std::string name_; |
| 527 | 535 |
| 528 sync_notifier::SyncNotifierFactory sync_notifier_factory_; | 536 sync_notifier::SyncNotifierFactory sync_notifier_factory_; |
| 529 | 537 |
| 530 scoped_ptr<SyncBackendRegistrar> registrar_; | 538 scoped_ptr<SyncBackendRegistrar> registrar_; |
| 531 | 539 |
| 532 // The frontend which we serve (and are owned by). | 540 // The frontend which we serve (and are owned by). |
| 533 SyncFrontend* frontend_; | 541 SyncFrontend* frontend_; |
| 534 | 542 |
| 535 // Path of the folder that stores the sync data files. | 543 // Path of the folder that stores the sync data files. |
| 536 FilePath sync_data_folder_path_; | 544 FilePath sync_data_folder_path_; |
| 537 | 545 |
| 538 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; | 546 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; |
| 539 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; | 547 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; |
| 540 | 548 |
| 541 // UI-thread cache of the last AuthErrorState received from syncapi. | 549 // UI-thread cache of the last AuthErrorState received from syncapi. |
| 542 GoogleServiceAuthError last_auth_error_; | 550 GoogleServiceAuthError last_auth_error_; |
| 543 | 551 |
| 544 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 552 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
| 545 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; | 553 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; |
| 546 | 554 |
| 547 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 555 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 548 }; | 556 }; |
| 549 | 557 |
| 550 } // namespace browser_sync | 558 } // namespace browser_sync |
| 551 | 559 |
| 552 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 560 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |