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/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
| 15 #include "components/signin/core/browser/signin_client.h" |
15 #include "components/signin/core/browser/signin_internals_util.h" | 16 #include "components/signin/core/browser/signin_internals_util.h" |
16 #include "components/signin/core/browser/signin_manager.h" | 17 #include "components/signin/core/browser/signin_manager.h" |
| 18 #include "google_apis/gaia/gaia_auth_consumer.h" |
17 #include "google_apis/gaia/oauth2_token_service.h" | 19 #include "google_apis/gaia/oauth2_token_service.h" |
18 | 20 |
| 21 class GaiaAuthFetcher; |
19 class ProfileOAuth2TokenService; | 22 class ProfileOAuth2TokenService; |
20 class SigninClient; | 23 class SigninClient; |
21 class SigninManagerBase; | 24 class SigninManagerBase; |
22 | 25 |
23 // Many values in SigninStatus are also associated with a timestamp. | 26 // Many values in SigninStatus are also associated with a timestamp. |
24 // This makes it easier to keep values and their associated times together. | 27 // This makes it easier to keep values and their associated times together. |
25 typedef std::pair<std::string, std::string> TimedSigninStatusValue; | 28 typedef std::pair<std::string, std::string> TimedSigninStatusValue; |
26 | 29 |
27 // This class collects authentication, signin and token information | 30 // This class collects authentication, signin and token information |
28 // to propagate to about:signin-internals via SigninInternalsUI. | 31 // to propagate to about:signin-internals via SigninInternalsUI. |
29 class AboutSigninInternals | 32 class AboutSigninInternals |
30 : public KeyedService, | 33 : public KeyedService, |
31 public signin_internals_util::SigninDiagnosticsObserver, | 34 public signin_internals_util::SigninDiagnosticsObserver, |
32 public OAuth2TokenService::DiagnosticsObserver { | 35 public OAuth2TokenService::DiagnosticsObserver, |
| 36 public GaiaAuthConsumer { |
33 public: | 37 public: |
34 class Observer { | 38 class Observer { |
35 public: | 39 public: |
36 // |info| will contain the dictionary of signin_status_ values as indicated | 40 // |info| will contain the dictionary of signin_status_ values as indicated |
37 // in the comments for GetSigninStatus() below. | 41 // in the comments for GetSigninStatus() below. |
38 virtual void OnSigninStateChanged( | 42 virtual void OnSigninStateChanged( |
39 scoped_ptr<base::DictionaryValue> info) = 0; | 43 scoped_ptr<base::DictionaryValue> info) = 0; |
| 44 |
| 45 // Notification that the cookie accounts are ready to be displayed. |
| 46 virtual void OnCookieAccountsFetched( |
| 47 scoped_ptr<base::DictionaryValue> info) = 0; |
40 }; | 48 }; |
41 | 49 |
42 AboutSigninInternals(ProfileOAuth2TokenService* token_service, | 50 AboutSigninInternals(ProfileOAuth2TokenService* token_service, |
43 SigninManagerBase* signin_manager); | 51 SigninManagerBase* signin_manager); |
44 virtual ~AboutSigninInternals(); | 52 virtual ~AboutSigninInternals(); |
45 | 53 |
46 // Each instance of SigninInternalsUI adds itself as an observer to be | 54 // Each instance of SigninInternalsUI adds itself as an observer to be |
47 // notified of all updates that AboutSigninInternals receives. | 55 // notified of all updates that AboutSigninInternals receives. |
48 void AddSigninObserver(Observer* observer); | 56 void AddSigninObserver(Observer* observer); |
49 void RemoveSigninObserver(Observer* observer); | 57 void RemoveSigninObserver(Observer* observer); |
(...skipping 24 matching lines...) Expand all Loading... |
74 // }, | 82 // }, |
75 // { "title": "Detailed Information", | 83 // { "title": "Detailed Information", |
76 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] | 84 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] |
77 // }], | 85 // }], |
78 // "token_info" : | 86 // "token_info" : |
79 // [ List of {"name": "foo-name", "token" : "foo-token", | 87 // [ List of {"name": "foo-name", "token" : "foo-token", |
80 // "status": "foo_stat", "time" : "foo_time"} elems] | 88 // "status": "foo_stat", "time" : "foo_time"} elems] |
81 // } | 89 // } |
82 scoped_ptr<base::DictionaryValue> GetSigninStatus(); | 90 scoped_ptr<base::DictionaryValue> GetSigninStatus(); |
83 | 91 |
| 92 // Triggers a ListAccounts call to acquire a list of the email addresses |
| 93 // corresponding to the cookies residing on the current cookie jar. |
| 94 void GetCookieAccountsAsync(); |
| 95 |
84 // OAuth2TokenService::DiagnosticsObserver implementations. | 96 // OAuth2TokenService::DiagnosticsObserver implementations. |
85 virtual void OnAccessTokenRequested( | 97 virtual void OnAccessTokenRequested( |
86 const std::string& account_id, | 98 const std::string& account_id, |
87 const std::string& consumer_id, | 99 const std::string& consumer_id, |
88 const OAuth2TokenService::ScopeSet& scopes) OVERRIDE; | 100 const OAuth2TokenService::ScopeSet& scopes) OVERRIDE; |
89 virtual void OnFetchAccessTokenComplete( | 101 virtual void OnFetchAccessTokenComplete( |
90 const std::string& account_id, | 102 const std::string& account_id, |
91 const std::string& consumer_id, | 103 const std::string& consumer_id, |
92 const OAuth2TokenService::ScopeSet& scopes, | 104 const OAuth2TokenService::ScopeSet& scopes, |
93 GoogleServiceAuthError error, | 105 GoogleServiceAuthError error, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // "scopes" : requested scoped, | 166 // "scopes" : requested scoped, |
155 // "request_time" : request time, | 167 // "request_time" : request time, |
156 // "status" : request status} elems] | 168 // "status" : request status} elems] |
157 // }], | 169 // }], |
158 // } | 170 // } |
159 scoped_ptr<base::DictionaryValue> ToValue(std::string product_version); | 171 scoped_ptr<base::DictionaryValue> ToValue(std::string product_version); |
160 }; | 172 }; |
161 | 173 |
162 void NotifyObservers(); | 174 void NotifyObservers(); |
163 | 175 |
| 176 |
| 177 // Overriden from GaiaAuthConsumer. |
| 178 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; |
| 179 virtual void OnListAccountsFailure(const GoogleServiceAuthError& error) |
| 180 OVERRIDE; |
| 181 |
| 182 // Callback for ListAccounts. Once the email addresses are fetched from GAIA, |
| 183 // they are pushed to the signin_internals_ui. |
| 184 void OnListAccountsComplete( |
| 185 std::vector<std::pair<std::string, bool> >& gaia_accounts); |
| 186 |
| 187 // Called when a cookie changes. If the cookie relates to a GAIA LSID cookie, |
| 188 // then we call ListAccounts and update the UI element. |
| 189 void OnCookieChanged(const net::CanonicalCookie* cookie); |
| 190 |
164 // Weak pointer to the token service. | 191 // Weak pointer to the token service. |
165 ProfileOAuth2TokenService* token_service_; | 192 ProfileOAuth2TokenService* token_service_; |
166 | 193 |
167 // Weak pointer to the signin manager. | 194 // Weak pointer to the signin manager. |
168 SigninManagerBase* signin_manager_; | 195 SigninManagerBase* signin_manager_; |
169 | 196 |
170 // Weak pointer to the client. | 197 // Weak pointer to the client. |
171 SigninClient* client_; | 198 SigninClient* client_; |
172 | 199 |
| 200 // Fetcher for information about accounts in the cookie jar from GAIA. |
| 201 scoped_ptr<GaiaAuthFetcher> gaia_fetcher_; |
| 202 |
173 // Encapsulates the actual signin and token related values. | 203 // Encapsulates the actual signin and token related values. |
174 // Most of the values are mirrored in the prefs for persistence. | 204 // Most of the values are mirrored in the prefs for persistence. |
175 SigninStatus signin_status_; | 205 SigninStatus signin_status_; |
176 | 206 |
177 ObserverList<Observer> signin_observers_; | 207 ObserverList<Observer> signin_observers_; |
178 | 208 |
| 209 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> |
| 210 cookie_changed_subscription_; |
| 211 |
179 DISALLOW_COPY_AND_ASSIGN(AboutSigninInternals); | 212 DISALLOW_COPY_AND_ASSIGN(AboutSigninInternals); |
180 }; | 213 }; |
181 | 214 |
182 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ABOUT_SIGNIN_INTERNALS_H_ | 215 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ABOUT_SIGNIN_INTERNALS_H_ |
OLD | NEW |