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_SIGNIN_SIGNIN_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ |
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ | 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ |
7 | 7 |
8 #include "chrome/browser/sync/profile_sync_service_observer.h" | 8 #include "chrome/browser/sync/profile_sync_service_observer.h" |
9 #include "chrome/common/net/gaia/google_service_auth_error.h" | 9 #include "chrome/common/net/gaia/google_service_auth_error.h" |
10 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 virtual void GaiaCredentialsValid() = 0; | 56 virtual void GaiaCredentialsValid() = 0; |
57 | 57 |
58 // The signin attempt failed. If this is called after GaiaCredentialsValid() | 58 // The signin attempt failed. If this is called after GaiaCredentialsValid() |
59 // then it means there was an error launching one of the dependent services. | 59 // then it means there was an error launching one of the dependent services. |
60 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0; | 60 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0; |
61 | 61 |
62 // The signin attempt succeeded. | 62 // The signin attempt succeeded. |
63 virtual void SigninSuccess() = 0; | 63 virtual void SigninSuccess() = 0; |
64 }; | 64 }; |
65 | 65 |
| 66 // The various states the login process can be in. |
| 67 enum LoginState { |
| 68 WAITING_FOR_GAIA_VALIDATION, |
| 69 SERVICES_INITIALIZING, |
| 70 SIGNIN_COMPLETE |
| 71 }; |
| 72 |
66 // Creates a SigninTracker that tracks the signin status on the passed | 73 // Creates a SigninTracker that tracks the signin status on the passed |
67 // |profile|, and notifies the |observer| on status changes. |observer| must | 74 // |profile|, and notifies the |observer| on status changes. |observer| must |
68 // be non-null and must outlive the SigninTracker. | 75 // be non-null and must outlive the SigninTracker. |
69 SigninTracker(Profile* profile, Observer* observer); | 76 SigninTracker(Profile* profile, Observer* observer); |
| 77 SigninTracker(Profile* profile, Observer* observer, LoginState state); |
70 virtual ~SigninTracker(); | 78 virtual ~SigninTracker(); |
71 | 79 |
72 // content::NotificationObserver implementation. | 80 // content::NotificationObserver implementation. |
73 virtual void Observe(int type, | 81 virtual void Observe(int type, |
74 const content::NotificationSource& source, | 82 const content::NotificationSource& source, |
75 const content::NotificationDetails& details) OVERRIDE; | 83 const content::NotificationDetails& details) OVERRIDE; |
76 | 84 |
77 // ProfileSyncServiceObserver implementation. | 85 // ProfileSyncServiceObserver implementation. |
78 virtual void OnStateChanged() OVERRIDE; | 86 virtual void OnStateChanged() OVERRIDE; |
79 | 87 |
80 // Returns true if the various authenticated services are properly signed in | 88 // Returns true if the various authenticated services are properly signed in |
81 // (all tokens loaded, no auth/startup errors, etc). | 89 // (all tokens loaded, no auth/startup errors, etc). |
82 static bool AreServicesSignedIn(Profile* profile); | 90 static bool AreServicesSignedIn(Profile* profile); |
83 | 91 |
84 // Returns true if the tokens are loaded for all signed-in services. | 92 // Returns true if the tokens are loaded for all signed-in services. |
85 static bool AreServiceTokensLoaded(Profile* profile); | 93 static bool AreServiceTokensLoaded(Profile* profile); |
86 | 94 |
87 private: | 95 private: |
88 // The various states the login process can be in. | 96 // Initializes this by adding notifications and observers. |
89 enum LoginState { | 97 void Initialize(); |
90 WAITING_FOR_GAIA_VALIDATION, | |
91 SERVICES_INITIALIZING, | |
92 SIGNIN_COMPLETE | |
93 }; | |
94 | 98 |
95 // Invoked when one of the services potentially changed its signin status so | 99 // Invoked when one of the services potentially changed its signin status so |
96 // we can check to see whether we need to notify our observer. | 100 // we can check to see whether we need to notify our observer. |
97 void HandleServiceStateChange(); | 101 void HandleServiceStateChange(); |
98 | 102 |
99 // The current state of the login process. | 103 // The current state of the login process. |
100 LoginState state_; | 104 LoginState state_; |
101 | 105 |
102 // The profile whose signin status we are tracking. | 106 // The profile whose signin status we are tracking. |
103 Profile* profile_; | 107 Profile* profile_; |
104 | 108 |
105 // Weak pointer to the observer we call when the signin state changes. | 109 // Weak pointer to the observer we call when the signin state changes. |
106 Observer* observer_; | 110 Observer* observer_; |
107 | 111 |
108 // Set to true when SigninManager has validated our credentials. | 112 // Set to true when SigninManager has validated our credentials. |
109 bool credentials_valid_; | 113 bool credentials_valid_; |
110 | 114 |
111 // Used to listen to notifications from the SigninManager. | 115 // Used to listen to notifications from the SigninManager. |
112 content::NotificationRegistrar registrar_; | 116 content::NotificationRegistrar registrar_; |
113 | 117 |
114 DISALLOW_COPY_AND_ASSIGN(SigninTracker); | 118 DISALLOW_COPY_AND_ASSIGN(SigninTracker); |
115 }; | 119 }; |
116 | 120 |
117 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ | 121 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ |
118 | |
OLD | NEW |