| 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 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // 3. New items with synced parents & predecessors. | 115 // 3. New items with synced parents & predecessors. |
| 116 // 4. Items with parents & predecessors in |changes|. | 116 // 4. Items with parents & predecessors in |changes|. |
| 117 // 5. Repeat #4 until all items are in |changes|. | 117 // 5. Repeat #4 until all items are in |changes|. |
| 118 // | 118 // |
| 119 // Thus, an implementation of OnChangesApplied should be able to | 119 // Thus, an implementation of OnChangesApplied should be able to |
| 120 // process the change records in the order without having to worry about | 120 // process the change records in the order without having to worry about |
| 121 // forward dependencies. But since deletions come before reparent | 121 // forward dependencies. But since deletions come before reparent |
| 122 // operations, a delete may temporarily orphan a node that is | 122 // operations, a delete may temporarily orphan a node that is |
| 123 // updated later in the list. | 123 // updated later in the list. |
| 124 virtual void OnChangesApplied( | 124 virtual void OnChangesApplied( |
| 125 syncable::ModelType model_type, | 125 syncer::ModelType model_type, |
| 126 const BaseTransaction* trans, | 126 const BaseTransaction* trans, |
| 127 const ImmutableChangeRecordList& changes) = 0; | 127 const ImmutableChangeRecordList& changes) = 0; |
| 128 | 128 |
| 129 // OnChangesComplete gets called when the TransactionComplete event is | 129 // OnChangesComplete gets called when the TransactionComplete event is |
| 130 // posted (after OnChangesApplied finishes), after the transaction lock | 130 // posted (after OnChangesApplied finishes), after the transaction lock |
| 131 // and the change channel mutex are released. | 131 // and the change channel mutex are released. |
| 132 // | 132 // |
| 133 // The purpose of this function is to support processors that require | 133 // The purpose of this function is to support processors that require |
| 134 // split-transactions changes. For example, if a model processor wants to | 134 // split-transactions changes. For example, if a model processor wants to |
| 135 // perform blocking I/O due to a change, it should calculate the changes | 135 // perform blocking I/O due to a change, it should calculate the changes |
| 136 // while holding the transaction lock (from within OnChangesApplied), buffer | 136 // while holding the transaction lock (from within OnChangesApplied), buffer |
| 137 // those changes, let the transaction fall out of scope, and then commit | 137 // those changes, let the transaction fall out of scope, and then commit |
| 138 // those changes from within OnChangesComplete (postponing the blocking | 138 // those changes from within OnChangesComplete (postponing the blocking |
| 139 // I/O to when it no longer holds any lock). | 139 // I/O to when it no longer holds any lock). |
| 140 virtual void OnChangesComplete(syncable::ModelType model_type) = 0; | 140 virtual void OnChangesComplete(syncer::ModelType model_type) = 0; |
| 141 | 141 |
| 142 protected: | 142 protected: |
| 143 virtual ~ChangeDelegate(); | 143 virtual ~ChangeDelegate(); |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 // Like ChangeDelegate, except called only on the sync thread and | 146 // Like ChangeDelegate, except called only on the sync thread and |
| 147 // not while a transaction is held. For objects that want to know | 147 // not while a transaction is held. For objects that want to know |
| 148 // when changes happen, but don't need to process them. | 148 // when changes happen, but don't need to process them. |
| 149 class ChangeObserver { | 149 class ChangeObserver { |
| 150 public: | 150 public: |
| 151 // Ids referred to in |changes| may or may not be in the write | 151 // Ids referred to in |changes| may or may not be in the write |
| 152 // transaction specified by |write_transaction_id|. If they're | 152 // transaction specified by |write_transaction_id|. If they're |
| 153 // not, that means that the node didn't actually change, but we | 153 // not, that means that the node didn't actually change, but we |
| 154 // marked them as changed for some other reason (e.g., siblings of | 154 // marked them as changed for some other reason (e.g., siblings of |
| 155 // re-ordered nodes). | 155 // re-ordered nodes). |
| 156 // | 156 // |
| 157 // TODO(sync, long-term): Ideally, ChangeDelegate/Observer would | 157 // TODO(sync, long-term): Ideally, ChangeDelegate/Observer would |
| 158 // be passed a transformed version of EntryKernelMutation instead | 158 // be passed a transformed version of EntryKernelMutation instead |
| 159 // of a transaction that would have to be used to look up the | 159 // of a transaction that would have to be used to look up the |
| 160 // changed nodes. That is, ChangeDelegate::OnChangesApplied() | 160 // changed nodes. That is, ChangeDelegate::OnChangesApplied() |
| 161 // would still be called under the transaction, but all the needed | 161 // would still be called under the transaction, but all the needed |
| 162 // data will be passed down. | 162 // data will be passed down. |
| 163 // | 163 // |
| 164 // Even more ideally, we would have sync semantics such that we'd | 164 // Even more ideally, we would have sync semantics such that we'd |
| 165 // be able to apply changes without being under a transaction. | 165 // be able to apply changes without being under a transaction. |
| 166 // But that's a ways off... | 166 // But that's a ways off... |
| 167 virtual void OnChangesApplied( | 167 virtual void OnChangesApplied( |
| 168 syncable::ModelType model_type, | 168 syncer::ModelType model_type, |
| 169 int64 write_transaction_id, | 169 int64 write_transaction_id, |
| 170 const ImmutableChangeRecordList& changes) = 0; | 170 const ImmutableChangeRecordList& changes) = 0; |
| 171 | 171 |
| 172 virtual void OnChangesComplete(syncable::ModelType model_type) = 0; | 172 virtual void OnChangesComplete(syncer::ModelType model_type) = 0; |
| 173 | 173 |
| 174 protected: | 174 protected: |
| 175 virtual ~ChangeObserver(); | 175 virtual ~ChangeObserver(); |
| 176 }; | 176 }; |
| 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 { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // |encrypted_types| will always be a superset of | 317 // |encrypted_types| will always be a superset of |
| 318 // Cryptographer::SensitiveTypes(). If |encrypt_everything| is | 318 // Cryptographer::SensitiveTypes(). If |encrypt_everything| is |
| 319 // true, |encrypted_types| will be the set of all known types. | 319 // true, |encrypted_types| will be the set of all known types. |
| 320 // | 320 // |
| 321 // Until this function is called, observers can assume that the | 321 // Until this function is called, observers can assume that the |
| 322 // set of encrypted types is Cryptographer::SensitiveTypes() and | 322 // set of encrypted types is Cryptographer::SensitiveTypes() and |
| 323 // that the encrypt everything flag is false. | 323 // that the encrypt everything flag is false. |
| 324 // | 324 // |
| 325 // Called from within a transaction. | 325 // Called from within a transaction. |
| 326 virtual void OnEncryptedTypesChanged( | 326 virtual void OnEncryptedTypesChanged( |
| 327 syncable::ModelTypeSet encrypted_types, | 327 syncer::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 syncer::SyncProtocolError& sync_protocol_error) = 0; | 337 const syncer::SyncProtocolError& sync_protocol_error) = 0; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 syncer::UnrecoverableErrorHandler* | 392 syncer::UnrecoverableErrorHandler* |
| 393 unrecoverable_error_handler, | 393 unrecoverable_error_handler, |
| 394 syncer::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 syncer::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 syncer::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 syncer::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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 syncer::ModelSafeRoutingInfo& routing_info, | 439 void RequestConfig(const syncer::ModelSafeRoutingInfo& routing_info, |
| 440 const syncable::ModelTypeSet& types, | 440 const syncer::ModelTypeSet& types, |
| 441 syncer::ConfigureReason reason); | 441 syncer::ConfigureReason reason); |
| 442 | 442 |
| 443 void RequestCleanupDisabledTypes( | 443 void RequestCleanupDisabledTypes( |
| 444 const syncer::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 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 // OnPassphraseRequired(), but otherwise it will trigger | 504 // OnPassphraseRequired(), but otherwise it will trigger |
| 505 // OnEncryptionComplete(). | 505 // OnEncryptionComplete(). |
| 506 void EnableEncryptEverything(); | 506 void EnableEncryptEverything(); |
| 507 | 507 |
| 508 // Returns true if we are currently encrypting all sync data. May | 508 // Returns true if we are currently encrypting all sync data. May |
| 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 syncer::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(syncer::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); |
| 530 | 530 |
| 531 void TriggerOnIncomingNotificationForTest( | 531 void TriggerOnIncomingNotificationForTest( |
| 532 syncable::ModelTypeSet model_types); | 532 syncer::ModelTypeSet model_types); |
| 533 | 533 |
| 534 static const int kDefaultNudgeDelayMilliseconds; | 534 static const int kDefaultNudgeDelayMilliseconds; |
| 535 static const int kPreferencesNudgeDelayMilliseconds; | 535 static const int kPreferencesNudgeDelayMilliseconds; |
| 536 static const int kPiggybackNudgeDelay; | 536 static const int kPiggybackNudgeDelay; |
| 537 | 537 |
| 538 static const FilePath::CharType kSyncDatabaseFilename[]; | 538 static const FilePath::CharType kSyncDatabaseFilename[]; |
| 539 | 539 |
| 540 private: | 540 private: |
| 541 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, NudgeDelayTest); | 541 FRIEND_TEST_ALL_PREFIXES(SyncManagerTest, NudgeDelayTest); |
| 542 | 542 |
| 543 // For unit tests. | 543 // For unit tests. |
| 544 base::TimeDelta GetNudgeDelayTimeDelta(const syncable::ModelType& model_type); | 544 base::TimeDelta GetNudgeDelayTimeDelta(const syncer::ModelType& model_type); |
| 545 | 545 |
| 546 base::ThreadChecker thread_checker_; | 546 base::ThreadChecker thread_checker_; |
| 547 | 547 |
| 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(syncer::ModelTypeSet types, UserShare* share); |
| 555 | 555 |
| 556 syncable::ModelTypeSet GetTypesWithEmptyProgressMarkerToken( | 556 syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken( |
| 557 syncable::ModelTypeSet types, | 557 syncer::ModelTypeSet types, |
| 558 syncer::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 syncer | 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 |