| 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 SYNC_INTERNAL_API_SYNC_MANAGER_H_ | 5 #ifndef SYNC_INTERNAL_API_SYNC_MANAGER_H_ |
| 6 #define SYNC_INTERNAL_API_SYNC_MANAGER_H_ | 6 #define SYNC_INTERNAL_API_SYNC_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "net/base/network_change_notifier.h" | 11 #include "net/base/network_change_notifier.h" |
| 12 #include "sync/engine/all_status.h" | 12 #include "sync/engine/all_status.h" |
| 13 #include "sync/engine/net/server_connection_manager.h" | 13 #include "sync/engine/net/server_connection_manager.h" |
| 14 #include "sync/engine/sync_engine_event.h" | 14 #include "sync/engine/sync_engine_event.h" |
| 15 #include "sync/engine/throttled_data_type_tracker.h" | 15 #include "sync/engine/throttled_data_type_tracker.h" |
| 16 #include "sync/engine/traffic_recorder.h" | 16 #include "sync/engine/traffic_recorder.h" |
| 17 #include "sync/internal_api/change_reorder_buffer.h" | 17 #include "sync/internal_api/change_reorder_buffer.h" |
| 18 #include "sync/internal_api/debug_info_event_listener.h" | 18 #include "sync/internal_api/debug_info_event_listener.h" |
| 19 #include "sync/internal_api/js_mutation_event_observer.h" | 19 #include "sync/internal_api/js_mutation_event_observer.h" |
| 20 #include "sync/internal_api/js_sync_encryption_handler_observer.h" | 20 #include "sync/internal_api/js_sync_encryption_handler_observer.h" |
| 21 #include "sync/internal_api/js_sync_manager_observer.h" | 21 #include "sync/internal_api/js_sync_manager_observer.h" |
| 22 #include "sync/internal_api/public/sync_manager.h" | 22 #include "sync/internal_api/public/sync_manager.h" |
| 23 #include "sync/internal_api/sync_encryption_handler_impl.h" | 23 #include "sync/internal_api/sync_encryption_handler_impl.h" |
| 24 #include "sync/js/js_backend.h" | 24 #include "sync/js/js_backend.h" |
| 25 #include "sync/notifier/invalidation_handler.h" |
| 25 #include "sync/notifier/notifications_disabled_reason.h" | 26 #include "sync/notifier/notifications_disabled_reason.h" |
| 26 #include "sync/notifier/sync_notifier_observer.h" | |
| 27 #include "sync/syncable/directory_change_delegate.h" | 27 #include "sync/syncable/directory_change_delegate.h" |
| 28 #include "sync/util/cryptographer.h" | 28 #include "sync/util/cryptographer.h" |
| 29 #include "sync/util/time.h" | 29 #include "sync/util/time.h" |
| 30 | 30 |
| 31 namespace syncer { | 31 namespace syncer { |
| 32 | 32 |
| 33 class SyncAPIServerConnectionManager; | 33 class SyncAPIServerConnectionManager; |
| 34 class WriteNode; | 34 class WriteNode; |
| 35 class WriteTransaction; | 35 class WriteTransaction; |
| 36 | 36 |
| 37 namespace sessions { | 37 namespace sessions { |
| 38 class SyncSessionContext; | 38 class SyncSessionContext; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // SyncManager encapsulates syncable::Directory and serves as the parent of all | 41 // SyncManager encapsulates syncable::Directory and serves as the parent of all |
| 42 // other objects in the sync API. If multiple threads interact with the same | 42 // other objects in the sync API. If multiple threads interact with the same |
| 43 // local sync repository (i.e. the same sqlite database), they should share a | 43 // local sync repository (i.e. the same sqlite database), they should share a |
| 44 // single SyncManager instance. The caller should typically create one | 44 // single SyncManager instance. The caller should typically create one |
| 45 // SyncManager for the lifetime of a user session. | 45 // SyncManager for the lifetime of a user session. |
| 46 // | 46 // |
| 47 // Unless stated otherwise, all methods of SyncManager should be called on the | 47 // Unless stated otherwise, all methods of SyncManager should be called on the |
| 48 // same thread. | 48 // same thread. |
| 49 class SyncManagerImpl : public SyncManager, | 49 class SyncManagerImpl : public SyncManager, |
| 50 public net::NetworkChangeNotifier::IPAddressObserver, | 50 public net::NetworkChangeNotifier::IPAddressObserver, |
| 51 public SyncNotifierObserver, | 51 public InvalidationHandler, |
| 52 public JsBackend, | 52 public JsBackend, |
| 53 public SyncEngineEventListener, | 53 public SyncEngineEventListener, |
| 54 public ServerConnectionEventListener, | 54 public ServerConnectionEventListener, |
| 55 public syncable::DirectoryChangeDelegate, | 55 public syncable::DirectoryChangeDelegate, |
| 56 public SyncEncryptionHandler::Observer { | 56 public SyncEncryptionHandler::Observer { |
| 57 public: | 57 public: |
| 58 // Create an uninitialized SyncManager. Callers must Init() before using. | 58 // Create an uninitialized SyncManager. Callers must Init() before using. |
| 59 explicit SyncManagerImpl(const std::string& name); | 59 explicit SyncManagerImpl(const std::string& name); |
| 60 virtual ~SyncManagerImpl(); | 60 virtual ~SyncManagerImpl(); |
| 61 | 61 |
| 62 // SyncManager implementation. | 62 // SyncManager implementation. |
| 63 virtual void Init( | 63 virtual void Init( |
| 64 const FilePath& database_location, | 64 const FilePath& database_location, |
| 65 const WeakHandle<JsEventHandler>& event_handler, | 65 const WeakHandle<JsEventHandler>& event_handler, |
| 66 const std::string& sync_server_and_path, | 66 const std::string& sync_server_and_path, |
| 67 int sync_server_port, | 67 int sync_server_port, |
| 68 bool use_ssl, | 68 bool use_ssl, |
| 69 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 69 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 70 scoped_ptr<HttpPostProviderFactory> post_factory, | 70 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 71 const std::vector<ModelSafeWorker*>& workers, | 71 const std::vector<ModelSafeWorker*>& workers, |
| 72 ExtensionsActivityMonitor* extensions_activity_monitor, | 72 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 73 SyncManager::ChangeDelegate* change_delegate, | 73 SyncManager::ChangeDelegate* change_delegate, |
| 74 const SyncCredentials& credentials, | 74 const SyncCredentials& credentials, |
| 75 scoped_ptr<SyncNotifier> sync_notifier, | 75 scoped_ptr<Invalidator> invalidator, |
| 76 const std::string& restored_key_for_bootstrapping, | 76 const std::string& restored_key_for_bootstrapping, |
| 77 const std::string& restored_keystore_key_for_bootstrapping, | 77 const std::string& restored_keystore_key_for_bootstrapping, |
| 78 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 78 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 79 Encryptor* encryptor, | 79 Encryptor* encryptor, |
| 80 UnrecoverableErrorHandler* unrecoverable_error_handler, | 80 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 81 ReportUnrecoverableErrorFunction | 81 ReportUnrecoverableErrorFunction |
| 82 report_unrecoverable_error_function) OVERRIDE; | 82 report_unrecoverable_error_function) OVERRIDE; |
| 83 virtual void ThrowUnrecoverableError() OVERRIDE; | 83 virtual void ThrowUnrecoverableError() OVERRIDE; |
| 84 virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE; | 84 virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE; |
| 85 virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken( | 85 virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken( |
| 86 ModelTypeSet types) OVERRIDE; | 86 ModelTypeSet types) OVERRIDE; |
| 87 virtual bool PurgePartiallySyncedTypes() OVERRIDE; | 87 virtual bool PurgePartiallySyncedTypes() OVERRIDE; |
| 88 virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; | 88 virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; |
| 89 virtual void UpdateEnabledTypes( | 89 virtual void UpdateEnabledTypes( |
| 90 const ModelTypeSet& enabled_types) OVERRIDE; | 90 const ModelTypeSet& enabled_types) OVERRIDE; |
| 91 virtual void RegisterInvalidationHandler( | 91 virtual void RegisterInvalidationHandler( |
| 92 SyncNotifierObserver* handler) OVERRIDE; | 92 InvalidationHandler* handler) OVERRIDE; |
| 93 virtual void UpdateRegisteredInvalidationIds( | 93 virtual void UpdateRegisteredInvalidationIds( |
| 94 SyncNotifierObserver* handler, | 94 InvalidationHandler* handler, |
| 95 const ObjectIdSet& ids) OVERRIDE; | 95 const ObjectIdSet& ids) OVERRIDE; |
| 96 virtual void UnregisterInvalidationHandler( | 96 virtual void UnregisterInvalidationHandler( |
| 97 SyncNotifierObserver* handler) OVERRIDE; | 97 InvalidationHandler* handler) OVERRIDE; |
| 98 virtual void StartSyncingNormally( | 98 virtual void StartSyncingNormally( |
| 99 const ModelSafeRoutingInfo& routing_info) OVERRIDE; | 99 const ModelSafeRoutingInfo& routing_info) OVERRIDE; |
| 100 virtual void ConfigureSyncer( | 100 virtual void ConfigureSyncer( |
| 101 ConfigureReason reason, | 101 ConfigureReason reason, |
| 102 const ModelTypeSet& types_to_config, | 102 const ModelTypeSet& types_to_config, |
| 103 const ModelSafeRoutingInfo& new_routing_info, | 103 const ModelSafeRoutingInfo& new_routing_info, |
| 104 const base::Closure& ready_task, | 104 const base::Closure& ready_task, |
| 105 const base::Closure& retry_task) OVERRIDE; | 105 const base::Closure& retry_task) OVERRIDE; |
| 106 virtual void AddObserver(SyncManager::Observer* observer) OVERRIDE; | 106 virtual void AddObserver(SyncManager::Observer* observer) OVERRIDE; |
| 107 virtual void RemoveObserver(SyncManager::Observer* observer) OVERRIDE; | 107 virtual void RemoveObserver(SyncManager::Observer* observer) OVERRIDE; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 virtual ModelTypeSet HandleTransactionEndingChangeEvent( | 160 virtual ModelTypeSet HandleTransactionEndingChangeEvent( |
| 161 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, | 161 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 162 syncable::BaseTransaction* trans) OVERRIDE; | 162 syncable::BaseTransaction* trans) OVERRIDE; |
| 163 virtual void HandleCalculateChangesChangeEventFromSyncApi( | 163 virtual void HandleCalculateChangesChangeEventFromSyncApi( |
| 164 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, | 164 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 165 syncable::BaseTransaction* trans) OVERRIDE; | 165 syncable::BaseTransaction* trans) OVERRIDE; |
| 166 virtual void HandleCalculateChangesChangeEventFromSyncer( | 166 virtual void HandleCalculateChangesChangeEventFromSyncer( |
| 167 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, | 167 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 168 syncable::BaseTransaction* trans) OVERRIDE; | 168 syncable::BaseTransaction* trans) OVERRIDE; |
| 169 | 169 |
| 170 // SyncNotifierObserver implementation. | 170 // InvalidationHandler implementation. |
| 171 virtual void OnNotificationsEnabled() OVERRIDE; | 171 virtual void OnNotificationsEnabled() OVERRIDE; |
| 172 virtual void OnNotificationsDisabled( | 172 virtual void OnNotificationsDisabled( |
| 173 NotificationsDisabledReason reason) OVERRIDE; | 173 NotificationsDisabledReason reason) OVERRIDE; |
| 174 virtual void OnIncomingNotification( | 174 virtual void OnIncomingNotification( |
| 175 const ObjectIdStateMap& id_state_map, | 175 const ObjectIdStateMap& id_state_map, |
| 176 IncomingNotificationSource source) OVERRIDE; | 176 IncomingNotificationSource source) OVERRIDE; |
| 177 | 177 |
| 178 // Called only by our NetworkChangeNotifier. | 178 // Called only by our NetworkChangeNotifier. |
| 179 virtual void OnIPAddressChanged() OVERRIDE; | 179 virtual void OnIPAddressChanged() OVERRIDE; |
| 180 | 180 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 scoped_ptr<SyncAPIServerConnectionManager> connection_manager_; | 325 scoped_ptr<SyncAPIServerConnectionManager> connection_manager_; |
| 326 | 326 |
| 327 // A container of various bits of information used by the SyncScheduler to | 327 // A container of various bits of information used by the SyncScheduler to |
| 328 // create SyncSessions. Must outlive the SyncScheduler. | 328 // create SyncSessions. Must outlive the SyncScheduler. |
| 329 scoped_ptr<sessions::SyncSessionContext> session_context_; | 329 scoped_ptr<sessions::SyncSessionContext> session_context_; |
| 330 | 330 |
| 331 // The scheduler that runs the Syncer. Needs to be explicitly | 331 // The scheduler that runs the Syncer. Needs to be explicitly |
| 332 // Start()ed. | 332 // Start()ed. |
| 333 scoped_ptr<SyncScheduler> scheduler_; | 333 scoped_ptr<SyncScheduler> scheduler_; |
| 334 | 334 |
| 335 // The SyncNotifier which notifies us when updates need to be downloaded. | 335 // The Invalidator which notifies us when updates need to be downloaded. |
| 336 scoped_ptr<SyncNotifier> sync_notifier_; | 336 scoped_ptr<Invalidator> invalidator_; |
| 337 | 337 |
| 338 // A multi-purpose status watch object that aggregates stats from various | 338 // A multi-purpose status watch object that aggregates stats from various |
| 339 // sync components. | 339 // sync components. |
| 340 AllStatus allstatus_; | 340 AllStatus allstatus_; |
| 341 | 341 |
| 342 // Each element of this array is a store of change records produced by | 342 // Each element of this array is a store of change records produced by |
| 343 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are | 343 // HandleChangeEvent during the CALCULATE_CHANGES step. The changes are |
| 344 // segregated by model type, and are stored here to be processed and | 344 // segregated by model type, and are stored here to be processed and |
| 345 // forwarded to the observer slightly later, at the TRANSACTION_ENDING | 345 // forwarded to the observer slightly later, at the TRANSACTION_ENDING |
| 346 // step by HandleTransactionEndingChangeEvent. The list is cleared in the | 346 // step by HandleTransactionEndingChangeEvent. The list is cleared in the |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // changing passphrases, and in general handles sync-specific interactions | 382 // changing passphrases, and in general handles sync-specific interactions |
| 383 // with the cryptographer. | 383 // with the cryptographer. |
| 384 scoped_ptr<SyncEncryptionHandlerImpl> sync_encryption_handler_; | 384 scoped_ptr<SyncEncryptionHandlerImpl> sync_encryption_handler_; |
| 385 | 385 |
| 386 DISALLOW_COPY_AND_ASSIGN(SyncManagerImpl); | 386 DISALLOW_COPY_AND_ASSIGN(SyncManagerImpl); |
| 387 }; | 387 }; |
| 388 | 388 |
| 389 } // namespace syncer | 389 } // namespace syncer |
| 390 | 390 |
| 391 #endif // SYNC_INTERNAL_API_SYNC_MANAGER_H_ | 391 #endif // SYNC_INTERNAL_API_SYNC_MANAGER_H_ |
| OLD | NEW |