| 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_PROFILE_SYNC_SERVICE_HARNESS_H_ | 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ |
| 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ | 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" |
| 14 #include "chrome/browser/sync/backend_migrator.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 15 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 #include "chrome/browser/sync/profile_sync_service_observer.h" | 16 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 15 #include "chrome/browser/sync/retry_verifier.h" | 17 #include "chrome/browser/sync/retry_verifier.h" |
| 16 #include "chrome/browser/sync/syncable/model_type.h" | 18 #include "chrome/browser/sync/syncable/model_type.h" |
| 17 | 19 |
| 18 class Profile; | 20 class Profile; |
| 19 | 21 |
| 20 namespace browser_sync { | 22 namespace browser_sync { |
| 21 namespace sessions { | 23 namespace sessions { |
| 22 struct SyncSessionSnapshot; | 24 struct SyncSessionSnapshot; |
| 23 } | 25 } |
| 24 } | 26 } |
| 25 | 27 |
| 26 // An instance of this class is basically our notion of a "sync client" for | 28 // An instance of this class is basically our notion of a "sync client" for |
| 27 // automation purposes. It harnesses the ProfileSyncService member of the | 29 // automation purposes. It harnesses the ProfileSyncService member of the |
| 28 // profile passed to it on construction and automates certain things like setup | 30 // profile passed to it on construction and automates certain things like setup |
| 29 // and authentication. It provides ways to "wait" adequate periods of time for | 31 // and authentication. It provides ways to "wait" adequate periods of time for |
| 30 // several clients to get to the same state. | 32 // several clients to get to the same state. |
| 31 class ProfileSyncServiceHarness : public ProfileSyncServiceObserver { | 33 class ProfileSyncServiceHarness |
| 34 : public ProfileSyncServiceObserver, |
| 35 public browser_sync::MigrationObserver { |
| 32 public: | 36 public: |
| 33 ProfileSyncServiceHarness(Profile* profile, | 37 ProfileSyncServiceHarness(Profile* profile, |
| 34 const std::string& username, | 38 const std::string& username, |
| 35 const std::string& password); | 39 const std::string& password); |
| 36 | 40 |
| 37 virtual ~ProfileSyncServiceHarness(); | 41 virtual ~ProfileSyncServiceHarness(); |
| 38 | 42 |
| 39 // Creates a ProfileSyncServiceHarness object and attaches it to |profile|, a | 43 // Creates a ProfileSyncServiceHarness object and attaches it to |profile|, a |
| 40 // profile that is assumed to have been signed into sync in the past. Caller | 44 // profile that is assumed to have been signed into sync in the past. Caller |
| 41 // takes ownership. | 45 // takes ownership. |
| 42 static ProfileSyncServiceHarness* CreateAndAttach(Profile* profile); | 46 static ProfileSyncServiceHarness* CreateAndAttach(Profile* profile); |
| 43 | 47 |
| 44 // Sets the GAIA credentials with which to sign in to sync. | 48 // Sets the GAIA credentials with which to sign in to sync. |
| 45 void SetCredentials(const std::string& username, const std::string& password); | 49 void SetCredentials(const std::string& username, const std::string& password); |
| 46 | 50 |
| 47 // Returns true if sync has been enabled on |profile_|. | 51 // Returns true if sync has been enabled on |profile_|. |
| 48 bool IsSyncAlreadySetup(); | 52 bool IsSyncAlreadySetup(); |
| 49 | 53 |
| 50 // Creates a ProfileSyncService for the profile passed at construction and | 54 // Creates a ProfileSyncService for the profile passed at construction and |
| 51 // enables sync for all available datatypes. Returns true only after sync has | 55 // enables sync for all available datatypes. Returns true only after sync has |
| 52 // been fully initialized and authenticated, and we are ready to process | 56 // been fully initialized and authenticated, and we are ready to process |
| 53 // changes. | 57 // changes. |
| 54 bool SetupSync(); | 58 bool SetupSync(); |
| 55 | 59 |
| 56 // Same as the above method, but enables sync only for the datatypes contained | 60 // Same as the above method, but enables sync only for the datatypes contained |
| 57 // in |synced_datatypes|. | 61 // in |synced_datatypes|. |
| 58 bool SetupSync(const syncable::ModelTypeSet& synced_datatypes); | 62 bool SetupSync(const syncable::ModelTypeSet& synced_datatypes); |
| 59 | 63 |
| 60 // ProfileSyncServiceObserver implementation. | 64 // ProfileSyncServiceObserver implementation. |
| 61 virtual void OnStateChanged(); | 65 virtual void OnStateChanged() OVERRIDE; |
| 66 |
| 67 // MigrationObserver implementation. |
| 68 virtual void OnMigrationStateChange() OVERRIDE; |
| 62 | 69 |
| 63 // Blocks the caller until the sync backend host associated with this harness | 70 // Blocks the caller until the sync backend host associated with this harness |
| 64 // has been initialized. Returns true if the wait was successful. | 71 // has been initialized. Returns true if the wait was successful. |
| 65 bool AwaitBackendInitialized(); | 72 bool AwaitBackendInitialized(); |
| 66 | 73 |
| 67 // Blocks the caller until the datatype manager is configured and sync has | 74 // Blocks the caller until the datatype manager is configured and sync has |
| 68 // been initialized (for example, after a browser restart). Returns true if | 75 // been initialized (for example, after a browser restart). Returns true if |
| 69 // the wait was successful. | 76 // the wait was successful. |
| 70 bool AwaitSyncRestart(); | 77 bool AwaitSyncRestart(); |
| 71 | 78 |
| 72 // Blocks the caller until this harness has completed a single sync cycle | 79 // Blocks the caller until this harness has completed a single sync cycle |
| 73 // since the previous one. Returns true if a sync cycle has completed. | 80 // since the previous one. Returns true if a sync cycle has completed. |
| 74 bool AwaitSyncCycleCompletion(const std::string& reason); | 81 bool AwaitSyncCycleCompletion(const std::string& reason); |
| 75 | 82 |
| 76 // Blocks the caller until this harness has completed a single sync | |
| 77 // cycle, even if we're already synced. Returns true if a sync | |
| 78 // cycle has completed. | |
| 79 // | |
| 80 // TODO(akalin): This is only used by some migration tests, pending | |
| 81 // the fix for http://crbug.com/92928. Remove this once that is | |
| 82 // fixed. | |
| 83 bool AwaitNextSyncCycleCompletion(const std::string& reason); | |
| 84 | |
| 85 // Blocks the caller until the sync has been disabled for this client. Returns | 83 // Blocks the caller until the sync has been disabled for this client. Returns |
| 86 // true if sync is disabled. | 84 // true if sync is disabled. |
| 87 bool AwaitSyncDisabled(const std::string& reason); | 85 bool AwaitSyncDisabled(const std::string& reason); |
| 88 | 86 |
| 89 // Blocks the caller until exponential backoff has been verified to happen. | 87 // Blocks the caller until exponential backoff has been verified to happen. |
| 90 bool AwaitExponentialBackoffVerification(); | 88 bool AwaitExponentialBackoffVerification(); |
| 91 | 89 |
| 90 // Blocks until the given set of data types are migrated. |
| 91 bool AwaitMigration(const syncable::ModelTypeSet& expected_migrated_types); |
| 92 |
| 92 // Blocks the caller until this harness has observed that the sync engine | 93 // Blocks the caller until this harness has observed that the sync engine |
| 93 // has downloaded all the changes seen by the |partner| harness's client. | 94 // has downloaded all the changes seen by the |partner| harness's client. |
| 94 bool WaitUntilTimestampMatches( | 95 bool WaitUntilTimestampMatches( |
| 95 ProfileSyncServiceHarness* partner, const std::string& reason); | 96 ProfileSyncServiceHarness* partner, const std::string& reason); |
| 96 | 97 |
| 97 // Calling this acts as a barrier and blocks the caller until |this| and | 98 // Calling this acts as a barrier and blocks the caller until |this| and |
| 98 // |partner| have both completed a sync cycle. When calling this method, | 99 // |partner| have both completed a sync cycle. When calling this method, |
| 99 // the |partner| should be the passive responder who responds to the actions | 100 // the |partner| should be the passive responder who responds to the actions |
| 100 // of |this|. This method relies upon the synchronization of callbacks | 101 // of |this|. This method relies upon the synchronization of callbacks |
| 101 // from the message queue. Returns true if two sync cycles have completed. | 102 // from the message queue. Returns true if two sync cycles have completed. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // full sync cycle is not expected to occur. | 207 // full sync cycle is not expected to occur. |
| 207 WAITING_FOR_SYNC_CONFIGURATION, | 208 WAITING_FOR_SYNC_CONFIGURATION, |
| 208 | 209 |
| 209 // The sync client is waiting for the sync to be disabled for this client. | 210 // The sync client is waiting for the sync to be disabled for this client. |
| 210 WAITING_FOR_SYNC_DISABLED, | 211 WAITING_FOR_SYNC_DISABLED, |
| 211 | 212 |
| 212 // The sync client is in the exponential backoff mode. Verify that | 213 // The sync client is in the exponential backoff mode. Verify that |
| 213 // backoffs are triggered correctly. | 214 // backoffs are triggered correctly. |
| 214 WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION, | 215 WAITING_FOR_EXPONENTIAL_BACKOFF_VERIFICATION, |
| 215 | 216 |
| 217 // The sync client is waiting for migration to start. |
| 218 WAITING_FOR_MIGRATION_TO_START, |
| 219 |
| 220 // The sync client is waiting for migration to finish. |
| 221 WAITING_FOR_MIGRATION_TO_FINISH, |
| 222 |
| 216 // The client verification is complete. We don't care about the state of | 223 // The client verification is complete. We don't care about the state of |
| 217 // the syncer any more. | 224 // the syncer any more. |
| 218 WAITING_FOR_NOTHING, | 225 WAITING_FOR_NOTHING, |
| 219 | 226 |
| 220 // The sync client needs a passphrase in order to decrypt data. | 227 // The sync client needs a passphrase in order to decrypt data. |
| 221 SET_PASSPHRASE_FAILED, | 228 SET_PASSPHRASE_FAILED, |
| 222 | 229 |
| 223 // The sync client cannot reach the server. | 230 // The sync client cannot reach the server. |
| 224 SERVER_UNREACHABLE, | 231 SERVER_UNREACHABLE, |
| 225 | 232 |
| 226 // The sync client is fully synced and there are no pending updates. | 233 // The sync client is fully synced and there are no pending updates. |
| 227 FULLY_SYNCED, | 234 FULLY_SYNCED, |
| 228 | 235 |
| 229 // Syncing is disabled for the client. | 236 // Syncing is disabled for the client. |
| 230 SYNC_DISABLED, | 237 SYNC_DISABLED, |
| 231 | 238 |
| 232 NUMBER_OF_STATES, | 239 NUMBER_OF_STATES, |
| 233 }; | 240 }; |
| 234 | 241 |
| 242 // Listen to migration events if the migrator has been initialized |
| 243 // and we're not already listening. Returns true if we started |
| 244 // listening. |
| 245 bool TryListeningToMigrationEvents(); |
| 246 |
| 235 // Called from the observer when the current wait state has been completed. | 247 // Called from the observer when the current wait state has been completed. |
| 236 void SignalStateCompleteWithNextState(WaitState next_state); | 248 void SignalStateCompleteWithNextState(WaitState next_state); |
| 237 | 249 |
| 238 // Indicates that the operation being waited on is complete. | 250 // Indicates that the operation being waited on is complete. |
| 239 void SignalStateComplete(); | 251 void SignalStateComplete(); |
| 240 | 252 |
| 241 // Finite state machine for controlling state. Returns true only if a state | 253 // Finite state machine for controlling state. Returns true only if a state |
| 242 // change has taken place. | 254 // change has taken place. |
| 243 bool RunStateChangeMachine(); | 255 bool RunStateChangeMachine(); |
| 244 | 256 |
| 245 // Returns true if a status change took place, false on timeout. | 257 // Returns true if a status change took place, false on timeout. |
| 246 bool AwaitStatusChangeWithTimeout(int timeout_milliseconds, | 258 bool AwaitStatusChangeWithTimeout(int timeout_milliseconds, |
| 247 const std::string& reason); | 259 const std::string& reason); |
| 248 | 260 |
| 249 // Used by AwaitSyncCycleCompletion() and | |
| 250 // AwaitNextSyncCycleCompletion(). | |
| 251 bool AwaitSyncCycleCompletionHelper(const std::string& reason); | |
| 252 | |
| 253 // Returns true if the sync client has no unsynced items. | 261 // Returns true if the sync client has no unsynced items. |
| 254 bool IsSynced(); | 262 bool IsSynced(); |
| 255 | 263 |
| 264 // Returns true if there is a backend migration in progress. |
| 265 bool HasPendingBackendMigration(); |
| 266 |
| 256 // Returns true if this client has downloaded all the items that the | 267 // Returns true if this client has downloaded all the items that the |
| 257 // other client has. | 268 // other client has. |
| 258 bool MatchesOtherClient(ProfileSyncServiceHarness* partner); | 269 bool MatchesOtherClient(ProfileSyncServiceHarness* partner); |
| 259 | 270 |
| 260 // Returns a string with relevant info about client's sync state (if | 271 // Returns a string with relevant info about client's sync state (if |
| 261 // available), annotated with |message|. Useful for logging. | 272 // available), annotated with |message|. Useful for logging. |
| 262 std::string GetClientInfoString(const std::string& message); | 273 std::string GetClientInfoString(const std::string& message); |
| 263 | 274 |
| 264 // Gets the current progress indicator of the current sync session | 275 // Gets the current progress indicator of the current sync session |
| 265 // for a particular datatype. | 276 // for a particular datatype. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 283 ProfileSyncService* service_; | 294 ProfileSyncService* service_; |
| 284 | 295 |
| 285 // The harness of the client whose update progress marker we're expecting | 296 // The harness of the client whose update progress marker we're expecting |
| 286 // eventually match. | 297 // eventually match. |
| 287 ProfileSyncServiceHarness* timestamp_match_partner_; | 298 ProfileSyncServiceHarness* timestamp_match_partner_; |
| 288 | 299 |
| 289 // Credentials used for GAIA authentication. | 300 // Credentials used for GAIA authentication. |
| 290 std::string username_; | 301 std::string username_; |
| 291 std::string password_; | 302 std::string password_; |
| 292 | 303 |
| 304 // The current set of data types pending migration. Used by |
| 305 // AwaitMigration(). |
| 306 syncable::ModelTypeSet pending_migration_types_; |
| 307 |
| 308 // The set of data types that have undergone migration. Used by |
| 309 // AwaitMigration(). |
| 310 syncable::ModelTypeSet migrated_types_; |
| 311 |
| 293 // Used for logging. | 312 // Used for logging. |
| 294 const std::string profile_debug_name_; | 313 const std::string profile_debug_name_; |
| 295 | 314 |
| 296 // Keeps track of the number of attempts at exponential backoff and its | 315 // Keeps track of the number of attempts at exponential backoff and its |
| 297 // related bookkeeping information for verification. | 316 // related bookkeeping information for verification. |
| 298 browser_sync::RetryVerifier retry_verifier_; | 317 browser_sync::RetryVerifier retry_verifier_; |
| 299 | 318 |
| 300 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceHarness); | 319 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceHarness); |
| 301 }; | 320 }; |
| 302 | 321 |
| 303 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ | 322 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ |
| OLD | NEW |