OLD | NEW |
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 | 4 |
5 #include "components/signin/core/browser/account_reconcilor.h" | 5 #include "components/signin/core/browser/account_reconcilor.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 GaiaCookieManagerService* cookie_manager_service) | 57 GaiaCookieManagerService* cookie_manager_service) |
58 : token_service_(token_service), | 58 : token_service_(token_service), |
59 signin_manager_(signin_manager), | 59 signin_manager_(signin_manager), |
60 client_(client), | 60 client_(client), |
61 cookie_manager_service_(cookie_manager_service), | 61 cookie_manager_service_(cookie_manager_service), |
62 registered_with_token_service_(false), | 62 registered_with_token_service_(false), |
63 registered_with_cookie_manager_service_(false), | 63 registered_with_cookie_manager_service_(false), |
64 registered_with_content_settings_(false), | 64 registered_with_content_settings_(false), |
65 is_reconcile_started_(false), | 65 is_reconcile_started_(false), |
66 first_execution_(true), | 66 first_execution_(true), |
| 67 error_during_last_reconcile_(false), |
67 chrome_accounts_changed_(false) { | 68 chrome_accounts_changed_(false) { |
68 VLOG(1) << "AccountReconcilor::AccountReconcilor"; | 69 VLOG(1) << "AccountReconcilor::AccountReconcilor"; |
69 } | 70 } |
70 | 71 |
71 AccountReconcilor::~AccountReconcilor() { | 72 AccountReconcilor::~AccountReconcilor() { |
72 VLOG(1) << "AccountReconcilor::~AccountReconcilor"; | 73 VLOG(1) << "AccountReconcilor::~AccountReconcilor"; |
73 // Make sure shutdown was called first. | 74 // Make sure shutdown was called first. |
74 DCHECK(!registered_with_token_service_); | 75 DCHECK(!registered_with_token_service_); |
75 DCHECK(!registered_with_cookie_manager_service_); | 76 DCHECK(!registered_with_cookie_manager_service_); |
76 } | 77 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return; | 170 return; |
170 | 171 |
171 cookie_manager_service_->RemoveObserver(this); | 172 cookie_manager_service_->RemoveObserver(this); |
172 registered_with_cookie_manager_service_ = false; | 173 registered_with_cookie_manager_service_ = false; |
173 } | 174 } |
174 | 175 |
175 bool AccountReconcilor::IsProfileConnected() { | 176 bool AccountReconcilor::IsProfileConnected() { |
176 return signin_manager_->IsAuthenticated(); | 177 return signin_manager_->IsAuthenticated(); |
177 } | 178 } |
178 | 179 |
| 180 AccountReconcilor::State AccountReconcilor::GetState() { |
| 181 if (!is_reconcile_started_) { |
| 182 return error_during_last_reconcile_ |
| 183 ? AccountReconcilor::State::NOT_RECONCILING_ERROR_OCCURED |
| 184 : AccountReconcilor::State::NOT_RECONCILING; |
| 185 } |
| 186 |
| 187 return add_to_cookie_.empty() |
| 188 ? AccountReconcilor::State::GATHERING_INFORMATION |
| 189 : AccountReconcilor::State::APPLYING_CHANGES; |
| 190 } |
| 191 |
179 void AccountReconcilor::OnContentSettingChanged( | 192 void AccountReconcilor::OnContentSettingChanged( |
180 const ContentSettingsPattern& primary_pattern, | 193 const ContentSettingsPattern& primary_pattern, |
181 const ContentSettingsPattern& secondary_pattern, | 194 const ContentSettingsPattern& secondary_pattern, |
182 ContentSettingsType content_type, | 195 ContentSettingsType content_type, |
183 std::string resource_identifier) { | 196 std::string resource_identifier) { |
184 // If this is not a change to cookie settings, just ignore. | 197 // If this is not a change to cookie settings, just ignore. |
185 if (content_type != CONTENT_SETTINGS_TYPE_COOKIES) | 198 if (content_type != CONTENT_SETTINGS_TYPE_COOKIES) |
186 return; | 199 return; |
187 | 200 |
188 // If this does not affect GAIA, just ignore. If the primary pattern is | 201 // If this does not affect GAIA, just ignore. If the primary pattern is |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 void AccountReconcilor::StartReconcile() { | 255 void AccountReconcilor::StartReconcile() { |
243 if (!IsProfileConnected() || !client_->AreSigninCookiesAllowed()) { | 256 if (!IsProfileConnected() || !client_->AreSigninCookiesAllowed()) { |
244 VLOG(1) << "AccountReconcilor::StartReconcile: !connected or no cookies"; | 257 VLOG(1) << "AccountReconcilor::StartReconcile: !connected or no cookies"; |
245 return; | 258 return; |
246 } | 259 } |
247 | 260 |
248 if (is_reconcile_started_) | 261 if (is_reconcile_started_) |
249 return; | 262 return; |
250 | 263 |
251 is_reconcile_started_ = true; | 264 is_reconcile_started_ = true; |
| 265 error_during_last_reconcile_ = false; |
252 | 266 |
253 // Reset state for validating gaia cookie. | 267 // Reset state for validating gaia cookie. |
254 gaia_accounts_.clear(); | 268 gaia_accounts_.clear(); |
255 | 269 |
256 // Reset state for validating oauth2 tokens. | 270 // Reset state for validating oauth2 tokens. |
257 primary_account_.clear(); | 271 primary_account_.clear(); |
258 chrome_accounts_.clear(); | 272 chrome_accounts_.clear(); |
259 add_to_cookie_.clear(); | 273 add_to_cookie_.clear(); |
260 ValidateAccountsFromTokenService(); | 274 ValidateAccountsFromTokenService(); |
261 | 275 |
262 // Rely on the GCMS to manage calls to and responses from ListAccounts. | 276 // Rely on the GCMS to manage calls to and responses from ListAccounts. |
263 if (cookie_manager_service_->ListAccounts(&gaia_accounts_)) { | 277 if (cookie_manager_service_->ListAccounts(&gaia_accounts_)) { |
264 OnGaiaAccountsInCookieUpdated( | 278 OnGaiaAccountsInCookieUpdated( |
265 gaia_accounts_, GoogleServiceAuthError(GoogleServiceAuthError::NONE)); | 279 gaia_accounts_, GoogleServiceAuthError(GoogleServiceAuthError::NONE)); |
266 } | 280 } |
267 } | 281 } |
268 | 282 |
269 void AccountReconcilor::OnGaiaAccountsInCookieUpdated( | 283 void AccountReconcilor::OnGaiaAccountsInCookieUpdated( |
270 const std::vector<std::pair<std::string, bool> >& accounts, | 284 const std::vector<std::pair<std::string, bool> >& accounts, |
271 const GoogleServiceAuthError& error) { | 285 const GoogleServiceAuthError& error) { |
| 286 VLOG(1) << "AccountReconcilor::OnGaiaAccountsInCookieUpdated: " |
| 287 << "CookieJar " << accounts.size() << " accounts, " |
| 288 << "Error was " << error.ToString(); |
272 if (error.state() == GoogleServiceAuthError::NONE) { | 289 if (error.state() == GoogleServiceAuthError::NONE) { |
273 gaia_accounts_ = accounts; | 290 gaia_accounts_ = accounts; |
274 | 291 |
275 // It is possible that O2RT is not available at this moment. | 292 // It is possible that O2RT is not available at this moment. |
276 if (token_service_->GetAccounts().empty()) | 293 if (token_service_->GetAccounts().empty()) |
277 return; | 294 return; |
278 | 295 |
279 is_reconcile_started_ ? FinishReconcile() : StartReconcile(); | 296 is_reconcile_started_ ? FinishReconcile() : StartReconcile(); |
280 } else { | 297 } else { |
| 298 if (is_reconcile_started_) |
| 299 error_during_last_reconcile_ = true; |
281 AbortReconcile(); | 300 AbortReconcile(); |
282 } | 301 } |
283 } | 302 } |
284 | 303 |
285 void AccountReconcilor::ValidateAccountsFromTokenService() { | 304 void AccountReconcilor::ValidateAccountsFromTokenService() { |
286 primary_account_ = signin_manager_->GetAuthenticatedAccountId(); | 305 primary_account_ = signin_manager_->GetAuthenticatedAccountId(); |
287 DCHECK(!primary_account_.empty()); | 306 DCHECK(!primary_account_.empty()); |
288 | 307 |
289 chrome_accounts_ = token_service_->GetAccounts(); | 308 chrome_accounts_ = token_service_->GetAccounts(); |
290 | 309 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 add_to_cookie_.erase(i); | 444 add_to_cookie_.erase(i); |
426 return true; | 445 return true; |
427 } | 446 } |
428 } | 447 } |
429 return false; | 448 return false; |
430 } | 449 } |
431 | 450 |
432 void AccountReconcilor::OnAddAccountToCookieCompleted( | 451 void AccountReconcilor::OnAddAccountToCookieCompleted( |
433 const std::string& account_id, | 452 const std::string& account_id, |
434 const GoogleServiceAuthError& error) { | 453 const GoogleServiceAuthError& error) { |
| 454 VLOG(1) << "AccountReconcilor::OnAddAccountToCookieCompleted: " |
| 455 << "Account added: " << account_id << ", " |
| 456 << "Error was " << error.ToString(); |
435 // Always listens to GaiaCookieManagerService. Only proceed if reconciling. | 457 // Always listens to GaiaCookieManagerService. Only proceed if reconciling. |
436 if (is_reconcile_started_ && MarkAccountAsAddedToCookie(account_id)) { | 458 if (is_reconcile_started_ && MarkAccountAsAddedToCookie(account_id)) { |
| 459 if (error.state() != GoogleServiceAuthError::State::NONE) |
| 460 error_during_last_reconcile_ = true; |
437 CalculateIfReconcileIsDone(); | 461 CalculateIfReconcileIsDone(); |
438 ScheduleStartReconcileIfChromeAccountsChanged(); | 462 ScheduleStartReconcileIfChromeAccountsChanged(); |
439 } | 463 } |
440 } | 464 } |
OLD | NEW |