Chromium Code Reviews| 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 "content/public/browser/notification_observer.h" | 8 #include "content/public/browser/notification_observer.h" |
| 9 #include "content/public/browser/notification_registrar.h" | 9 #include "content/public/browser/notification_registrar.h" |
| 10 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
| 11 #include "google_apis/gaia/google_service_auth_error.h" | 11 #include "google_apis/gaia/google_service_auth_error.h" |
| 12 #include "google_apis/gaia/oauth2_token_service.h" | |
| 12 | 13 |
| 13 class Profile; | 14 class Profile; |
| 14 | 15 |
| 15 // The signin flow logic is spread across several classes with varying | 16 // The signin flow logic is spread across several classes with varying |
| 16 // responsibilities: | 17 // responsibilities: |
| 17 // | 18 // |
| 18 // SigninTracker (this class) - This class listens to notifications from various | 19 // SigninTracker (this class) - This class listens to notifications from various |
| 19 // services (SigninManager, tokenService, etc) and coalesces them into | 20 // services (SigninManager, OAuth2TokenService) and coalesces them into |
| 20 // notifications for the UI layer. This is the class that encapsulates the logic | 21 // notifications for the UI layer. This is the class that encapsulates the logic |
| 21 // that determines whether a user is fully logged in or not, and exposes | 22 // that determines whether a user is fully logged in or not, and exposes |
| 22 // callbacks so various pieces of the UI (OneClickSyncStarter, SyncSetupHandler) | 23 // callbacks so various pieces of the UI (OneClickSyncStarter) can track the |
| 23 // can track the current startup state. | 24 // current startup state. |
| 24 // | 25 // |
| 25 // SyncSetupHandler - This class is primarily responsible for interacting with | 26 // SyncSetupHandler - This class is primarily responsible for interacting with |
| 26 // the web UI for performing system login and sync configuration. Receives | 27 // the web UI for performing system login and sync configuration. Receives |
| 27 // callbacks from the UI when the user wishes to initiate a login, and | 28 // callbacks from the UI when the user wishes to initiate a login, and |
| 28 // translates system state (login errors, etc) into the appropriate calls into | 29 // translates system state (login errors, etc) into the appropriate calls into |
| 29 // the UI to reflect this status to the user. | 30 // the UI to reflect this status to the user. |
| 30 // | 31 // |
| 31 // LoginUIService - Our desktop UI flows rely on having only a single login flow | 32 // LoginUIService - Our desktop UI flows rely on having only a single login flow |
| 32 // visible to the user at once. This is achieved via LoginUIService | 33 // visible to the user at once. This is achieved via LoginUIService |
| 33 // (a BrowserContextKeyedService that keeps track of the currently visible | 34 // (a BrowserContextKeyedService that keeps track of the currently visible |
| 34 // login UI). | 35 // login UI). |
| 35 // | 36 // |
| 36 // SigninManager - Records the currently-logged-in user and handles all | 37 // SigninManager - Records the currently-logged-in user and handles all |
| 37 // interaction with the GAIA backend during the signin process. Unlike | 38 // interaction with the GAIA backend during the signin process. Unlike |
| 38 // SigninTracker, SigninManager only knows about the GAIA login state and is | 39 // SigninTracker, SigninManager only knows about the GAIA login state and is |
| 39 // not aware of the state of any signed in services. | 40 // not aware of the state of any signed in services. |
| 40 // | 41 // |
| 41 // TokenService - Uses credentials provided by SigninManager to generate tokens | 42 // TokenService - Uses credentials provided by SigninManager to generate tokens |
| 42 // for all signed-in services in Chrome. | 43 // for all signed-in services in Chrome. |
| 43 // | 44 // |
| 45 // OAuth2TokenService - Maintains and manages OAuth2 tokens for the accounts | |
| 46 // connected to this profile. | |
| 47 // | |
| 44 // ProfileSyncService - Provides the external API for interacting with the | 48 // ProfileSyncService - Provides the external API for interacting with the |
| 45 // sync framework. Listens for notifications from the TokenService to know | 49 // sync framework. Listens for notifications from the TokenService to know |
| 46 // when to startup sync, and provides an Observer interface to notify the UI | 50 // when to startup sync, and provides an Observer interface to notify the UI |
| 47 // layer of changes in sync state so they can be reflected in the UI. | 51 // layer of changes in sync state so they can be reflected in the UI. |
| 48 class SigninTracker : public content::NotificationObserver { | 52 class SigninTracker : public content::NotificationObserver, |
| 53 public OAuth2TokenService::Observer { | |
| 49 public: | 54 public: |
| 50 class Observer { | 55 class Observer { |
| 51 public: | 56 public: |
| 52 // The signin attempt failed, and the cause is passed in |error|. | 57 // The signin attempt failed, and the cause is passed in |error|. |
| 53 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0; | 58 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0; |
| 54 | 59 |
| 55 // The signin attempt succeeded. | 60 // The signin attempt succeeded. |
| 56 virtual void SigninSuccess() = 0; | 61 virtual void SigninSuccess() = 0; |
| 57 }; | 62 }; |
| 58 | 63 |
| 59 // The various states the login process can be in. | 64 // The various states the login process can be in. |
| 60 enum LoginState { | 65 enum LoginState { |
| 61 WAITING_FOR_GAIA_VALIDATION, | 66 WAITING_FOR_GAIA_VALIDATION, |
| 62 SERVICES_INITIALIZING, | 67 SERVICES_INITIALIZING, |
| 63 SIGNIN_COMPLETE | 68 SIGNIN_COMPLETE |
| 64 }; | 69 }; |
| 65 | 70 |
| 66 // Creates a SigninTracker that tracks the signin status on the passed | 71 // Creates a SigninTracker that tracks the signin status on the passed |
| 67 // |profile|, and notifies the |observer| on status changes. |observer| must | 72 // |profile|, and notifies the |observer| on status changes. |observer| must |
| 68 // be non-null and must outlive the SigninTracker. | 73 // be non-null and must outlive the SigninTracker. |
| 69 SigninTracker(Profile* profile, Observer* observer); | 74 SigninTracker(Profile* profile, Observer* observer); |
| 70 virtual ~SigninTracker(); | 75 virtual ~SigninTracker(); |
| 71 | 76 |
| 72 // content::NotificationObserver implementation. | 77 // content::NotificationObserver implementation. |
| 73 virtual void Observe(int type, | 78 virtual void Observe(int type, |
| 74 const content::NotificationSource& source, | 79 const content::NotificationSource& source, |
| 75 const content::NotificationDetails& details) OVERRIDE; | 80 const content::NotificationDetails& details) OVERRIDE; |
| 76 | 81 |
| 82 // OAuth2TokenService::Observer implementation. | |
| 83 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | |
| 84 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | |
| 85 | |
| 77 // Returns true if the tokens are loaded for all signed-in services. | 86 // Returns true if the tokens are loaded for all signed-in services. |
| 78 static bool AreServiceTokensLoaded(Profile* profile); | 87 static bool AreServiceTokensLoaded(Profile* profile); |
|
Andrew T Wilson (Slow)
2013/08/31 14:04:10
Nobody outside SigninTracker calls this any more -
Roger Tawa OOO till Jul 10th
2013/09/07 14:03:38
Done.
| |
| 79 | 88 |
| 80 // Returns the sign in state for |profile|. If the profile is not signed in, | 89 // Returns the sign in state for |profile|. If the profile is not signed in, |
| 81 // or is authenticating with GAIA, WAITING_FOR_GAIA_VALIDATION is returned. | 90 // or is authenticating with GAIA, WAITING_FOR_GAIA_VALIDATION is returned. |
| 82 // If SigninManager in has completed but TokenService is not ready, | 91 // If SigninManager in has completed but TokenService is not ready, |
| 83 // SERVICES_INITIALIZING is returned. Otherwise SIGNIN_COMPLETE is returned. | 92 // SERVICES_INITIALIZING is returned. Otherwise SIGNIN_COMPLETE is returned. |
| 84 static LoginState GetSigninState(Profile* profile, | 93 static LoginState GetSigninState(Profile* profile, |
|
Andrew T Wilson (Slow)
2013/08/31 14:04:10
I think this is pretty much obsolete as public API
Roger Tawa OOO till Jul 10th
2013/09/07 14:03:38
Done.
| |
| 85 GoogleServiceAuthError* error); | 94 GoogleServiceAuthError* error); |
| 86 | 95 |
| 87 private: | 96 private: |
| 88 // Initializes this by adding notifications and observers. | 97 // Initializes this by adding notifications and observers. |
| 89 void Initialize(); | 98 void Initialize(); |
| 90 | 99 |
| 91 // Invoked when one of the services potentially changed its signin status so | 100 // Invoked when one of the services potentially changed its signin status so |
| 92 // we can check to see whether we need to notify our observer. | 101 // we can check to see whether we need to notify our observer. |
| 93 void HandleServiceStateChange(); | 102 void HandleServiceStateChange(); |
| 94 | 103 |
| 95 // The current state of the login process. | 104 // The current state of the login process. |
| 96 LoginState state_; | 105 LoginState state_; |
| 97 | 106 |
| 98 // The profile whose signin status we are tracking. | 107 // The profile whose signin status we are tracking. |
| 99 Profile* profile_; | 108 Profile* profile_; |
| 100 | 109 |
| 101 // Weak pointer to the observer we call when the signin state changes. | 110 // Weak pointer to the observer we call when the signin state changes. |
| 102 Observer* observer_; | 111 Observer* observer_; |
| 103 | 112 |
| 104 // Set to true when SigninManager has validated our credentials. | 113 // Set to true when SigninManager has validated our credentials. |
| 105 bool credentials_valid_; | 114 bool credentials_valid_; |
| 106 | 115 |
| 107 // Used to listen to notifications from the SigninManager. | 116 // Used to listen to notifications from the SigninManager. |
| 108 content::NotificationRegistrar registrar_; | 117 content::NotificationRegistrar registrar_; |
| 109 | 118 |
| 110 DISALLOW_COPY_AND_ASSIGN(SigninTracker); | 119 DISALLOW_COPY_AND_ASSIGN(SigninTracker); |
| 111 }; | 120 }; |
| 112 | 121 |
| 113 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ | 122 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ |
| OLD | NEW |