Chromium Code Reviews| 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) { |
| 272 if (error.state() == GoogleServiceAuthError::NONE) { | 286 if (error.state() == GoogleServiceAuthError::NONE) { |
|
Roger Tawa OOO till Jul 10th
2015/04/27 20:08:49
Nit: can you add a VLOG above the if?
Mike Lerman
2015/04/27 20:16:49
Done.
| |
| 273 gaia_accounts_ = accounts; | 287 gaia_accounts_ = accounts; |
| 274 | 288 |
| 275 // It is possible that O2RT is not available at this moment. | 289 // It is possible that O2RT is not available at this moment. |
| 276 if (token_service_->GetAccounts().empty()) | 290 if (token_service_->GetAccounts().empty()) |
| 277 return; | 291 return; |
| 278 | 292 |
| 279 is_reconcile_started_ ? FinishReconcile() : StartReconcile(); | 293 is_reconcile_started_ ? FinishReconcile() : StartReconcile(); |
| 280 } else { | 294 } else { |
| 295 if (is_reconcile_started_) | |
| 296 error_during_last_reconcile_ = true; | |
| 281 AbortReconcile(); | 297 AbortReconcile(); |
| 282 } | 298 } |
| 283 } | 299 } |
| 284 | 300 |
| 285 void AccountReconcilor::ValidateAccountsFromTokenService() { | 301 void AccountReconcilor::ValidateAccountsFromTokenService() { |
| 286 primary_account_ = signin_manager_->GetAuthenticatedAccountId(); | 302 primary_account_ = signin_manager_->GetAuthenticatedAccountId(); |
| 287 DCHECK(!primary_account_.empty()); | 303 DCHECK(!primary_account_.empty()); |
| 288 | 304 |
| 289 chrome_accounts_ = token_service_->GetAccounts(); | 305 chrome_accounts_ = token_service_->GetAccounts(); |
| 290 | 306 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 add_to_cookie_.erase(i); | 441 add_to_cookie_.erase(i); |
| 426 return true; | 442 return true; |
| 427 } | 443 } |
| 428 } | 444 } |
| 429 return false; | 445 return false; |
| 430 } | 446 } |
| 431 | 447 |
| 432 void AccountReconcilor::OnAddAccountToCookieCompleted( | 448 void AccountReconcilor::OnAddAccountToCookieCompleted( |
| 433 const std::string& account_id, | 449 const std::string& account_id, |
| 434 const GoogleServiceAuthError& error) { | 450 const GoogleServiceAuthError& error) { |
| 435 // Always listens to GaiaCookieManagerService. Only proceed if reconciling. | 451 // Always listens to GaiaCookieManagerService. Only proceed if reconciling. |
|
Roger Tawa OOO till Jul 10th
2015/04/27 20:08:49
Nit: can you add a VLOG here?
Mike Lerman
2015/04/27 20:16:49
Done.
| |
| 436 if (is_reconcile_started_ && MarkAccountAsAddedToCookie(account_id)) { | 452 if (is_reconcile_started_ && MarkAccountAsAddedToCookie(account_id)) { |
| 453 if (error.state() != GoogleServiceAuthError::State::NONE) | |
| 454 error_during_last_reconcile_ = true; | |
| 437 CalculateIfReconcileIsDone(); | 455 CalculateIfReconcileIsDone(); |
| 438 ScheduleStartReconcileIfChromeAccountsChanged(); | 456 ScheduleStartReconcileIfChromeAccountsChanged(); |
| 439 } | 457 } |
| 440 } | 458 } |
| OLD | NEW |