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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 16 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 17 #include "components/signin/core/browser/signin_client.h" | 17 #include "components/signin/core/browser/signin_client.h" |
| 18 #include "components/signin/core/browser/signin_oauth_helper.h" | 18 #include "components/signin/core/browser/signin_oauth_helper.h" |
| 19 #include "components/signin/core/common/profile_management_switches.h" | |
| 19 #include "google_apis/gaia/gaia_auth_fetcher.h" | 20 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 20 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
| 21 #include "google_apis/gaia/gaia_constants.h" | 22 #include "google_apis/gaia/gaia_constants.h" |
| 22 #include "google_apis/gaia/gaia_oauth_client.h" | 23 #include "google_apis/gaia/gaia_oauth_client.h" |
| 23 #include "google_apis/gaia/gaia_urls.h" | 24 #include "google_apis/gaia/gaia_urls.h" |
| 24 #include "net/cookies/canonical_cookie.h" | 25 #include "net/cookies/canonical_cookie.h" |
| 25 | 26 |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 signin_manager_(signin_manager), | 195 signin_manager_(signin_manager), |
| 195 client_(client), | 196 client_(client), |
| 196 merge_session_helper_(token_service_, | 197 merge_session_helper_(token_service_, |
| 197 client->GetURLRequestContext(), | 198 client->GetURLRequestContext(), |
| 198 this), | 199 this), |
| 199 registered_with_token_service_(false), | 200 registered_with_token_service_(false), |
| 200 is_reconcile_started_(false), | 201 is_reconcile_started_(false), |
| 201 are_gaia_accounts_set_(false), | 202 are_gaia_accounts_set_(false), |
| 202 requests_(NULL) { | 203 requests_(NULL) { |
| 203 VLOG(1) << "AccountReconcilor::AccountReconcilor"; | 204 VLOG(1) << "AccountReconcilor::AccountReconcilor"; |
| 205 noop_only_mode_ = !switches::IsNewProfileManagement(); | |
| 204 } | 206 } |
| 205 | 207 |
| 206 AccountReconcilor::~AccountReconcilor() { | 208 AccountReconcilor::~AccountReconcilor() { |
| 207 VLOG(1) << "AccountReconcilor::~AccountReconcilor"; | 209 VLOG(1) << "AccountReconcilor::~AccountReconcilor"; |
| 208 // Make sure shutdown was called first. | 210 // Make sure shutdown was called first. |
| 209 DCHECK(!registered_with_token_service_); | 211 DCHECK(!registered_with_token_service_); |
| 210 DCHECK(!reconciliation_timer_.IsRunning()); | 212 DCHECK(!reconciliation_timer_.IsRunning()); |
| 211 DCHECK(!requests_); | 213 DCHECK(!requests_); |
| 212 DCHECK_EQ(0u, user_id_fetchers_.size()); | 214 DCHECK_EQ(0u, user_id_fetchers_.size()); |
| 213 DCHECK_EQ(0u, refresh_token_fetchers_.size()); | 215 DCHECK_EQ(0u, refresh_token_fetchers_.size()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 | 334 |
| 333 void AccountReconcilor::OnCookieChanged(const net::CanonicalCookie* cookie) { | 335 void AccountReconcilor::OnCookieChanged(const net::CanonicalCookie* cookie) { |
| 334 if (cookie->Name() == "LSID" && | 336 if (cookie->Name() == "LSID" && |
| 335 cookie->Domain() == GaiaUrls::GetInstance()->gaia_url().host() && | 337 cookie->Domain() == GaiaUrls::GetInstance()->gaia_url().host() && |
| 336 cookie->IsSecure() && cookie->IsHttpOnly()) { | 338 cookie->IsSecure() && cookie->IsHttpOnly()) { |
| 337 VLOG(1) << "AccountReconcilor::OnCookieChanged: LSID changed"; | 339 VLOG(1) << "AccountReconcilor::OnCookieChanged: LSID changed"; |
| 338 #ifdef OS_CHROMEOS | 340 #ifdef OS_CHROMEOS |
| 339 // On Chrome OS it is possible that O2RT is not available at this moment | 341 // On Chrome OS it is possible that O2RT is not available at this moment |
| 340 // because profile data transfer is still in progress. | 342 // because profile data transfer is still in progress. |
| 341 if (!token_service_->GetAccounts().size()) { | 343 if (!token_service_->GetAccounts().size()) { |
| 342 VLOG(1) << "AccountReconcilor::OnCookieChanged: cookie change is ingored" | 344 VLOG(1) << "AccountReconcilor::OnCookieChanged: cookie change is ingored" |
|
Roger Tawa OOO till Jul 10th
2014/05/07 16:14:45
Could you fix this typo: ingored -> ignored
Mike Lerman
2014/05/08 15:17:50
Done.
| |
| 343 "because profile data transfer is in progress."; | 345 "because profile data transfer is in progress."; |
| 344 return; | 346 return; |
| 345 } | 347 } |
| 346 #endif | 348 #endif |
| 347 StartReconcile(); | 349 StartReconcile(); |
| 348 } | 350 } |
| 349 } | 351 } |
| 350 | 352 |
| 351 void AccountReconcilor::OnRefreshTokenAvailable(const std::string& account_id) { | 353 void AccountReconcilor::OnRefreshTokenAvailable(const std::string& account_id) { |
| 352 VLOG(1) << "AccountReconcilor::OnRefreshTokenAvailable: " << account_id; | 354 VLOG(1) << "AccountReconcilor::OnRefreshTokenAvailable: " << account_id; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 369 } | 371 } |
| 370 | 372 |
| 371 void AccountReconcilor::GoogleSignedOut(const std::string& username) { | 373 void AccountReconcilor::GoogleSignedOut(const std::string& username) { |
| 372 VLOG(1) << "AccountReconcilor::GoogleSignedOut: signed out"; | 374 VLOG(1) << "AccountReconcilor::GoogleSignedOut: signed out"; |
| 373 UnregisterWithTokenService(); | 375 UnregisterWithTokenService(); |
| 374 UnregisterForCookieChanges(); | 376 UnregisterForCookieChanges(); |
| 375 StopPeriodicReconciliation(); | 377 StopPeriodicReconciliation(); |
| 376 } | 378 } |
| 377 | 379 |
| 378 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { | 380 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { |
| 381 if (noop_only_mode_) | |
| 382 return; | |
| 379 VLOG(1) << "AccountReconcilor::PerformMergeAction: " << account_id; | 383 VLOG(1) << "AccountReconcilor::PerformMergeAction: " << account_id; |
| 380 merge_session_helper_.LogIn(account_id); | 384 merge_session_helper_.LogIn(account_id); |
| 381 } | 385 } |
| 382 | 386 |
| 383 void AccountReconcilor::StartRemoveAction(const std::string& account_id) { | 387 void AccountReconcilor::StartRemoveAction(const std::string& account_id) { |
| 384 VLOG(1) << "AccountReconcilor::StartRemoveAction: " << account_id; | 388 VLOG(1) << "AccountReconcilor::StartRemoveAction: " << account_id; |
| 385 GetAccountsFromCookie(base::Bind(&AccountReconcilor::FinishRemoveAction, | 389 GetAccountsFromCookie(base::Bind(&AccountReconcilor::FinishRemoveAction, |
| 386 base::Unretained(this), | 390 base::Unretained(this), |
| 387 account_id)); | 391 account_id)); |
| 388 } | 392 } |
| 389 | 393 |
| 390 void AccountReconcilor::FinishRemoveAction( | 394 void AccountReconcilor::FinishRemoveAction( |
| 391 const std::string& account_id, | 395 const std::string& account_id, |
| 392 const GoogleServiceAuthError& error, | 396 const GoogleServiceAuthError& error, |
| 393 const std::vector<std::pair<std::string, bool> >& accounts) { | 397 const std::vector<std::pair<std::string, bool> >& accounts) { |
| 394 VLOG(1) << "AccountReconcilor::FinishRemoveAction:" | 398 VLOG(1) << "AccountReconcilor::FinishRemoveAction:" |
| 395 << " account=" << account_id << " error=" << error.ToString(); | 399 << " account=" << account_id << " error=" << error.ToString(); |
| 396 if (error.state() == GoogleServiceAuthError::NONE) { | 400 if (error.state() == GoogleServiceAuthError::NONE) { |
| 397 AbortReconcile(); | 401 AbortReconcile(); |
| 398 std::vector<std::string> accounts_only; | 402 std::vector<std::string> accounts_only; |
| 399 for (std::vector<std::pair<std::string, bool> >::const_iterator i = | 403 for (std::vector<std::pair<std::string, bool> >::const_iterator i = |
| 400 accounts.begin(); | 404 accounts.begin(); |
| 401 i != accounts.end(); | 405 i != accounts.end(); |
| 402 ++i) { | 406 ++i) { |
| 403 accounts_only.push_back(i->first); | 407 accounts_only.push_back(i->first); |
| 404 } | 408 } |
| 405 merge_session_helper_.LogOut(account_id, accounts_only); | 409 merge_session_helper_.LogOut(account_id, accounts_only); |
|
Roger Tawa OOO till Jul 10th
2014/05/07 16:14:45
Most calls to |merge_session_helper_| have side ef
Mike Lerman
2014/05/08 15:17:50
Functions renamed.
Add a check on top of PerformFi
| |
| 406 } | 410 } |
| 407 // Wait for the next ReconcileAction if there is an error. | 411 // Wait for the next ReconcileAction if there is an error. |
| 408 } | 412 } |
| 409 | 413 |
| 410 void AccountReconcilor::PerformAddToChromeAction(const std::string& account_id, | 414 void AccountReconcilor::PerformAddToChromeAction(const std::string& account_id, |
| 411 int session_index) { | 415 int session_index) { |
| 416 if (noop_only_mode_) | |
| 417 return; | |
| 412 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:" | 418 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:" |
| 413 << " account=" << account_id << " session_index=" << session_index; | 419 << " account=" << account_id << " session_index=" << session_index; |
| 414 | 420 |
| 415 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 421 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 416 refresh_token_fetchers_.push_back( | 422 refresh_token_fetchers_.push_back( |
| 417 new RefreshTokenFetcher(this, account_id, session_index)); | 423 new RefreshTokenFetcher(this, account_id, session_index)); |
| 418 #endif | 424 #endif |
| 419 } | 425 } |
| 420 | 426 |
| 421 void AccountReconcilor::PerformLogoutAllAccountsAction() { | 427 void AccountReconcilor::PerformLogoutAllAccountsAction() { |
| 428 if (noop_only_mode_) | |
| 429 return; | |
| 422 VLOG(1) << "AccountReconcilor::PerformLogoutAllAccountsAction"; | 430 VLOG(1) << "AccountReconcilor::PerformLogoutAllAccountsAction"; |
| 423 merge_session_helper_.LogOutAllAccounts(); | 431 merge_session_helper_.LogOutAllAccounts(); |
| 424 } | 432 } |
| 425 | 433 |
| 426 void AccountReconcilor::StartReconcile() { | 434 void AccountReconcilor::StartReconcile() { |
| 427 if (!IsProfileConnected() || is_reconcile_started_) | 435 if (!IsProfileConnected() || is_reconcile_started_) |
| 428 return; | 436 return; |
| 429 | 437 |
| 430 is_reconcile_started_ = true; | 438 is_reconcile_started_ = true; |
| 431 | 439 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 | 728 |
| 721 void AccountReconcilor::HandleFailedAccountIdCheck( | 729 void AccountReconcilor::HandleFailedAccountIdCheck( |
| 722 const std::string& account_id) { | 730 const std::string& account_id) { |
| 723 invalid_chrome_accounts_.insert(account_id); | 731 invalid_chrome_accounts_.insert(account_id); |
| 724 FinishReconcile(); | 732 FinishReconcile(); |
| 725 } | 733 } |
| 726 | 734 |
| 727 void AccountReconcilor::HandleRefreshTokenFetched( | 735 void AccountReconcilor::HandleRefreshTokenFetched( |
| 728 const std::string& account_id, | 736 const std::string& account_id, |
| 729 const std::string& refresh_token) { | 737 const std::string& refresh_token) { |
| 730 if (!refresh_token.empty()) { | 738 if (!refresh_token.empty()) { |
|
Roger Tawa OOO till Jul 10th
2014/05/07 16:14:45
Should probably also add a check to this if block
Mike Lerman
2014/05/08 15:17:50
Added the check, you're right it doesn't hurt (muc
| |
| 731 token_service_->UpdateCredentials(account_id, refresh_token); | 739 token_service_->UpdateCredentials(account_id, refresh_token); |
| 732 } | 740 } |
| 733 | 741 |
| 734 // Remove the account from the list that is being updated. | 742 // Remove the account from the list that is being updated. |
| 735 for (std::vector<std::pair<std::string, int> >::iterator i = | 743 for (std::vector<std::pair<std::string, int> >::iterator i = |
| 736 add_to_chrome_.begin(); | 744 add_to_chrome_.begin(); |
| 737 i != add_to_chrome_.end(); | 745 i != add_to_chrome_.end(); |
| 738 ++i) { | 746 ++i) { |
| 739 if (gaia::AreEmailsSame(account_id, i->first)) { | 747 if (gaia::AreEmailsSame(account_id, i->first)) { |
| 740 add_to_chrome_.erase(i); | 748 add_to_chrome_.erase(i); |
| 741 break; | 749 break; |
| 742 } | 750 } |
| 743 } | 751 } |
| 744 | 752 |
| 745 CalculateIfReconcileIsDone(); | 753 CalculateIfReconcileIsDone(); |
| 746 } | 754 } |
| OLD | NEW |