| 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 COMPONENTS_SIGNIN_CORE_BROWSER_ABOUT_SIGNIN_INTERNALS_H_ | 5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ABOUT_SIGNIN_INTERNALS_H_ |
| 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_ABOUT_SIGNIN_INTERNALS_H_ | 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_ABOUT_SIGNIN_INTERNALS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
| 16 #include "components/signin/core/browser/signin_client.h" | 16 #include "components/signin/core/browser/signin_client.h" |
| 17 #include "components/signin/core/browser/signin_internals_util.h" | 17 #include "components/signin/core/browser/signin_internals_util.h" |
| 18 #include "components/signin/core/browser/signin_manager.h" | 18 #include "components/signin/core/browser/signin_manager.h" |
| 19 #include "google_apis/gaia/gaia_auth_consumer.h" | 19 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 20 #include "google_apis/gaia/oauth2_token_service.h" | 20 #include "google_apis/gaia/oauth2_token_service.h" |
| 21 | 21 |
| 22 class AccountTrackerService; |
| 22 class GaiaAuthFetcher; | 23 class GaiaAuthFetcher; |
| 23 class ProfileOAuth2TokenService; | 24 class ProfileOAuth2TokenService; |
| 24 class SigninClient; | 25 class SigninClient; |
| 25 class SigninManagerBase; | |
| 26 | 26 |
| 27 // Many values in SigninStatus are also associated with a timestamp. | 27 // Many values in SigninStatus are also associated with a timestamp. |
| 28 // This makes it easier to keep values and their associated times together. | 28 // This makes it easier to keep values and their associated times together. |
| 29 typedef std::pair<std::string, std::string> TimedSigninStatusValue; | 29 typedef std::pair<std::string, std::string> TimedSigninStatusValue; |
| 30 | 30 |
| 31 // This class collects authentication, signin and token information | 31 // This class collects authentication, signin and token information |
| 32 // to propagate to about:signin-internals via SigninInternalsUI. | 32 // to propagate to about:signin-internals via SigninInternalsUI. |
| 33 class AboutSigninInternals | 33 class AboutSigninInternals |
| 34 : public KeyedService, | 34 : public KeyedService, |
| 35 public signin_internals_util::SigninDiagnosticsObserver, | 35 public signin_internals_util::SigninDiagnosticsObserver, |
| 36 public OAuth2TokenService::DiagnosticsObserver, | 36 public OAuth2TokenService::DiagnosticsObserver, |
| 37 public GaiaAuthConsumer { | 37 public GaiaAuthConsumer, |
| 38 SigninManagerBase::Observer { |
| 38 public: | 39 public: |
| 39 class Observer { | 40 class Observer { |
| 40 public: | 41 public: |
| 41 // |info| will contain the dictionary of signin_status_ values as indicated | 42 // |info| will contain the dictionary of signin_status_ values as indicated |
| 42 // in the comments for GetSigninStatus() below. | 43 // in the comments for GetSigninStatus() below. |
| 43 virtual void OnSigninStateChanged(const base::DictionaryValue* info) = 0; | 44 virtual void OnSigninStateChanged(const base::DictionaryValue* info) = 0; |
| 44 | 45 |
| 45 // Notification that the cookie accounts are ready to be displayed. | 46 // Notification that the cookie accounts are ready to be displayed. |
| 46 virtual void OnCookieAccountsFetched(const base::DictionaryValue* info) = 0; | 47 virtual void OnCookieAccountsFetched(const base::DictionaryValue* info) = 0; |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 AboutSigninInternals(ProfileOAuth2TokenService* token_service, | 50 AboutSigninInternals(ProfileOAuth2TokenService* token_service, |
| 51 AccountTrackerService* account_tracker, |
| 50 SigninManagerBase* signin_manager); | 52 SigninManagerBase* signin_manager); |
| 51 ~AboutSigninInternals() override; | 53 ~AboutSigninInternals() override; |
| 52 | 54 |
| 53 // Each instance of SigninInternalsUI adds itself as an observer to be | 55 // Each instance of SigninInternalsUI adds itself as an observer to be |
| 54 // notified of all updates that AboutSigninInternals receives. | 56 // notified of all updates that AboutSigninInternals receives. |
| 55 void AddSigninObserver(Observer* observer); | 57 void AddSigninObserver(Observer* observer); |
| 56 void RemoveSigninObserver(Observer* observer); | 58 void RemoveSigninObserver(Observer* observer); |
| 57 | 59 |
| 58 // Pulls all signin values that have been persisted in the user prefs. | 60 // Pulls all signin values that have been persisted in the user prefs. |
| 59 void RefreshSigninPrefs(); | 61 void RefreshSigninPrefs(); |
| 60 | 62 |
| 61 // SigninManager::SigninDiagnosticsObserver implementation. | 63 void Initialize(SigninClient* client); |
| 62 void NotifySigninValueChanged( | |
| 63 const signin_internals_util::UntimedSigninStatusField& field, | |
| 64 const std::string& value) override; | |
| 65 | 64 |
| 66 void NotifySigninValueChanged( | 65 void OnRefreshTokenReceived(std::string status); |
| 67 const signin_internals_util::TimedSigninStatusField& field, | 66 void OnAuthenticationResultReceived(std::string status); |
| 68 const std::string& value) override; | |
| 69 | |
| 70 void Initialize(SigninClient* client); | |
| 71 | 67 |
| 72 // KeyedService implementation. | 68 // KeyedService implementation. |
| 73 void Shutdown() override; | 69 void Shutdown() override; |
| 74 | 70 |
| 75 // Returns a dictionary of values in signin_status_ for use in | 71 // Returns a dictionary of values in signin_status_ for use in |
| 76 // about:signin-internals. The values are formatted as shown - | 72 // about:signin-internals. The values are formatted as shown - |
| 77 // | 73 // |
| 78 // { "signin_info" : | 74 // { "signin_info" : |
| 79 // [ {"title": "Basic Information", | 75 // [ {"title": "Basic Information", |
| 80 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] | 76 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] |
| 81 // }, | 77 // }, |
| 82 // { "title": "Detailed Information", | 78 // { "title": "Detailed Information", |
| 83 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] | 79 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] |
| 84 // }], | 80 // }], |
| 85 // "token_info" : | 81 // "token_info" : |
| 86 // [ List of {"name": "foo-name", "token" : "foo-token", | 82 // [ List of {"name": "foo-name", "token" : "foo-token", |
| 87 // "status": "foo_stat", "time" : "foo_time"} elems] | 83 // "status": "foo_stat", "time" : "foo_time"} elems] |
| 88 // } | 84 // } |
| 89 scoped_ptr<base::DictionaryValue> GetSigninStatus(); | 85 scoped_ptr<base::DictionaryValue> GetSigninStatus(); |
| 90 | 86 |
| 91 // Triggers a ListAccounts call to acquire a list of the email addresses | 87 // Triggers a ListAccounts call to acquire a list of the email addresses |
| 92 // corresponding to the cookies residing on the current cookie jar. | 88 // corresponding to the cookies residing on the current cookie jar. |
| 93 void GetCookieAccountsAsync(); | 89 void GetCookieAccountsAsync(); |
| 94 | 90 |
| 95 // OAuth2TokenService::DiagnosticsObserver implementations. | |
| 96 void OnAccessTokenRequested( | |
| 97 const std::string& account_id, | |
| 98 const std::string& consumer_id, | |
| 99 const OAuth2TokenService::ScopeSet& scopes) override; | |
| 100 void OnFetchAccessTokenComplete(const std::string& account_id, | |
| 101 const std::string& consumer_id, | |
| 102 const OAuth2TokenService::ScopeSet& scopes, | |
| 103 GoogleServiceAuthError error, | |
| 104 base::Time expiration_time) override; | |
| 105 void OnTokenRemoved(const std::string& account_id, | |
| 106 const OAuth2TokenService::ScopeSet& scopes) override; | |
| 107 | |
| 108 void OnRefreshTokenReceived(std::string status); | |
| 109 void OnAuthenticationResultReceived(std::string status); | |
| 110 | |
| 111 private: | 91 private: |
| 112 // Encapsulates diagnostic information about tokens for different services. | 92 // Encapsulates diagnostic information about tokens for different services. |
| 113 struct TokenInfo { | 93 struct TokenInfo { |
| 114 TokenInfo(const std::string& consumer_id, | 94 TokenInfo(const std::string& consumer_id, |
| 115 const OAuth2TokenService::ScopeSet& scopes); | 95 const OAuth2TokenService::ScopeSet& scopes); |
| 116 ~TokenInfo(); | 96 ~TokenInfo(); |
| 117 base::DictionaryValue* ToValue() const; | 97 base::DictionaryValue* ToValue() const; |
| 118 | 98 |
| 119 static bool LessThan(const TokenInfo* a, const TokenInfo* b); | 99 static bool LessThan(const TokenInfo* a, const TokenInfo* b); |
| 120 | 100 |
| 121 // Called when the token is invalidated. | 101 // Called when the token is invalidated. |
| 122 void Invalidate(); | 102 void Invalidate(); |
| 123 | 103 |
| 124 std::string consumer_id; // service that requested the token. | 104 std::string consumer_id; // service that requested the token. |
| 125 OAuth2TokenService::ScopeSet scopes; // Scoped that are requested. | 105 OAuth2TokenService::ScopeSet scopes; // Scoped that are requested. |
| 126 base::Time request_time; | 106 base::Time request_time; |
| 127 base::Time receive_time; | 107 base::Time receive_time; |
| 128 base::Time expiration_time; | 108 base::Time expiration_time; |
| 129 GoogleServiceAuthError error; | 109 GoogleServiceAuthError error; |
| 130 bool removed_; | 110 bool removed_; |
| 131 }; | 111 }; |
| 132 | 112 |
| 133 // Map account id to tokens associated to the account. | 113 // Map account id to tokens associated to the account. |
| 134 typedef std::map<std::string, std::vector<TokenInfo*> > TokenInfoMap; | 114 typedef std::map<std::string, std::vector<TokenInfo*> > TokenInfoMap; |
| 135 | 115 |
| 136 // Encapsulates both authentication and token related information. Used | 116 // Encapsulates both authentication and token related information. Used |
| 137 // by SigninInternals to maintain information that needs to be shown in | 117 // by SigninInternals to maintain information that needs to be shown in |
| 138 // the about:signin-internals page. | 118 // the about:signin-internals page. |
| 139 struct SigninStatus { | 119 struct SigninStatus { |
| 140 std::vector<std::string> untimed_signin_fields; | |
| 141 std::vector<TimedSigninStatusValue> timed_signin_fields; | 120 std::vector<TimedSigninStatusValue> timed_signin_fields; |
| 142 TokenInfoMap token_info_map; | 121 TokenInfoMap token_info_map; |
| 143 | 122 |
| 144 SigninStatus(); | 123 SigninStatus(); |
| 145 ~SigninStatus(); | 124 ~SigninStatus(); |
| 146 | 125 |
| 147 TokenInfo* FindToken(const std::string& account_id, | 126 TokenInfo* FindToken(const std::string& account_id, |
| 148 const std::string& consumer_id, | 127 const std::string& consumer_id, |
| 149 const OAuth2TokenService::ScopeSet& scopes); | 128 const OAuth2TokenService::ScopeSet& scopes); |
| 150 | 129 |
| 151 // Returns a dictionary with the following form: | 130 // Returns a dictionary with the following form: |
| 152 // { "signin_info" : | 131 // { "signin_info" : |
| 153 // [ {"title": "Basic Information", | 132 // [ {"title": "Basic Information", |
| 154 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] | 133 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] |
| 155 // }, | 134 // }, |
| 156 // { "title": "Detailed Information", | 135 // { "title": "Detailed Information", |
| 157 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] | 136 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] |
| 158 // }], | 137 // }], |
| 159 // "token_info" : | 138 // "token_info" : |
| 160 // [ List of | 139 // [ List of |
| 161 // { "title": account id, | 140 // { "title": account id, |
| 162 // "data": [List of {"service" : service name, | 141 // "data": [List of {"service" : service name, |
| 163 // "scopes" : requested scoped, | 142 // "scopes" : requested scoped, |
| 164 // "request_time" : request time, | 143 // "request_time" : request time, |
| 165 // "status" : request status} elems] | 144 // "status" : request status} elems] |
| 166 // }], | 145 // }], |
| 167 // } | 146 // } |
| 168 scoped_ptr<base::DictionaryValue> ToValue(std::string product_version); | 147 scoped_ptr<base::DictionaryValue> ToValue( |
| 148 AccountTrackerService* account_tracker, |
| 149 SigninManagerBase* signin_manager, |
| 150 const std::string& product_version); |
| 169 }; | 151 }; |
| 170 | 152 |
| 171 void NotifyObservers(); | 153 // SigninManager::SigninDiagnosticsObserver implementation. |
| 154 void NotifySigninValueChanged( |
| 155 const signin_internals_util::TimedSigninStatusField& field, |
| 156 const std::string& value) override; |
| 172 | 157 |
| 158 // OAuth2TokenService::DiagnosticsObserver implementations. |
| 159 void OnAccessTokenRequested( |
| 160 const std::string& account_id, |
| 161 const std::string& consumer_id, |
| 162 const OAuth2TokenService::ScopeSet& scopes) override; |
| 163 void OnFetchAccessTokenComplete(const std::string& account_id, |
| 164 const std::string& consumer_id, |
| 165 const OAuth2TokenService::ScopeSet& scopes, |
| 166 GoogleServiceAuthError error, |
| 167 base::Time expiration_time) override; |
| 168 void OnTokenRemoved(const std::string& account_id, |
| 169 const OAuth2TokenService::ScopeSet& scopes) override; |
| 173 | 170 |
| 174 // Overriden from GaiaAuthConsumer. | 171 // GaiaAuthConsumer implementations. |
| 175 void OnListAccountsSuccess(const std::string& data) override; | 172 void OnListAccountsSuccess(const std::string& data) override; |
| 176 void OnListAccountsFailure(const GoogleServiceAuthError& error) override; | 173 void OnListAccountsFailure(const GoogleServiceAuthError& error) override; |
| 177 | 174 |
| 175 // SigninManagerBase::Observer implementations. |
| 176 void GoogleSigninFailed(const GoogleServiceAuthError& error) override; |
| 177 void GoogleSigninSucceeded(const std::string& account_id, |
| 178 const std::string& username, |
| 179 const std::string& password) override; |
| 180 void GoogleSignedOut(const std::string& account_id, |
| 181 const std::string& username) override; |
| 182 |
| 183 void NotifyObservers(); |
| 184 |
| 178 // Callback for ListAccounts. Once the email addresses are fetched from GAIA, | 185 // Callback for ListAccounts. Once the email addresses are fetched from GAIA, |
| 179 // they are pushed to the signin_internals_ui. | 186 // they are pushed to the signin_internals_ui. |
| 180 void OnListAccountsComplete( | 187 void OnListAccountsComplete( |
| 181 std::vector<std::pair<std::string, bool> >& gaia_accounts); | 188 std::vector<std::pair<std::string, bool> >& gaia_accounts); |
| 182 | 189 |
| 183 // Called when a cookie changes. If the cookie relates to a GAIA LSID cookie, | 190 // Called when a cookie changes. If the cookie relates to a GAIA LSID cookie, |
| 184 // then we call ListAccounts and update the UI element. | 191 // then we call ListAccounts and update the UI element. |
| 185 void OnCookieChanged(const net::CanonicalCookie& cookie, bool removed); | 192 void OnCookieChanged(const net::CanonicalCookie& cookie, bool removed); |
| 186 | 193 |
| 187 // Weak pointer to the token service. | 194 // Weak pointer to the token service. |
| 188 ProfileOAuth2TokenService* token_service_; | 195 ProfileOAuth2TokenService* token_service_; |
| 189 | 196 |
| 197 // Weak pointer to the account tracker. |
| 198 AccountTrackerService* account_tracker_; |
| 199 |
| 190 // Weak pointer to the signin manager. | 200 // Weak pointer to the signin manager. |
| 191 SigninManagerBase* signin_manager_; | 201 SigninManagerBase* signin_manager_; |
| 192 | 202 |
| 193 // Weak pointer to the client. | 203 // Weak pointer to the client. |
| 194 SigninClient* client_; | 204 SigninClient* client_; |
| 195 | 205 |
| 196 // Fetcher for information about accounts in the cookie jar from GAIA. | 206 // Fetcher for information about accounts in the cookie jar from GAIA. |
| 197 scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; | 207 scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; |
| 198 | 208 |
| 199 // Encapsulates the actual signin and token related values. | 209 // Encapsulates the actual signin and token related values. |
| 200 // Most of the values are mirrored in the prefs for persistence. | 210 // Most of the values are mirrored in the prefs for persistence. |
| 201 SigninStatus signin_status_; | 211 SigninStatus signin_status_; |
| 202 | 212 |
| 203 ObserverList<Observer> signin_observers_; | 213 ObserverList<Observer> signin_observers_; |
| 204 | 214 |
| 205 scoped_ptr<SigninClient::CookieChangedSubscription> | 215 scoped_ptr<SigninClient::CookieChangedSubscription> |
| 206 cookie_changed_subscription_; | 216 cookie_changed_subscription_; |
| 207 | 217 |
| 208 DISALLOW_COPY_AND_ASSIGN(AboutSigninInternals); | 218 DISALLOW_COPY_AND_ASSIGN(AboutSigninInternals); |
| 209 }; | 219 }; |
| 210 | 220 |
| 211 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ABOUT_SIGNIN_INTERNALS_H_ | 221 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ABOUT_SIGNIN_INTERNALS_H_ |
| OLD | NEW |