| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/time.h" | 12 #include "base/time.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 #include "chrome/common/notification_observer.h" | |
| 15 #include "chrome/common/notification_registrar.h" | |
| 16 | 14 |
| 17 using browser_sync::sessions::SyncSessionSnapshot; | 15 using browser_sync::sessions::SyncSessionSnapshot; |
| 18 | 16 |
| 19 class Profile; | 17 class Profile; |
| 20 | 18 |
| 21 // An instance of this class is basically our notion of a "sync client" for | 19 // An instance of this class is basically our notion of a "sync client" for |
| 22 // automation purposes. It harnesses the ProfileSyncService member of the | 20 // automation purposes. It harnesses the ProfileSyncService member of the |
| 23 // profile passed to it on construction and automates certain things like setup | 21 // profile passed to it on construction and automates certain things like setup |
| 24 // and authentication. It provides ways to "wait" adequate periods of time for | 22 // and authentication. It provides ways to "wait" adequate periods of time for |
| 25 // several clients to get to the same state. | 23 // several clients to get to the same state. |
| 26 class ProfileSyncServiceHarness : public ProfileSyncServiceObserver, | 24 class ProfileSyncServiceHarness : public ProfileSyncServiceObserver { |
| 27 public NotificationObserver { | |
| 28 public: | 25 public: |
| 29 ProfileSyncServiceHarness(Profile* profile, | 26 ProfileSyncServiceHarness(Profile* profile, |
| 30 const std::string& username, | 27 const std::string& username, |
| 31 const std::string& password, | 28 const std::string& password, |
| 32 int id); | 29 int id); |
| 33 | 30 |
| 34 virtual ~ProfileSyncServiceHarness() {} | 31 virtual ~ProfileSyncServiceHarness() {} |
| 35 | 32 |
| 36 // Creates a ProfileSyncServiceHarness object and attaches it to |profile|, a | 33 // Creates a ProfileSyncServiceHarness object and attaches it to |profile|, a |
| 37 // profile that is assumed to have been signed into sync in the past. Caller | 34 // profile that is assumed to have been signed into sync in the past. Caller |
| (...skipping 12 matching lines...) Expand all Loading... |
| 50 // changes. | 47 // changes. |
| 51 bool SetupSync(); | 48 bool SetupSync(); |
| 52 | 49 |
| 53 // Same as the above method, but enables sync only for the datatypes contained | 50 // Same as the above method, but enables sync only for the datatypes contained |
| 54 // in |synced_datatypes|. | 51 // in |synced_datatypes|. |
| 55 bool SetupSync(const syncable::ModelTypeSet& synced_datatypes); | 52 bool SetupSync(const syncable::ModelTypeSet& synced_datatypes); |
| 56 | 53 |
| 57 // ProfileSyncServiceObserver implementation. | 54 // ProfileSyncServiceObserver implementation. |
| 58 virtual void OnStateChanged(); | 55 virtual void OnStateChanged(); |
| 59 | 56 |
| 60 // NotificationObserver implementation. | |
| 61 virtual void Observe(NotificationType type, | |
| 62 const NotificationSource& source, | |
| 63 const NotificationDetails& details); | |
| 64 | |
| 65 // Blocks the caller until this harness has completed a single sync cycle | 57 // Blocks the caller until this harness has completed a single sync cycle |
| 66 // since the previous one. Returns true if a sync cycle has completed. | 58 // since the previous one. Returns true if a sync cycle has completed. |
| 67 bool AwaitSyncCycleCompletion(const std::string& reason); | 59 bool AwaitSyncCycleCompletion(const std::string& reason); |
| 68 | 60 |
| 69 // Blocks the caller until this harness has observed that the sync engine | 61 // Blocks the caller until this harness has observed that the sync engine |
| 70 // has "synced" up to at least the specified local timestamp. | 62 // has "synced" up to at least the specified local timestamp. |
| 71 bool WaitUntilTimestampIsAtLeast(int64 timestamp, const std::string& reason); | 63 bool WaitUntilTimestampIsAtLeast(int64 timestamp, const std::string& reason); |
| 72 | 64 |
| 73 // Calling this acts as a barrier and blocks the caller until |this| and | 65 // Calling this acts as a barrier and blocks the caller until |this| and |
| 74 // |partner| have both completed a sync cycle. When calling this method, | 66 // |partner| have both completed a sync cycle. When calling this method, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // Returns true if the sync client has no unsynced items. | 168 // Returns true if the sync client has no unsynced items. |
| 177 bool IsSynced(); | 169 bool IsSynced(); |
| 178 | 170 |
| 179 // Logs message with relevant info about client's sync state (if available). | 171 // Logs message with relevant info about client's sync state (if available). |
| 180 void LogClientInfo(std::string message); | 172 void LogClientInfo(std::string message); |
| 181 | 173 |
| 182 // Updates |last_timestamp_| with the timestamp of the current sync session. | 174 // Updates |last_timestamp_| with the timestamp of the current sync session. |
| 183 // Returns the new value of |last_timestamp_|. | 175 // Returns the new value of |last_timestamp_|. |
| 184 int64 GetUpdatedTimestamp(); | 176 int64 GetUpdatedTimestamp(); |
| 185 | 177 |
| 186 void StartObservingPassphraseEvents(); | |
| 187 | |
| 188 WaitState wait_state_; | 178 WaitState wait_state_; |
| 189 | 179 |
| 190 Profile* profile_; | 180 Profile* profile_; |
| 191 ProfileSyncService* service_; | 181 ProfileSyncService* service_; |
| 192 | 182 |
| 193 // This value tracks the max sync timestamp (e.g. synced-to revision) inside | 183 // This value tracks the max sync timestamp (e.g. synced-to revision) inside |
| 194 // the sync engine. It gets updated when a sync cycle ends and the session | 184 // the sync engine. It gets updated when a sync cycle ends and the session |
| 195 // snapshot implies syncing is "done". | 185 // snapshot implies syncing is "done". |
| 196 int64 last_timestamp_; | 186 int64 last_timestamp_; |
| 197 | 187 |
| 198 // The minimum value of the 'max_local_timestamp' member of a | 188 // The minimum value of the 'max_local_timestamp' member of a |
| 199 // SyncSessionSnapshot we need to wait to observe in OnStateChanged when told | 189 // SyncSessionSnapshot we need to wait to observe in OnStateChanged when told |
| 200 // to WaitUntilTimestampIsAtLeast(...). | 190 // to WaitUntilTimestampIsAtLeast(...). |
| 201 int64 min_timestamp_needed_; | 191 int64 min_timestamp_needed_; |
| 202 | 192 |
| 203 // Credentials used for GAIA authentication. | 193 // Credentials used for GAIA authentication. |
| 204 std::string username_; | 194 std::string username_; |
| 205 std::string password_; | 195 std::string password_; |
| 206 | 196 |
| 207 // A counter to track the number of await passphrase requests versus | |
| 208 // actual acceptances. Can go negative if #requests > #acceptances. | |
| 209 int passphrase_acceptance_counter_; | |
| 210 | |
| 211 NotificationRegistrar registrar_; | |
| 212 | |
| 213 // Client ID, used for logging purposes. | 197 // Client ID, used for logging purposes. |
| 214 int id_; | 198 int id_; |
| 215 | 199 |
| 216 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceHarness); | 200 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceHarness); |
| 217 }; | 201 }; |
| 218 | 202 |
| 219 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ | 203 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_HARNESS_H_ |
| OLD | NEW |