OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_SYNC_STARTUP_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_SYNC_STARTUP_TRACKER_H_ |
6 #define CHROME_BROWSER_SYNC_SYNC_STARTUP_TRACKER_H_ | 6 #define CHROME_BROWSER_SYNC_SYNC_STARTUP_TRACKER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "components/sync/driver/sync_service_observer.h" | 10 #include "components/sync/driver/sync_service_observer.h" |
11 | 11 |
12 class Profile; | 12 class Profile; |
13 | 13 |
14 // SyncStartupTracker provides a centralized way for observers to detect when | 14 // SyncStartupTracker provides a centralized way for observers to detect when |
15 // ProfileSyncService has successfully started up, or when startup has failed | 15 // ProfileSyncService has successfully started up, or when startup has failed |
16 // due to some kind of error. This code was originally part of SigninTracker | 16 // due to some kind of error. This code was originally part of SigninTracker |
17 // but now that sync initialization is no longer a required part of signin, | 17 // but now that sync initialization is no longer a required part of signin, |
18 // it has been broken out of that class so only those places that care about | 18 // it has been broken out of that class so only those places that care about |
19 // sync initialization depend on it. | 19 // sync initialization depend on it. |
20 class SyncStartupTracker : public sync_driver::SyncServiceObserver { | 20 class SyncStartupTracker : public syncer::SyncServiceObserver { |
21 public: | 21 public: |
22 // Observer interface used to notify observers when sync has started up. | 22 // Observer interface used to notify observers when sync has started up. |
23 class Observer { | 23 class Observer { |
24 public: | 24 public: |
25 virtual ~Observer() {} | 25 virtual ~Observer() {} |
26 | 26 |
27 virtual void SyncStartupCompleted() = 0; | 27 virtual void SyncStartupCompleted() = 0; |
28 virtual void SyncStartupFailed() = 0; | 28 virtual void SyncStartupFailed() = 0; |
29 }; | 29 }; |
30 | 30 |
31 SyncStartupTracker(Profile* profile, Observer* observer); | 31 SyncStartupTracker(Profile* profile, Observer* observer); |
32 ~SyncStartupTracker() override; | 32 ~SyncStartupTracker() override; |
33 | 33 |
34 enum SyncServiceState { | 34 enum SyncServiceState { |
35 // Sync backend is still starting up. | 35 // Sync backend is still starting up. |
36 SYNC_STARTUP_PENDING, | 36 SYNC_STARTUP_PENDING, |
37 // An error has been detected that prevents the sync backend from starting | 37 // An error has been detected that prevents the sync backend from starting |
38 // up. | 38 // up. |
39 SYNC_STARTUP_ERROR, | 39 SYNC_STARTUP_ERROR, |
40 // Sync startup has completed (i.e. ProfileSyncService::IsSyncActive() | 40 // Sync startup has completed (i.e. ProfileSyncService::IsSyncActive() |
41 // returns true). | 41 // returns true). |
42 SYNC_STARTUP_COMPLETE | 42 SYNC_STARTUP_COMPLETE |
43 }; | 43 }; |
44 | 44 |
45 // Returns the current state of the sync service. | 45 // Returns the current state of the sync service. |
46 static SyncServiceState GetSyncServiceState(Profile* profile); | 46 static SyncServiceState GetSyncServiceState(Profile* profile); |
47 | 47 |
48 // sync_driver::SyncServiceObserver implementation. | 48 // syncer::SyncServiceObserver implementation. |
49 void OnStateChanged() override; | 49 void OnStateChanged() override; |
50 | 50 |
51 private: | 51 private: |
52 // Checks the current service state and notifies |observer_| if the state | 52 // Checks the current service state and notifies |observer_| if the state |
53 // has changed. Note that it is expected that the observer will free this | 53 // has changed. Note that it is expected that the observer will free this |
54 // object, so callers should not reference this object after making this call. | 54 // object, so callers should not reference this object after making this call. |
55 void CheckServiceState(); | 55 void CheckServiceState(); |
56 | 56 |
57 // Profile whose ProfileSyncService we should track. | 57 // Profile whose ProfileSyncService we should track. |
58 Profile* profile_; | 58 Profile* profile_; |
59 | 59 |
60 // Weak pointer to the observer to notify. | 60 // Weak pointer to the observer to notify. |
61 Observer* observer_; | 61 Observer* observer_; |
62 | 62 |
63 DISALLOW_COPY_AND_ASSIGN(SyncStartupTracker); | 63 DISALLOW_COPY_AND_ASSIGN(SyncStartupTracker); |
64 }; | 64 }; |
65 | 65 |
66 #endif // CHROME_BROWSER_SYNC_SYNC_STARTUP_TRACKER_H_ | 66 #endif // CHROME_BROWSER_SYNC_SYNC_STARTUP_TRACKER_H_ |
OLD | NEW |