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 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 | 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/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "chrome/browser/sync/backend_migrator.h" | 13 #include "chrome/browser/sync/backend_migrator.h" |
14 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
15 #include "chrome/browser/sync/profile_sync_service_observer.h" | 15 #include "chrome/browser/sync/profile_sync_service_observer.h" |
16 #include "chrome/browser/sync/retry_verifier.h" | 16 #include "chrome/browser/sync/retry_verifier.h" |
17 #include "sync/internal_api/public/base/model_type.h" | 17 #include "sync/internal_api/public/base/model_type.h" |
18 | 18 |
19 class Profile; | 19 class Profile; |
20 | 20 |
| 21 namespace invalidation { |
| 22 class P2PInvalidationService; |
| 23 } |
| 24 |
21 namespace browser_sync { | 25 namespace browser_sync { |
22 namespace sessions { | 26 namespace sessions { |
23 class SyncSessionSnapshot; | 27 class SyncSessionSnapshot; |
24 } | 28 } |
25 } | 29 } |
26 | 30 |
27 // An instance of this class is basically our notion of a "sync client" for | 31 // An instance of this class is basically our notion of a "sync client" for |
28 // automation purposes. It harnesses the ProfileSyncService member of the | 32 // automation purposes. It harnesses the ProfileSyncService member of the |
29 // profile passed to it on construction and automates certain things like setup | 33 // profile passed to it on construction and automates certain things like setup |
30 // and authentication. It provides ways to "wait" adequate periods of time for | 34 // and authentication. It provides ways to "wait" adequate periods of time for |
31 // several clients to get to the same state. | 35 // several clients to get to the same state. |
32 class ProfileSyncServiceHarness | 36 class ProfileSyncServiceHarness |
33 : public ProfileSyncServiceObserver, | 37 : public ProfileSyncServiceObserver, |
34 public browser_sync::MigrationObserver { | 38 public browser_sync::MigrationObserver { |
35 public: | 39 public: |
36 ProfileSyncServiceHarness(Profile* profile, | 40 static ProfileSyncServiceHarness* Create( |
37 const std::string& username, | 41 Profile* profile, |
38 const std::string& password); | 42 const std::string& username, |
| 43 const std::string& password); |
| 44 |
| 45 static ProfileSyncServiceHarness* CreateForIntegrationTest( |
| 46 Profile* profile, |
| 47 const std::string& username, |
| 48 const std::string& password, |
| 49 invalidation::P2PInvalidationService* invalidation_service); |
39 | 50 |
40 virtual ~ProfileSyncServiceHarness(); | 51 virtual ~ProfileSyncServiceHarness(); |
41 | 52 |
42 // Creates a ProfileSyncServiceHarness object and attaches it to |profile|, a | |
43 // profile that is assumed to have been signed into sync in the past. Caller | |
44 // takes ownership. | |
45 static ProfileSyncServiceHarness* CreateAndAttach(Profile* profile); | |
46 | |
47 // Sets the GAIA credentials with which to sign in to sync. | 53 // Sets the GAIA credentials with which to sign in to sync. |
48 void SetCredentials(const std::string& username, const std::string& password); | 54 void SetCredentials(const std::string& username, const std::string& password); |
49 | 55 |
50 // Returns true if sync has been enabled on |profile_|. | 56 // Returns true if sync has been enabled on |profile_|. |
51 bool IsSyncAlreadySetup(); | 57 bool IsSyncAlreadySetup(); |
52 | 58 |
53 // Creates a ProfileSyncService for the profile passed at construction and | 59 // Creates a ProfileSyncService for the profile passed at construction and |
54 // enables sync for all available datatypes. Returns true only after sync has | 60 // enables sync for all available datatypes. Returns true only after sync has |
55 // been fully initialized and authenticated, and we are ready to process | 61 // been fully initialized and authenticated, and we are ready to process |
56 // changes. | 62 // changes. |
57 bool SetupSync(); | 63 bool SetupSync(); |
58 | 64 |
59 // Same as the above method, but enables sync only for the datatypes contained | 65 // Same as the above method, but enables sync only for the datatypes contained |
60 // in |synced_datatypes|. | 66 // in |synced_datatypes|. |
61 bool SetupSync(syncer::ModelTypeSet synced_datatypes); | 67 bool SetupSync(syncer::ModelTypeSet synced_datatypes); |
62 | 68 |
63 // ProfileSyncServiceObserver implementation. | 69 // ProfileSyncServiceObserver implementation. |
64 virtual void OnStateChanged() OVERRIDE; | 70 virtual void OnStateChanged() OVERRIDE; |
| 71 virtual void OnSyncCycleCompleted() OVERRIDE; |
65 | 72 |
66 // MigrationObserver implementation. | 73 // MigrationObserver implementation. |
67 virtual void OnMigrationStateChange() OVERRIDE; | 74 virtual void OnMigrationStateChange() OVERRIDE; |
68 | 75 |
69 // Blocks the caller until the sync backend host associated with this harness | 76 // Blocks the caller until the sync backend host associated with this harness |
70 // has been initialized. Returns true if the wait was successful. | 77 // has been initialized. Returns true if the wait was successful. |
71 bool AwaitBackendInitialized(); | 78 bool AwaitBackendInitialized(); |
72 | 79 |
73 // Blocks the caller until this harness has completed a single sync cycle | 80 // Blocks the caller until this harness has completed a single sync cycle |
74 // since the previous one. Returns true if a sync cycle has completed. | 81 // since the previous one. Returns true if a sync cycle has completed. |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 270 |
264 // The sync client is fully synced and there are no pending updates. | 271 // The sync client is fully synced and there are no pending updates. |
265 FULLY_SYNCED, | 272 FULLY_SYNCED, |
266 | 273 |
267 // Syncing is disabled for the client. | 274 // Syncing is disabled for the client. |
268 SYNC_DISABLED, | 275 SYNC_DISABLED, |
269 | 276 |
270 NUMBER_OF_STATES, | 277 NUMBER_OF_STATES, |
271 }; | 278 }; |
272 | 279 |
| 280 ProfileSyncServiceHarness( |
| 281 Profile* profile, |
| 282 const std::string& username, |
| 283 const std::string& password, |
| 284 invalidation::P2PInvalidationService* invalidation_service); |
| 285 |
273 // Listen to migration events if the migrator has been initialized | 286 // Listen to migration events if the migrator has been initialized |
274 // and we're not already listening. Returns true if we started | 287 // and we're not already listening. Returns true if we started |
275 // listening. | 288 // listening. |
276 bool TryListeningToMigrationEvents(); | 289 bool TryListeningToMigrationEvents(); |
277 | 290 |
278 // Called from the observer when the current wait state has been completed. | 291 // Called from the observer when the current wait state has been completed. |
279 void SignalStateCompleteWithNextState(WaitState next_state); | 292 void SignalStateCompleteWithNextState(WaitState next_state); |
280 | 293 |
281 // Indicates that the operation being waited on is complete. | 294 // Indicates that the operation being waited on is complete. |
282 void SignalStateComplete(); | 295 void SignalStateComplete(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // The WaitState in which the sync client currently is. Helps determine what | 340 // The WaitState in which the sync client currently is. Helps determine what |
328 // action to take when RunStateChangeMachine() is called. | 341 // action to take when RunStateChangeMachine() is called. |
329 WaitState wait_state_; | 342 WaitState wait_state_; |
330 | 343 |
331 // Sync profile associated with this sync client. | 344 // Sync profile associated with this sync client. |
332 Profile* profile_; | 345 Profile* profile_; |
333 | 346 |
334 // ProfileSyncService object associated with |profile_|. | 347 // ProfileSyncService object associated with |profile_|. |
335 ProfileSyncService* service_; | 348 ProfileSyncService* service_; |
336 | 349 |
| 350 // P2PInvalidationService associated with |profile_|. |
| 351 invalidation::P2PInvalidationService* p2p_invalidation_service_; |
| 352 |
337 // The harness of the client whose update progress marker we're expecting | 353 // The harness of the client whose update progress marker we're expecting |
338 // eventually match. | 354 // eventually match. |
339 ProfileSyncServiceHarness* progress_marker_partner_; | 355 ProfileSyncServiceHarness* progress_marker_partner_; |
340 | 356 |
341 // Credentials used for GAIA authentication. | 357 // Credentials used for GAIA authentication. |
342 std::string username_; | 358 std::string username_; |
343 std::string password_; | 359 std::string password_; |
344 | 360 |
345 // The current set of data types pending migration. Used by | 361 // The current set of data types pending migration. Used by |
346 // AwaitMigration(). | 362 // AwaitMigration(). |
(...skipping 12 matching lines...) Expand all Loading... |
359 | 375 |
360 // Flag set to true when we're waiting for a status change to happen. Used to | 376 // Flag set to true when we're waiting for a status change to happen. Used to |
361 // avoid triggering internal state machine logic on unexpected sync observer | 377 // avoid triggering internal state machine logic on unexpected sync observer |
362 // callbacks. | 378 // callbacks. |
363 bool waiting_for_status_change_; | 379 bool waiting_for_status_change_; |
364 | 380 |
365 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceHarness); | 381 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceHarness); |
366 }; | 382 }; |
367 | 383 |
368 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ | 384 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ |
OLD | NEW |