Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1023)

Side by Side Diff: components/signin/core/browser/account_reconcilor.h

Issue 590113004: Handle account removal correctly on all platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modify metrics Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ 4 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_
5 #define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ 5 #define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_
6 6
7 #include <deque> 7 #include <deque>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/callback_forward.h" 15 #include "base/callback_forward.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/scoped_vector.h" 18 #include "base/memory/scoped_vector.h"
19 #include "components/keyed_service/core/keyed_service.h" 19 #include "components/keyed_service/core/keyed_service.h"
20 #include "components/signin/core/browser/signin_client.h" 20 #include "components/signin/core/browser/signin_client.h"
21 #include "components/signin/core/browser/signin_manager.h" 21 #include "components/signin/core/browser/signin_manager.h"
22 #include "google_apis/gaia/gaia_auth_consumer.h" 22 #include "google_apis/gaia/gaia_auth_consumer.h"
23 #include "google_apis/gaia/google_service_auth_error.h" 23 #include "google_apis/gaia/google_service_auth_error.h"
24 #include "google_apis/gaia/merge_session_helper.h" 24 #include "google_apis/gaia/merge_session_helper.h"
25 #include "google_apis/gaia/oauth2_token_service.h" 25 #include "google_apis/gaia/oauth2_token_service.h"
26 26
27 class GaiaAuthFetcher; 27 class GaiaAuthFetcher;
28 class ProfileOAuth2TokenService; 28 class ProfileOAuth2TokenService;
29 class SigninClient; 29 class SigninClient;
30 class SigninOAuthHelper; 30 class SigninOAuthHelper;
Mike Lerman 2014/09/23 14:27:47 I think we can remove this declaration?
Roger Tawa OOO till Jul 10th 2014/09/23 21:25:58 Done.
Roger Tawa OOO till Jul 10th 2014/09/23 21:25:58 Done.
31 31
32 namespace net { 32 namespace net {
33 class CanonicalCookie; 33 class CanonicalCookie;
34 } 34 }
35 35
36 class AccountReconcilor : public KeyedService, 36 class AccountReconcilor : public KeyedService,
37 public GaiaAuthConsumer, 37 public GaiaAuthConsumer,
38 public MergeSessionHelper::Observer, 38 public MergeSessionHelper::Observer,
39 public OAuth2TokenService::Consumer,
40 public OAuth2TokenService::Observer, 39 public OAuth2TokenService::Observer,
41 public SigninManagerBase::Observer { 40 public SigninManagerBase::Observer {
42 public: 41 public:
43 AccountReconcilor(ProfileOAuth2TokenService* token_service, 42 AccountReconcilor(ProfileOAuth2TokenService* token_service,
44 SigninManagerBase* signin_manager, 43 SigninManagerBase* signin_manager,
45 SigninClient* client); 44 SigninClient* client);
46 virtual ~AccountReconcilor(); 45 virtual ~AccountReconcilor();
47 46
48 void Initialize(bool start_reconcile_if_tokens_available); 47 void Initialize(bool start_reconcile_if_tokens_available);
49 48
(...skipping 16 matching lines...) Expand all
66 // Used during GetAccountsFromCookie. 65 // Used during GetAccountsFromCookie.
67 // Stores a callback for the next action to perform. 66 // Stores a callback for the next action to perform.
68 typedef base::Callback< 67 typedef base::Callback<
69 void(const GoogleServiceAuthError& error, 68 void(const GoogleServiceAuthError& error,
70 const std::vector<std::pair<std::string, bool> >&)> 69 const std::vector<std::pair<std::string, bool> >&)>
71 GetAccountsFromCookieCallback; 70 GetAccountsFromCookieCallback;
72 71
73 virtual void GetAccountsFromCookie(GetAccountsFromCookieCallback callback); 72 virtual void GetAccountsFromCookie(GetAccountsFromCookieCallback callback);
74 73
75 private: 74 private:
76 // An std::set<> for use with email addresses that uses
77 // gaia::CanonicalizeEmail() during comparisons.
78 // TODO(rogerta): this is a workaround for the fact that SigninManager and
79 // SigninOAuthHelper use the gaia "email" property when adding accounts to
80 // the token service, whereas gaia::ParseListAccountsData() returns email
81 // addresses that have been passed through gaia::CanonicalizeEmail(). These
82 // two types of email addresses are not directly comparable.
83 class EmailLessFunc : public std::less<std::string> {
84 public:
85 bool operator()(const std::string& s1, const std::string& s2) const;
86 };
87 typedef std::set<std::string, EmailLessFunc> EmailSet;
88
89 class RefreshTokenFetcher;
90 class UserIdFetcher;
91
92 bool IsRegisteredWithTokenService() const { 75 bool IsRegisteredWithTokenService() const {
93 return registered_with_token_service_; 76 return registered_with_token_service_;
94 } 77 }
95 78
96 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; } 79 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; }
97 80
98 bool AreAllRefreshTokensChecked() const;
99
100 const std::vector<std::pair<std::string, bool> >& GetGaiaAccountsForTesting() 81 const std::vector<std::pair<std::string, bool> >& GetGaiaAccountsForTesting()
101 const { 82 const {
102 return gaia_accounts_; 83 return gaia_accounts_;
103 } 84 }
104 85
105 const EmailSet& GetValidChromeAccountsForTesting() const {
106 return valid_chrome_accounts_;
107 }
108
109 const EmailSet& GetInvalidChromeAccountsForTesting() const {
110 return invalid_chrome_accounts_;
111 }
112
113 // Virtual so that it can be overridden in tests. 86 // Virtual so that it can be overridden in tests.
114 virtual void StartFetchingExternalCcResult(); 87 virtual void StartFetchingExternalCcResult();
115 88
116 friend class AccountReconcilorTest; 89 friend class AccountReconcilorTest;
117 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration); 90 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration);
118 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, Reauth); 91 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, Reauth);
119 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ProfileAlreadyConnected); 92 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ProfileAlreadyConnected);
120 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess); 93 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess);
121 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure); 94 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure);
122 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens); 95 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens);
(...skipping 18 matching lines...) Expand all
141 // Register and unregister with dependent services. 114 // Register and unregister with dependent services.
142 void RegisterForCookieChanges(); 115 void RegisterForCookieChanges();
143 void UnregisterForCookieChanges(); 116 void UnregisterForCookieChanges();
144 void RegisterWithSigninManager(); 117 void RegisterWithSigninManager();
145 void UnregisterWithSigninManager(); 118 void UnregisterWithSigninManager();
146 void RegisterWithTokenService(); 119 void RegisterWithTokenService();
147 void UnregisterWithTokenService(); 120 void UnregisterWithTokenService();
148 121
149 bool IsProfileConnected(); 122 bool IsProfileConnected();
150 123
151 void DeleteFetchers();
152
153 // All actions with side effects. Virtual so that they can be overridden 124 // All actions with side effects. Virtual so that they can be overridden
154 // in tests. 125 // in tests.
155 virtual void PerformMergeAction(const std::string& account_id); 126 virtual void PerformMergeAction(const std::string& account_id);
156 virtual void PerformAddToChromeAction(
157 const std::string& account_id,
158 int session_index,
159 const std::string& signin_scoped_device_id);
160 virtual void PerformLogoutAllAccountsAction(); 127 virtual void PerformLogoutAllAccountsAction();
161 virtual void PerformAddAccountToTokenService(
162 const std::string& account_id,
163 const std::string& refresh_token);
164
165 // Used to remove an account from chrome and the cookie jar.
166 virtual void PerformStartRemoveAction(const std::string& account_id);
167 virtual void PerformFinishRemoveAction(
168 const std::string& account_id,
169 const GoogleServiceAuthError& error,
170 const std::vector<std::pair<std::string, bool> >& accounts);
171 128
172 // Used during periodic reconciliation. 129 // Used during periodic reconciliation.
173 void StartReconcile(); 130 void StartReconcile();
174 void FinishReconcile(); 131 void FinishReconcile();
175 void AbortReconcile(); 132 void AbortReconcile();
176 void CalculateIfReconcileIsDone(); 133 void CalculateIfReconcileIsDone();
177 void ScheduleStartReconcileIfChromeAccountsChanged(); 134 void ScheduleStartReconcileIfChromeAccountsChanged();
178 void HandleSuccessfulAccountIdCheck(const std::string& account_id);
179 void HandleFailedAccountIdCheck(const std::string& account_id);
180 void HandleRefreshTokenFetched(const std::string& account_id,
181 const std::string& refresh_token);
182 135
183 void ContinueReconcileActionAfterGetGaiaAccounts( 136 void ContinueReconcileActionAfterGetGaiaAccounts(
184 const GoogleServiceAuthError& error, 137 const GoogleServiceAuthError& error,
185 const std::vector<std::pair<std::string, bool> >& accounts); 138 const std::vector<std::pair<std::string, bool> >& accounts);
186 void ValidateAccountsFromTokenService(); 139 void ValidateAccountsFromTokenService();
187 // Note internally that this |account_id| is added to the cookie jar. 140 // Note internally that this |account_id| is added to the cookie jar.
188 bool MarkAccountAsAddedToCookie(const std::string& account_id); 141 bool MarkAccountAsAddedToCookie(const std::string& account_id);
189 // Note internally that this |account_id| is added to the token service.
190 void MarkAccountAsAddedToChrome(const std::string& account_id);
191 142
192 void OnCookieChanged(const net::CanonicalCookie* cookie); 143 void OnCookieChanged(const net::CanonicalCookie* cookie);
193 144
194 // Overriden from GaiaAuthConsumer. 145 // Overriden from GaiaAuthConsumer.
195 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; 146 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE;
196 virtual void OnListAccountsFailure(const GoogleServiceAuthError& error) 147 virtual void OnListAccountsFailure(const GoogleServiceAuthError& error)
197 OVERRIDE; 148 OVERRIDE;
198 149
199 // Overriden from MergeSessionHelper::Observer. 150 // Overriden from MergeSessionHelper::Observer.
200 virtual void MergeSessionCompleted(const std::string& account_id, 151 virtual void MergeSessionCompleted(const std::string& account_id,
201 const GoogleServiceAuthError& error) 152 const GoogleServiceAuthError& error)
202 OVERRIDE; 153 OVERRIDE;
203 154
204 // Overriden from OAuth2TokenService::Consumer.
205 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
206 const std::string& access_token,
207 const base::Time& expiration_time) OVERRIDE;
208 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
209 const GoogleServiceAuthError& error) OVERRIDE;
210
211 // Overriden from OAuth2TokenService::Observer. 155 // Overriden from OAuth2TokenService::Observer.
212 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
213 virtual void OnEndBatchChanges() OVERRIDE; 156 virtual void OnEndBatchChanges() OVERRIDE;
214 157
215 // Overriden from SigninManagerBase::Observer. 158 // Overriden from SigninManagerBase::Observer.
216 virtual void GoogleSigninSucceeded(const std::string& account_id, 159 virtual void GoogleSigninSucceeded(const std::string& account_id,
217 const std::string& username, 160 const std::string& username,
218 const std::string& password) OVERRIDE; 161 const std::string& password) OVERRIDE;
219 virtual void GoogleSignedOut(const std::string& account_id, 162 virtual void GoogleSignedOut(const std::string& account_id,
220 const std::string& username) OVERRIDE; 163 const std::string& username) OVERRIDE;
221 164
222 void MayBeDoNextListAccounts(); 165 void MayBeDoNextListAccounts();
(...skipping 12 matching lines...) Expand all
235 bool registered_with_token_service_; 178 bool registered_with_token_service_;
236 179
237 // True while the reconcilor is busy checking or managing the accounts in 180 // True while the reconcilor is busy checking or managing the accounts in
238 // this profile. 181 // this profile.
239 bool is_reconcile_started_; 182 bool is_reconcile_started_;
240 183
241 // True iff this is the first time the reconcilor is executing. 184 // True iff this is the first time the reconcilor is executing.
242 bool first_execution_; 185 bool first_execution_;
243 186
244 // Used during reconcile action. 187 // Used during reconcile action.
245 // These members are used used to validate the gaia cookie. |gaia_accounts_| 188 // These members are used to validate the gaia cookie. |gaia_accounts_|
246 // holds the state of google accounts in the gaia cookie. Each element is 189 // holds the state of google accounts in the gaia cookie. Each element is
247 // a pair that holds the email address of the account and a boolean that 190 // a pair that holds the email address of the account and a boolean that
248 // indicates whether the account is valid or not. The accounts in the vector 191 // indicates whether the account is valid or not. The accounts in the vector
249 // are ordered the in same way as the gaia cookie. 192 // are ordered the in same way as the gaia cookie.
250 bool are_gaia_accounts_set_; 193 bool are_gaia_accounts_set_;
251 std::vector<std::pair<std::string, bool> > gaia_accounts_; 194 std::vector<std::pair<std::string, bool> > gaia_accounts_;
252 195
253 // Used during reconcile action. 196 // Used during reconcile action.
254 // These members are used to validate the tokens in OAuth2TokenService. 197 // These members are used to validate the tokens in OAuth2TokenService.
255 std::string primary_account_; 198 std::string primary_account_;
256 std::vector<std::string> chrome_accounts_; 199 std::vector<std::string> chrome_accounts_;
257 scoped_ptr<OAuth2TokenService::Request>* requests_;
258 ScopedVector<UserIdFetcher> user_id_fetchers_;
259 ScopedVector<SigninOAuthHelper> refresh_token_fetchers_;
260 EmailSet valid_chrome_accounts_;
261 EmailSet invalid_chrome_accounts_;
262 std::vector<std::string> add_to_cookie_; 200 std::vector<std::string> add_to_cookie_;
263 std::vector<std::pair<std::string, int> > add_to_chrome_;
264 201
265 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_; 202 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_;
266 203
267 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> 204 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription>
268 cookie_changed_subscription_; 205 cookie_changed_subscription_;
269 206
270 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor); 207 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor);
271 }; 208 };
272 209
273 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ 210 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698