| 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 #ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "sync/base/sync_export.h" | 17 #include "sync/base/sync_export.h" |
| 18 #include "sync/internal_api/public/base/model_type.h" | 18 #include "sync/internal_api/public/base/model_type.h" |
| 19 #include "sync/internal_api/public/change_record.h" | 19 #include "sync/internal_api/public/change_record.h" |
| 20 #include "sync/internal_api/public/configure_reason.h" | 20 #include "sync/internal_api/public/configure_reason.h" |
| 21 #include "sync/internal_api/public/engine/model_safe_worker.h" | 21 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 22 #include "sync/internal_api/public/engine/sync_status.h" | 22 #include "sync/internal_api/public/engine/sync_status.h" |
| 23 #include "sync/internal_api/public/sync_encryption_handler.h" | 23 #include "sync/internal_api/public/sync_encryption_handler.h" |
| 24 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" | 24 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" |
| 25 #include "sync/internal_api/public/util/weak_handle.h" | 25 #include "sync/internal_api/public/util/weak_handle.h" |
| 26 #include "sync/notifier/invalidation_handler.h" | 26 #include "sync/notifier/invalidation_util.h" |
| 27 #include "sync/protocol/sync_protocol_error.h" | 27 #include "sync/protocol/sync_protocol_error.h" |
| 28 | 28 |
| 29 namespace sync_pb { | 29 namespace sync_pb { |
| 30 class EncryptedData; | 30 class EncryptedData; |
| 31 } // namespace sync_pb | 31 } // namespace sync_pb |
| 32 | 32 |
| 33 namespace syncer { | 33 namespace syncer { |
| 34 | 34 |
| 35 class BaseTransaction; | 35 class BaseTransaction; |
| 36 class DataTypeDebugInfoListener; | 36 class DataTypeDebugInfoListener; |
| 37 class Encryptor; | 37 class Encryptor; |
| 38 struct Experiments; | 38 struct Experiments; |
| 39 class ExtensionsActivityMonitor; | 39 class ExtensionsActivityMonitor; |
| 40 class HttpPostProviderFactory; | 40 class HttpPostProviderFactory; |
| 41 class InternalComponentsFactory; | 41 class InternalComponentsFactory; |
| 42 class InvalidationHandler; |
| 43 class Invalidator; |
| 42 class JsBackend; | 44 class JsBackend; |
| 43 class JsEventHandler; | 45 class JsEventHandler; |
| 44 class SyncEncryptionHandler; | 46 class SyncEncryptionHandler; |
| 45 class SyncScheduler; | 47 class SyncScheduler; |
| 46 class UnrecoverableErrorHandler; | 48 class UnrecoverableErrorHandler; |
| 47 struct UserShare; | 49 struct UserShare; |
| 48 | 50 |
| 49 namespace sessions { | 51 namespace sessions { |
| 50 class SyncSessionSnapshot; | 52 class SyncSessionSnapshot; |
| 51 } // namespace sessions | 53 } // namespace sessions |
| (...skipping 14 matching lines...) Expand all Loading... |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 // SyncManager encapsulates syncable::Directory and serves as the parent of all | 70 // SyncManager encapsulates syncable::Directory and serves as the parent of all |
| 69 // other objects in the sync API. If multiple threads interact with the same | 71 // other objects in the sync API. If multiple threads interact with the same |
| 70 // local sync repository (i.e. the same sqlite database), they should share a | 72 // local sync repository (i.e. the same sqlite database), they should share a |
| 71 // single SyncManager instance. The caller should typically create one | 73 // single SyncManager instance. The caller should typically create one |
| 72 // SyncManager for the lifetime of a user session. | 74 // SyncManager for the lifetime of a user session. |
| 73 // | 75 // |
| 74 // Unless stated otherwise, all methods of SyncManager should be called on the | 76 // Unless stated otherwise, all methods of SyncManager should be called on the |
| 75 // same thread. | 77 // same thread. |
| 76 class SYNC_EXPORT SyncManager : public syncer::InvalidationHandler { | 78 class SYNC_EXPORT SyncManager { |
| 77 public: | 79 public: |
| 78 // An interface the embedding application implements to be notified | 80 // An interface the embedding application implements to be notified |
| 79 // on change events. Note that these methods may be called on *any* | 81 // on change events. Note that these methods may be called on *any* |
| 80 // thread. | 82 // thread. |
| 81 class SYNC_EXPORT ChangeDelegate { | 83 class SYNC_EXPORT ChangeDelegate { |
| 82 public: | 84 public: |
| 83 // Notify the delegate that changes have been applied to the sync model. | 85 // Notify the delegate that changes have been applied to the sync model. |
| 84 // | 86 // |
| 85 // This will be invoked on the same thread as on which ApplyChanges was | 87 // This will be invoked on the same thread as on which ApplyChanges was |
| 86 // called. |changes| is an array of size |change_count|, and contains the | 88 // called. |changes| is an array of size |change_count|, and contains the |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 const base::FilePath& database_location, | 308 const base::FilePath& database_location, |
| 307 const WeakHandle<JsEventHandler>& event_handler, | 309 const WeakHandle<JsEventHandler>& event_handler, |
| 308 const std::string& sync_server_and_path, | 310 const std::string& sync_server_and_path, |
| 309 int sync_server_port, | 311 int sync_server_port, |
| 310 bool use_ssl, | 312 bool use_ssl, |
| 311 scoped_ptr<HttpPostProviderFactory> post_factory, | 313 scoped_ptr<HttpPostProviderFactory> post_factory, |
| 312 const std::vector<ModelSafeWorker*>& workers, | 314 const std::vector<ModelSafeWorker*>& workers, |
| 313 ExtensionsActivityMonitor* extensions_activity_monitor, | 315 ExtensionsActivityMonitor* extensions_activity_monitor, |
| 314 ChangeDelegate* change_delegate, | 316 ChangeDelegate* change_delegate, |
| 315 const SyncCredentials& credentials, | 317 const SyncCredentials& credentials, |
| 318 scoped_ptr<Invalidator> invalidator, |
| 316 const std::string& invalidator_client_id, | 319 const std::string& invalidator_client_id, |
| 317 const std::string& restored_key_for_bootstrapping, | 320 const std::string& restored_key_for_bootstrapping, |
| 318 const std::string& restored_keystore_key_for_bootstrapping, | 321 const std::string& restored_keystore_key_for_bootstrapping, |
| 319 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 322 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
| 320 Encryptor* encryptor, | 323 Encryptor* encryptor, |
| 321 UnrecoverableErrorHandler* unrecoverable_error_handler, | 324 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 322 ReportUnrecoverableErrorFunction report_unrecoverable_error_function, | 325 ReportUnrecoverableErrorFunction report_unrecoverable_error_function, |
| 323 bool use_oauth2_token) = 0; | 326 bool use_oauth2_token) = 0; |
| 324 | 327 |
| 325 // Throw an unrecoverable error from a transaction (mostly used for | 328 // Throw an unrecoverable error from a transaction (mostly used for |
| 326 // testing). | 329 // testing). |
| 327 virtual void ThrowUnrecoverableError() = 0; | 330 virtual void ThrowUnrecoverableError() = 0; |
| 328 | 331 |
| 329 virtual ModelTypeSet InitialSyncEndedTypes() = 0; | 332 virtual ModelTypeSet InitialSyncEndedTypes() = 0; |
| 330 | 333 |
| 331 // Returns those types within |types| that have an empty progress marker | 334 // Returns those types within |types| that have an empty progress marker |
| 332 // token. | 335 // token. |
| 333 virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken( | 336 virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken( |
| 334 ModelTypeSet types) = 0; | 337 ModelTypeSet types) = 0; |
| 335 | 338 |
| 336 // Purge from the directory those types with non-empty progress markers | 339 // Purge from the directory those types with non-empty progress markers |
| 337 // but without initial synced ended set. | 340 // but without initial synced ended set. |
| 338 // Returns false if an error occurred, true otherwise. | 341 // Returns false if an error occurred, true otherwise. |
| 339 virtual bool PurgePartiallySyncedTypes() = 0; | 342 virtual bool PurgePartiallySyncedTypes() = 0; |
| 340 | 343 |
| 341 // Update tokens that we're using in Sync. Email must stay the same. | 344 // Update tokens that we're using in Sync. Email must stay the same. |
| 342 virtual void UpdateCredentials(const SyncCredentials& credentials) = 0; | 345 virtual void UpdateCredentials(const SyncCredentials& credentials) = 0; |
| 343 | 346 |
| 347 // Called when the user disables or enables a sync type. |
| 348 virtual void UpdateEnabledTypes(ModelTypeSet enabled_types) = 0; |
| 349 |
| 350 // Forwards to the underlying invalidator (see comments in invalidator.h). |
| 351 virtual void RegisterInvalidationHandler( |
| 352 InvalidationHandler* handler) = 0; |
| 353 |
| 354 // Forwards to the underlying notifier (see comments in invalidator.h). |
| 355 virtual void UpdateRegisteredInvalidationIds( |
| 356 InvalidationHandler* handler, |
| 357 const ObjectIdSet& ids) = 0; |
| 358 |
| 359 // Forwards to the underlying notifier (see comments in invalidator.h). |
| 360 virtual void UnregisterInvalidationHandler( |
| 361 InvalidationHandler* handler) = 0; |
| 362 |
| 363 // Forwards to the underlying notifier (see comments in invalidator.h). |
| 364 virtual void AcknowledgeInvalidation( |
| 365 const invalidation::ObjectId& id, |
| 366 const syncer::AckHandle& ack_handle) = 0; |
| 367 |
| 344 // Put the syncer in normal mode ready to perform nudges and polls. | 368 // Put the syncer in normal mode ready to perform nudges and polls. |
| 345 virtual void StartSyncingNormally( | 369 virtual void StartSyncingNormally( |
| 346 const ModelSafeRoutingInfo& routing_info) = 0; | 370 const ModelSafeRoutingInfo& routing_info) = 0; |
| 347 | 371 |
| 348 // Switches the mode of operation to CONFIGURATION_MODE and performs | 372 // Switches the mode of operation to CONFIGURATION_MODE and performs |
| 349 // any configuration tasks needed as determined by the params. Once complete, | 373 // any configuration tasks needed as determined by the params. Once complete, |
| 350 // syncer will remain in CONFIGURATION_MODE until StartSyncingNormally is | 374 // syncer will remain in CONFIGURATION_MODE until StartSyncingNormally is |
| 351 // called. | 375 // called. |
| 352 // Data whose types are not in |new_routing_info| are purged from sync | 376 // Data whose types are not in |new_routing_info| are purged from sync |
| 353 // directory, unless they're part of |to_ignore|, in which case they're left | 377 // directory, unless they're part of |to_ignore|, in which case they're left |
| 354 // untouched. The purged data is backed up in delete journal for recovery in | 378 // untouched. The purged data is backed up in delete journal for recovery in |
| 355 // next session if its type is in |to_journal|. If in |to_unapply| | 379 // next session if its type is in |to_journal|. If in |to_unapply| |
| 356 // only the local data is removed; the server data is preserved. | 380 // only the local data is removed; the server data is preserved. |
| 357 // |ready_task| is invoked when the configuration completes. | 381 // |ready_task| is invoked when the configuration completes. |
| 358 // |retry_task| is invoked if the configuration job could not immediately | 382 // |retry_task| is invoked if the configuration job could not immediately |
| 359 // execute. |ready_task| will still be called when it eventually | 383 // execute. |ready_task| will still be called when it eventually |
| 360 // does finish. | 384 // does finish. |
| 361 virtual void ConfigureSyncer( | 385 virtual void ConfigureSyncer( |
| 362 ConfigureReason reason, | 386 ConfigureReason reason, |
| 363 ModelTypeSet to_download, | 387 ModelTypeSet to_download, |
| 364 ModelTypeSet to_purge, | 388 ModelTypeSet to_purge, |
| 365 ModelTypeSet to_journal, | 389 ModelTypeSet to_journal, |
| 366 ModelTypeSet to_unapply, | 390 ModelTypeSet to_unapply, |
| 367 const ModelSafeRoutingInfo& new_routing_info, | 391 const ModelSafeRoutingInfo& new_routing_info, |
| 368 const base::Closure& ready_task, | 392 const base::Closure& ready_task, |
| 369 const base::Closure& retry_task) = 0; | 393 const base::Closure& retry_task) = 0; |
| 370 | 394 |
| 371 // Inform the syncer of a change in the invalidator's state. | |
| 372 virtual void OnInvalidatorStateChange(InvalidatorState state) = 0; | |
| 373 | |
| 374 // Inform the syncer that its cached information about a type is obsolete. | |
| 375 virtual void OnIncomingInvalidation( | |
| 376 const ObjectIdInvalidationMap& invalidation_map) = 0; | |
| 377 | |
| 378 // Adds a listener to be notified of sync events. | 395 // Adds a listener to be notified of sync events. |
| 379 // NOTE: It is OK (in fact, it's probably a good idea) to call this before | 396 // NOTE: It is OK (in fact, it's probably a good idea) to call this before |
| 380 // having received OnInitializationCompleted. | 397 // having received OnInitializationCompleted. |
| 381 virtual void AddObserver(Observer* observer) = 0; | 398 virtual void AddObserver(Observer* observer) = 0; |
| 382 | 399 |
| 383 // Remove the given observer. Make sure to call this if the | 400 // Remove the given observer. Make sure to call this if the |
| 384 // Observer is being destroyed so the SyncManager doesn't | 401 // Observer is being destroyed so the SyncManager doesn't |
| 385 // potentially dereference garbage. | 402 // potentially dereference garbage. |
| 386 virtual void RemoveObserver(Observer* observer) = 0; | 403 virtual void RemoveObserver(Observer* observer) = 0; |
| 387 | 404 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 // Returns the SyncManager's encryption handler. | 442 // Returns the SyncManager's encryption handler. |
| 426 virtual SyncEncryptionHandler* GetEncryptionHandler() = 0; | 443 virtual SyncEncryptionHandler* GetEncryptionHandler() = 0; |
| 427 | 444 |
| 428 // Ask the SyncManager to fetch updates for the given types. | 445 // Ask the SyncManager to fetch updates for the given types. |
| 429 virtual void RefreshTypes(ModelTypeSet types) = 0; | 446 virtual void RefreshTypes(ModelTypeSet types) = 0; |
| 430 }; | 447 }; |
| 431 | 448 |
| 432 } // namespace syncer | 449 } // namespace syncer |
| 433 | 450 |
| 434 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ | 451 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ |
| OLD | NEW |