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

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: rebased Created 6 years, 2 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;
31 30
32 namespace net { 31 namespace net {
33 class CanonicalCookie; 32 class CanonicalCookie;
34 } 33 }
35 34
36 class AccountReconcilor : public KeyedService, 35 class AccountReconcilor : public KeyedService,
37 public GaiaAuthConsumer, 36 public GaiaAuthConsumer,
38 public MergeSessionHelper::Observer, 37 public MergeSessionHelper::Observer,
39 public OAuth2TokenService::Consumer,
40 public OAuth2TokenService::Observer, 38 public OAuth2TokenService::Observer,
41 public SigninManagerBase::Observer { 39 public SigninManagerBase::Observer {
42 public: 40 public:
43 AccountReconcilor(ProfileOAuth2TokenService* token_service, 41 AccountReconcilor(ProfileOAuth2TokenService* token_service,
44 SigninManagerBase* signin_manager, 42 SigninManagerBase* signin_manager,
45 SigninClient* client); 43 SigninClient* client);
46 virtual ~AccountReconcilor(); 44 virtual ~AccountReconcilor();
47 45
48 void Initialize(bool start_reconcile_if_tokens_available); 46 void Initialize(bool start_reconcile_if_tokens_available);
49 47
(...skipping 16 matching lines...) Expand all
66 // Used during GetAccountsFromCookie. 64 // Used during GetAccountsFromCookie.
67 // Stores a callback for the next action to perform. 65 // Stores a callback for the next action to perform.
68 typedef base::Callback< 66 typedef base::Callback<
69 void(const GoogleServiceAuthError& error, 67 void(const GoogleServiceAuthError& error,
70 const std::vector<std::pair<std::string, bool> >&)> 68 const std::vector<std::pair<std::string, bool> >&)>
71 GetAccountsFromCookieCallback; 69 GetAccountsFromCookieCallback;
72 70
73 virtual void GetAccountsFromCookie(GetAccountsFromCookieCallback callback); 71 virtual void GetAccountsFromCookie(GetAccountsFromCookieCallback callback);
74 72
75 private: 73 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 { 74 bool IsRegisteredWithTokenService() const {
93 return registered_with_token_service_; 75 return registered_with_token_service_;
94 } 76 }
95 77
96 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; } 78 bool AreGaiaAccountsSet() const { return are_gaia_accounts_set_; }
97 79
98 bool AreAllRefreshTokensChecked() const;
99
100 const std::vector<std::pair<std::string, bool> >& GetGaiaAccountsForTesting() 80 const std::vector<std::pair<std::string, bool> >& GetGaiaAccountsForTesting()
101 const { 81 const {
102 return gaia_accounts_; 82 return gaia_accounts_;
103 } 83 }
104 84
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. 85 // Virtual so that it can be overridden in tests.
114 virtual void StartFetchingExternalCcResult(); 86 virtual void StartFetchingExternalCcResult();
115 87
116 friend class AccountReconcilorTest; 88 friend class AccountReconcilorTest;
117 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration); 89 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration);
118 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, Reauth); 90 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, Reauth);
119 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ProfileAlreadyConnected); 91 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ProfileAlreadyConnected);
120 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess); 92 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieSuccess);
121 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure); 93 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, GetAccountsFromCookieFailure);
122 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, ValidateAccountsFromTokens);
123 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
124 ValidateAccountsFromTokensFailedUserInfo);
125 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
126 ValidateAccountsFromTokensFailedTokenRequest);
127 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoop); 94 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoop);
128 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopWithDots); 95 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopWithDots);
129 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopMultiple); 96 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopMultiple);
130 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToCookie); 97 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToCookie);
131 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, 98 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
99 StartReconcileRemoveFromCookie);
100 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
132 StartReconcileAddToCookieTwice); 101 StartReconcileAddToCookieTwice);
133 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToChrome);
134 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileBadPrimary); 102 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileBadPrimary);
135 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileOnlyOnce); 103 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileOnlyOnce);
136 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, 104 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
137 StartReconcileWithSessionInfoExpiredDefault); 105 StartReconcileWithSessionInfoExpiredDefault);
138 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, 106 FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
139 MergeSessionCompletedWithBogusAccount); 107 MergeSessionCompletedWithBogusAccount);
140 108
141 // Register and unregister with dependent services. 109 // Register and unregister with dependent services.
142 void RegisterForCookieChanges(); 110 void RegisterForCookieChanges();
143 void UnregisterForCookieChanges(); 111 void UnregisterForCookieChanges();
144 void RegisterWithSigninManager(); 112 void RegisterWithSigninManager();
145 void UnregisterWithSigninManager(); 113 void UnregisterWithSigninManager();
146 void RegisterWithTokenService(); 114 void RegisterWithTokenService();
147 void UnregisterWithTokenService(); 115 void UnregisterWithTokenService();
148 116
149 bool IsProfileConnected(); 117 bool IsProfileConnected();
150 118
151 void DeleteFetchers();
152
153 // All actions with side effects. Virtual so that they can be overridden 119 // All actions with side effects. Virtual so that they can be overridden
154 // in tests. 120 // in tests.
155 virtual void PerformMergeAction(const std::string& account_id); 121 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(); 122 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 123
172 // Used during periodic reconciliation. 124 // Used during periodic reconciliation.
173 void StartReconcile(); 125 void StartReconcile();
174 void FinishReconcile(); 126 void FinishReconcile();
175 void AbortReconcile(); 127 void AbortReconcile();
176 void CalculateIfReconcileIsDone(); 128 void CalculateIfReconcileIsDone();
177 void ScheduleStartReconcileIfChromeAccountsChanged(); 129 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 130
183 void ContinueReconcileActionAfterGetGaiaAccounts( 131 void ContinueReconcileActionAfterGetGaiaAccounts(
184 const GoogleServiceAuthError& error, 132 const GoogleServiceAuthError& error,
185 const std::vector<std::pair<std::string, bool> >& accounts); 133 const std::vector<std::pair<std::string, bool> >& accounts);
186 void ValidateAccountsFromTokenService(); 134 void ValidateAccountsFromTokenService();
187 // Note internally that this |account_id| is added to the cookie jar. 135 // Note internally that this |account_id| is added to the cookie jar.
188 bool MarkAccountAsAddedToCookie(const std::string& account_id); 136 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 137
192 void OnCookieChanged(const net::CanonicalCookie* cookie); 138 void OnCookieChanged(const net::CanonicalCookie* cookie);
193 139
194 // Overriden from GaiaAuthConsumer. 140 // Overriden from GaiaAuthConsumer.
195 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE; 141 virtual void OnListAccountsSuccess(const std::string& data) OVERRIDE;
196 virtual void OnListAccountsFailure(const GoogleServiceAuthError& error) 142 virtual void OnListAccountsFailure(const GoogleServiceAuthError& error)
197 OVERRIDE; 143 OVERRIDE;
198 144
199 // Overriden from MergeSessionHelper::Observer. 145 // Overriden from MergeSessionHelper::Observer.
200 virtual void MergeSessionCompleted(const std::string& account_id, 146 virtual void MergeSessionCompleted(const std::string& account_id,
201 const GoogleServiceAuthError& error) 147 const GoogleServiceAuthError& error)
202 OVERRIDE; 148 OVERRIDE;
203 149
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. 150 // Overriden from OAuth2TokenService::Observer.
212 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
213 virtual void OnEndBatchChanges() OVERRIDE; 151 virtual void OnEndBatchChanges() OVERRIDE;
214 152
215 // Overriden from SigninManagerBase::Observer. 153 // Overriden from SigninManagerBase::Observer.
216 virtual void GoogleSigninSucceeded(const std::string& account_id, 154 virtual void GoogleSigninSucceeded(const std::string& account_id,
217 const std::string& username, 155 const std::string& username,
218 const std::string& password) OVERRIDE; 156 const std::string& password) OVERRIDE;
219 virtual void GoogleSignedOut(const std::string& account_id, 157 virtual void GoogleSignedOut(const std::string& account_id,
220 const std::string& username) OVERRIDE; 158 const std::string& username) OVERRIDE;
221 159
222 void MayBeDoNextListAccounts(); 160 void MayBeDoNextListAccounts();
(...skipping 12 matching lines...) Expand all
235 bool registered_with_token_service_; 173 bool registered_with_token_service_;
236 174
237 // True while the reconcilor is busy checking or managing the accounts in 175 // True while the reconcilor is busy checking or managing the accounts in
238 // this profile. 176 // this profile.
239 bool is_reconcile_started_; 177 bool is_reconcile_started_;
240 178
241 // True iff this is the first time the reconcilor is executing. 179 // True iff this is the first time the reconcilor is executing.
242 bool first_execution_; 180 bool first_execution_;
243 181
244 // Used during reconcile action. 182 // Used during reconcile action.
245 // These members are used used to validate the gaia cookie. |gaia_accounts_| 183 // 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 184 // 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 185 // 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 186 // indicates whether the account is valid or not. The accounts in the vector
249 // are ordered the in same way as the gaia cookie. 187 // are ordered the in same way as the gaia cookie.
250 bool are_gaia_accounts_set_; 188 bool are_gaia_accounts_set_;
251 std::vector<std::pair<std::string, bool> > gaia_accounts_; 189 std::vector<std::pair<std::string, bool> > gaia_accounts_;
252 190
253 // Used during reconcile action. 191 // Used during reconcile action.
254 // These members are used to validate the tokens in OAuth2TokenService. 192 // These members are used to validate the tokens in OAuth2TokenService.
255 std::string primary_account_; 193 std::string primary_account_;
256 std::vector<std::string> chrome_accounts_; 194 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_; 195 std::vector<std::string> add_to_cookie_;
263 std::vector<std::pair<std::string, int> > add_to_chrome_;
264 196
265 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_; 197 std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_;
266 198
267 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> 199 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription>
268 cookie_changed_subscription_; 200 cookie_changed_subscription_;
269 201
270 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor); 202 DISALLOW_COPY_AND_ASSIGN(AccountReconcilor);
271 }; 203 };
272 204
273 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_ 205 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_RECONCILOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/signin/account_reconcilor_unittest.cc ('k') | components/signin/core/browser/account_reconcilor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698