| 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_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/file_path.h" | 13 #include "base/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 "base/time.h" | 17 #include "base/time.h" |
| 18 #include "sync/internal_api/public/change_record.h" | 18 #include "sync/internal_api/public/change_record.h" |
| 19 #include "sync/internal_api/public/configure_reason.h" | 19 #include "sync/internal_api/public/configure_reason.h" |
| 20 #include "sync/internal_api/public/engine/model_safe_worker.h" | 20 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 21 #include "sync/internal_api/public/engine/sync_status.h" | 21 #include "sync/internal_api/public/engine/sync_status.h" |
| 22 #include "sync/internal_api/public/syncable/model_type.h" | 22 #include "sync/internal_api/public/syncable/model_type.h" |
| 23 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" | 23 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" |
| 24 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" | 24 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" |
| 25 #include "sync/internal_api/public/util/weak_handle.h" | 25 #include "sync/internal_api/public/util/weak_handle.h" |
| 26 #include "sync/protocol/sync_protocol_error.h" | 26 #include "sync/protocol/sync_protocol_error.h" |
| 27 | 27 |
| 28 namespace csync { | 28 namespace syncer { |
| 29 class Encryptor; | 29 class Encryptor; |
| 30 struct Experiments; | 30 struct Experiments; |
| 31 class ExtensionsActivityMonitor; | 31 class ExtensionsActivityMonitor; |
| 32 class JsBackend; | 32 class JsBackend; |
| 33 class JsEventHandler; | 33 class JsEventHandler; |
| 34 | 34 |
| 35 namespace sessions { | 35 namespace sessions { |
| 36 class SyncSessionSnapshot; | 36 class SyncSessionSnapshot; |
| 37 } // namespace sessions | 37 } // namespace sessions |
| 38 } // namespace csync | 38 } // namespace syncer |
| 39 | 39 |
| 40 namespace csync { | 40 namespace syncer { |
| 41 class SyncNotifier; | 41 class SyncNotifier; |
| 42 } // namespace csync | 42 } // namespace syncer |
| 43 | 43 |
| 44 namespace sync_pb { | 44 namespace sync_pb { |
| 45 class EncryptedData; | 45 class EncryptedData; |
| 46 } // namespace sync_pb | 46 } // namespace sync_pb |
| 47 | 47 |
| 48 namespace csync { | 48 namespace syncer { |
| 49 | 49 |
| 50 class BaseTransaction; | 50 class BaseTransaction; |
| 51 class HttpPostProviderFactory; | 51 class HttpPostProviderFactory; |
| 52 struct UserShare; | 52 struct UserShare; |
| 53 | 53 |
| 54 // Used by SyncManager::OnConnectionStatusChange(). | 54 // Used by SyncManager::OnConnectionStatusChange(). |
| 55 enum ConnectionStatus { | 55 enum ConnectionStatus { |
| 56 CONNECTION_OK, | 56 CONNECTION_OK, |
| 57 CONNECTION_AUTH_ERROR, | 57 CONNECTION_AUTH_ERROR, |
| 58 CONNECTION_SERVER_ERROR | 58 CONNECTION_SERVER_ERROR |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Reasons due to which csync::Cryptographer might require a passphrase. | 61 // Reasons due to which syncer::Cryptographer might require a passphrase. |
| 62 enum PassphraseRequiredReason { | 62 enum PassphraseRequiredReason { |
| 63 REASON_PASSPHRASE_NOT_REQUIRED = 0, // Initial value. | 63 REASON_PASSPHRASE_NOT_REQUIRED = 0, // Initial value. |
| 64 REASON_ENCRYPTION = 1, // The cryptographer requires a | 64 REASON_ENCRYPTION = 1, // The cryptographer requires a |
| 65 // passphrase for its first attempt at | 65 // passphrase for its first attempt at |
| 66 // encryption. Happens only during | 66 // encryption. Happens only during |
| 67 // migration or upgrade. | 67 // migration or upgrade. |
| 68 REASON_DECRYPTION = 2, // The cryptographer requires a | 68 REASON_DECRYPTION = 2, // The cryptographer requires a |
| 69 // passphrase for its first attempt at | 69 // passphrase for its first attempt at |
| 70 // decryption. | 70 // decryption. |
| 71 }; | 71 }; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 // An interface the embedding application implements to receive | 178 // An interface the embedding application implements to receive |
| 179 // notifications from the SyncManager. Register an observer via | 179 // notifications from the SyncManager. Register an observer via |
| 180 // SyncManager::AddObserver. All methods are called only on the | 180 // SyncManager::AddObserver. All methods are called only on the |
| 181 // sync thread. | 181 // sync thread. |
| 182 class Observer { | 182 class Observer { |
| 183 public: | 183 public: |
| 184 // A round-trip sync-cycle took place and the syncer has resolved any | 184 // A round-trip sync-cycle took place and the syncer has resolved any |
| 185 // conflicts that may have arisen. | 185 // conflicts that may have arisen. |
| 186 virtual void OnSyncCycleCompleted( | 186 virtual void OnSyncCycleCompleted( |
| 187 const csync::sessions::SyncSessionSnapshot& snapshot) = 0; | 187 const syncer::sessions::SyncSessionSnapshot& snapshot) = 0; |
| 188 | 188 |
| 189 // Called when the status of the connection to the sync server has | 189 // Called when the status of the connection to the sync server has |
| 190 // changed. | 190 // changed. |
| 191 virtual void OnConnectionStatusChange(ConnectionStatus status) = 0; | 191 virtual void OnConnectionStatusChange(ConnectionStatus status) = 0; |
| 192 | 192 |
| 193 // Called when a new auth token is provided by the sync server. | 193 // Called when a new auth token is provided by the sync server. |
| 194 virtual void OnUpdatedToken(const std::string& token) = 0; | 194 virtual void OnUpdatedToken(const std::string& token) = 0; |
| 195 | 195 |
| 196 // Called when user interaction is required to obtain a valid passphrase. | 196 // Called when user interaction is required to obtain a valid passphrase. |
| 197 // - If the passphrase is required for encryption, |reason| will be | 197 // - If the passphrase is required for encryption, |reason| will be |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 * Gets child ids for a given id. | 293 * Gets child ids for a given id. |
| 294 * | 294 * |
| 295 * @param {string} id 64-bit id in decimal string form of the parent | 295 * @param {string} id 64-bit id in decimal string form of the parent |
| 296 * node. | 296 * node. |
| 297 * @param {Array.<string>} callback Called with the (possibly empty) | 297 * @param {Array.<string>} callback Called with the (possibly empty) |
| 298 * list of child ids. | 298 * list of child ids. |
| 299 */ | 299 */ |
| 300 // function getChildNodeIds(id); | 300 // function getChildNodeIds(id); |
| 301 | 301 |
| 302 virtual void OnInitializationComplete( | 302 virtual void OnInitializationComplete( |
| 303 const csync::WeakHandle<csync::JsBackend>& | 303 const syncer::WeakHandle<syncer::JsBackend>& |
| 304 js_backend, bool success) = 0; | 304 js_backend, bool success) = 0; |
| 305 | 305 |
| 306 // We are no longer permitted to communicate with the server. Sync should | 306 // We are no longer permitted to communicate with the server. Sync should |
| 307 // be disabled and state cleaned up at once. This can happen for a number | 307 // be disabled and state cleaned up at once. This can happen for a number |
| 308 // of reasons, e.g. swapping from a test instance to production, or a | 308 // of reasons, e.g. swapping from a test instance to production, or a |
| 309 // global stop syncing operation has wiped the store. | 309 // global stop syncing operation has wiped the store. |
| 310 virtual void OnStopSyncingPermanently() = 0; | 310 virtual void OnStopSyncingPermanently() = 0; |
| 311 | 311 |
| 312 // Called when the set of encrypted types or the encrypt | 312 // Called when the set of encrypted types or the encrypt |
| 313 // everything flag has been changed. Note that encryption isn't | 313 // everything flag has been changed. Note that encryption isn't |
| (...skipping 13 matching lines...) Expand all Loading... |
| 327 syncable::ModelTypeSet encrypted_types, | 327 syncable::ModelTypeSet encrypted_types, |
| 328 bool encrypt_everything) = 0; | 328 bool encrypt_everything) = 0; |
| 329 | 329 |
| 330 // Called after we finish encrypting the current set of encrypted | 330 // Called after we finish encrypting the current set of encrypted |
| 331 // types. | 331 // types. |
| 332 // | 332 // |
| 333 // Called from within a transaction. | 333 // Called from within a transaction. |
| 334 virtual void OnEncryptionComplete() = 0; | 334 virtual void OnEncryptionComplete() = 0; |
| 335 | 335 |
| 336 virtual void OnActionableError( | 336 virtual void OnActionableError( |
| 337 const csync::SyncProtocolError& sync_protocol_error) = 0; | 337 const syncer::SyncProtocolError& sync_protocol_error) = 0; |
| 338 | 338 |
| 339 protected: | 339 protected: |
| 340 virtual ~Observer(); | 340 virtual ~Observer(); |
| 341 }; | 341 }; |
| 342 | 342 |
| 343 enum TestingMode { | 343 enum TestingMode { |
| 344 NON_TEST, | 344 NON_TEST, |
| 345 TEST_ON_DISK, | 345 TEST_ON_DISK, |
| 346 TEST_IN_MEMORY, | 346 TEST_IN_MEMORY, |
| 347 }; | 347 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 365 // instances of an HttpPostProvider. | 365 // instances of an HttpPostProvider. |
| 366 // |model_safe_worker| ownership is given to the SyncManager. | 366 // |model_safe_worker| ownership is given to the SyncManager. |
| 367 // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent | 367 // |user_agent| is a 7-bit ASCII string suitable for use as the User-Agent |
| 368 // HTTP header. Used internally when collecting stats to classify clients. | 368 // HTTP header. Used internally when collecting stats to classify clients. |
| 369 // |sync_notifier| is owned and used to listen for notifications. | 369 // |sync_notifier| is owned and used to listen for notifications. |
| 370 // |report_unrecoverable_error_function| may be NULL. | 370 // |report_unrecoverable_error_function| may be NULL. |
| 371 // | 371 // |
| 372 // TODO(akalin): Replace the |post_factory| parameter with a | 372 // TODO(akalin): Replace the |post_factory| parameter with a |
| 373 // URLFetcher parameter. | 373 // URLFetcher parameter. |
| 374 bool Init(const FilePath& database_location, | 374 bool Init(const FilePath& database_location, |
| 375 const csync::WeakHandle<csync::JsEventHandler>& | 375 const syncer::WeakHandle<syncer::JsEventHandler>& |
| 376 event_handler, | 376 event_handler, |
| 377 const std::string& sync_server_and_path, | 377 const std::string& sync_server_and_path, |
| 378 int sync_server_port, | 378 int sync_server_port, |
| 379 bool use_ssl, | 379 bool use_ssl, |
| 380 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 380 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 381 HttpPostProviderFactory* post_factory, | 381 HttpPostProviderFactory* post_factory, |
| 382 const csync::ModelSafeRoutingInfo& model_safe_routing_info, | 382 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, |
| 383 const std::vector<csync::ModelSafeWorker*>& workers, | 383 const std::vector<syncer::ModelSafeWorker*>& workers, |
| 384 csync::ExtensionsActivityMonitor* | 384 syncer::ExtensionsActivityMonitor* |
| 385 extensions_activity_monitor, | 385 extensions_activity_monitor, |
| 386 ChangeDelegate* change_delegate, | 386 ChangeDelegate* change_delegate, |
| 387 const SyncCredentials& credentials, | 387 const SyncCredentials& credentials, |
| 388 csync::SyncNotifier* sync_notifier, | 388 syncer::SyncNotifier* sync_notifier, |
| 389 const std::string& restored_key_for_bootstrapping, | 389 const std::string& restored_key_for_bootstrapping, |
| 390 TestingMode testing_mode, | 390 TestingMode testing_mode, |
| 391 csync::Encryptor* encryptor, | 391 syncer::Encryptor* encryptor, |
| 392 csync::UnrecoverableErrorHandler* | 392 syncer::UnrecoverableErrorHandler* |
| 393 unrecoverable_error_handler, | 393 unrecoverable_error_handler, |
| 394 csync::ReportUnrecoverableErrorFunction | 394 syncer::ReportUnrecoverableErrorFunction |
| 395 report_unrecoverable_error_function); | 395 report_unrecoverable_error_function); |
| 396 | 396 |
| 397 // Throw an unrecoverable error from a transaction (mostly used for | 397 // Throw an unrecoverable error from a transaction (mostly used for |
| 398 // testing). | 398 // testing). |
| 399 void ThrowUnrecoverableError(); | 399 void ThrowUnrecoverableError(); |
| 400 | 400 |
| 401 // Returns the set of types for which we have stored some sync data. | 401 // Returns the set of types for which we have stored some sync data. |
| 402 syncable::ModelTypeSet InitialSyncEndedTypes(); | 402 syncable::ModelTypeSet InitialSyncEndedTypes(); |
| 403 | 403 |
| 404 // Update tokens that we're using in Sync. Email must stay the same. | 404 // Update tokens that we're using in Sync. Email must stay the same. |
| 405 void UpdateCredentials(const SyncCredentials& credentials); | 405 void UpdateCredentials(const SyncCredentials& credentials); |
| 406 | 406 |
| 407 // Called when the user disables or enables a sync type. | 407 // Called when the user disables or enables a sync type. |
| 408 void UpdateEnabledTypes(const syncable::ModelTypeSet& enabled_types); | 408 void UpdateEnabledTypes(const syncable::ModelTypeSet& enabled_types); |
| 409 | 409 |
| 410 // Put the syncer in normal mode ready to perform nudges and polls. | 410 // Put the syncer in normal mode ready to perform nudges and polls. |
| 411 void StartSyncingNormally( | 411 void StartSyncingNormally( |
| 412 const csync::ModelSafeRoutingInfo& routing_info); | 412 const syncer::ModelSafeRoutingInfo& routing_info); |
| 413 | 413 |
| 414 // Attempts to re-encrypt encrypted data types using the passphrase provided. | 414 // Attempts to re-encrypt encrypted data types using the passphrase provided. |
| 415 // Notifies observers of the result of the operation via OnPassphraseAccepted | 415 // Notifies observers of the result of the operation via OnPassphraseAccepted |
| 416 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as | 416 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as |
| 417 // appropriate. If an explicit password has been set previously, we drop | 417 // appropriate. If an explicit password has been set previously, we drop |
| 418 // subsequent requests to set a passphrase. If the cryptographer has pending | 418 // subsequent requests to set a passphrase. If the cryptographer has pending |
| 419 // keys, and a new implicit passphrase is provided, we try decrypting the | 419 // keys, and a new implicit passphrase is provided, we try decrypting the |
| 420 // pending keys with it, and if that fails, we cache the passphrase for | 420 // pending keys with it, and if that fails, we cache the passphrase for |
| 421 // re-encryption once the pending keys are decrypted. | 421 // re-encryption once the pending keys are decrypted. |
| 422 void SetEncryptionPassphrase(const std::string& passphrase, bool is_explicit); | 422 void SetEncryptionPassphrase(const std::string& passphrase, bool is_explicit); |
| 423 | 423 |
| 424 // Provides a passphrase for decrypting the user's existing sync data. | 424 // Provides a passphrase for decrypting the user's existing sync data. |
| 425 // Notifies observers of the result of the operation via OnPassphraseAccepted | 425 // Notifies observers of the result of the operation via OnPassphraseAccepted |
| 426 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as | 426 // or OnPassphraseRequired, updates the nigori node, and does re-encryption as |
| 427 // appropriate if there is a previously cached encryption passphrase. It is an | 427 // appropriate if there is a previously cached encryption passphrase. It is an |
| 428 // error to call this when we don't have pending keys. | 428 // error to call this when we don't have pending keys. |
| 429 void SetDecryptionPassphrase(const std::string& passphrase); | 429 void SetDecryptionPassphrase(const std::string& passphrase); |
| 430 | 430 |
| 431 // Puts the SyncScheduler into a mode where no normal nudge or poll traffic | 431 // Puts the SyncScheduler into a mode where no normal nudge or poll traffic |
| 432 // will occur, but calls to RequestConfig will be supported. If |callback| | 432 // will occur, but calls to RequestConfig will be supported. If |callback| |
| 433 // is provided, it will be invoked (from the internal SyncScheduler) when | 433 // is provided, it will be invoked (from the internal SyncScheduler) when |
| 434 // the thread has changed to configuration mode. | 434 // the thread has changed to configuration mode. |
| 435 void StartConfigurationMode(const base::Closure& callback); | 435 void StartConfigurationMode(const base::Closure& callback); |
| 436 | 436 |
| 437 // Switches the mode of operation to CONFIGURATION_MODE and | 437 // Switches the mode of operation to CONFIGURATION_MODE and |
| 438 // schedules a config task to fetch updates for |types|. | 438 // schedules a config task to fetch updates for |types|. |
| 439 void RequestConfig(const csync::ModelSafeRoutingInfo& routing_info, | 439 void RequestConfig(const syncer::ModelSafeRoutingInfo& routing_info, |
| 440 const syncable::ModelTypeSet& types, | 440 const syncable::ModelTypeSet& types, |
| 441 csync::ConfigureReason reason); | 441 syncer::ConfigureReason reason); |
| 442 | 442 |
| 443 void RequestCleanupDisabledTypes( | 443 void RequestCleanupDisabledTypes( |
| 444 const csync::ModelSafeRoutingInfo& routing_info); | 444 const syncer::ModelSafeRoutingInfo& routing_info); |
| 445 | 445 |
| 446 // Adds a listener to be notified of sync events. | 446 // Adds a listener to be notified of sync events. |
| 447 // NOTE: It is OK (in fact, it's probably a good idea) to call this before | 447 // NOTE: It is OK (in fact, it's probably a good idea) to call this before |
| 448 // having received OnInitializationCompleted. | 448 // having received OnInitializationCompleted. |
| 449 void AddObserver(Observer* observer); | 449 void AddObserver(Observer* observer); |
| 450 | 450 |
| 451 // Remove the given observer. Make sure to call this if the | 451 // Remove the given observer. Make sure to call this if the |
| 452 // Observer is being destroyed so the SyncManager doesn't | 452 // Observer is being destroyed so the SyncManager doesn't |
| 453 // potentially dereference garbage. | 453 // potentially dereference garbage. |
| 454 void RemoveObserver(Observer* observer); | 454 void RemoveObserver(Observer* observer); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // be called on any thread. | 509 // be called on any thread. |
| 510 bool EncryptEverythingEnabledForTest() const; | 510 bool EncryptEverythingEnabledForTest() const; |
| 511 | 511 |
| 512 // Gets the set of encrypted types from the cryptographer | 512 // Gets the set of encrypted types from the cryptographer |
| 513 // Note: opens a transaction. May be called from any thread. | 513 // Note: opens a transaction. May be called from any thread. |
| 514 syncable::ModelTypeSet GetEncryptedDataTypesForTest() const; | 514 syncable::ModelTypeSet GetEncryptedDataTypesForTest() const; |
| 515 | 515 |
| 516 // Reads the nigori node to determine if any experimental features should | 516 // Reads the nigori node to determine if any experimental features should |
| 517 // be enabled. | 517 // be enabled. |
| 518 // Note: opens a transaction. May be called on any thread. | 518 // Note: opens a transaction. May be called on any thread. |
| 519 bool ReceivedExperiment(csync::Experiments* experiments) const; | 519 bool ReceivedExperiment(syncer::Experiments* experiments) const; |
| 520 | 520 |
| 521 // Uses a read-only transaction to determine if the directory being synced has | 521 // Uses a read-only transaction to determine if the directory being synced has |
| 522 // any remaining unsynced items. May be called on any thread. | 522 // any remaining unsynced items. May be called on any thread. |
| 523 bool HasUnsyncedItems() const; | 523 bool HasUnsyncedItems() const; |
| 524 | 524 |
| 525 // Functions used for testing. | 525 // Functions used for testing. |
| 526 | 526 |
| 527 void SimulateEnableNotificationsForTest(); | 527 void SimulateEnableNotificationsForTest(); |
| 528 | 528 |
| 529 void SimulateDisableNotificationsForTest(int reason); | 529 void SimulateDisableNotificationsForTest(int reason); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 548 // An opaque pointer to the nested private class. | 548 // An opaque pointer to the nested private class. |
| 549 SyncInternal* data_; | 549 SyncInternal* data_; |
| 550 | 550 |
| 551 DISALLOW_COPY_AND_ASSIGN(SyncManager); | 551 DISALLOW_COPY_AND_ASSIGN(SyncManager); |
| 552 }; | 552 }; |
| 553 | 553 |
| 554 bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, UserShare* share); | 554 bool InitialSyncEndedForTypes(syncable::ModelTypeSet types, UserShare* share); |
| 555 | 555 |
| 556 syncable::ModelTypeSet GetTypesWithEmptyProgressMarkerToken( | 556 syncable::ModelTypeSet GetTypesWithEmptyProgressMarkerToken( |
| 557 syncable::ModelTypeSet types, | 557 syncable::ModelTypeSet types, |
| 558 csync::UserShare* share); | 558 syncer::UserShare* share); |
| 559 | 559 |
| 560 const char* ConnectionStatusToString(ConnectionStatus status); | 560 const char* ConnectionStatusToString(ConnectionStatus status); |
| 561 | 561 |
| 562 // Returns the string representation of a PassphraseRequiredReason value. | 562 // Returns the string representation of a PassphraseRequiredReason value. |
| 563 const char* PassphraseRequiredReasonToString(PassphraseRequiredReason reason); | 563 const char* PassphraseRequiredReasonToString(PassphraseRequiredReason reason); |
| 564 | 564 |
| 565 } // namespace csync | 565 } // namespace syncer |
| 566 | 566 |
| 567 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ | 567 #endif // SYNC_INTERNAL_API_PUBLIC_SYNC_MANAGER_H_ |
| OLD | NEW |