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