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_metrics.h" | 18 #include "components/signin/core/browser/signin_metrics.h" |
19 #include "components/signin/core/browser/signin_oauth_helper.h" | 19 #include "components/signin/core/browser/signin_oauth_helper.h" |
| 20 #include "components/signin/core/common/profile_management_switches.h" |
20 #include "google_apis/gaia/gaia_auth_fetcher.h" | 21 #include "google_apis/gaia/gaia_auth_fetcher.h" |
21 #include "google_apis/gaia/gaia_auth_util.h" | 22 #include "google_apis/gaia/gaia_auth_util.h" |
22 #include "google_apis/gaia/gaia_constants.h" | 23 #include "google_apis/gaia/gaia_constants.h" |
23 #include "google_apis/gaia/gaia_oauth_client.h" | 24 #include "google_apis/gaia/gaia_oauth_client.h" |
24 #include "google_apis/gaia/gaia_urls.h" | 25 #include "google_apis/gaia/gaia_urls.h" |
25 #include "net/cookies/canonical_cookie.h" | 26 #include "net/cookies/canonical_cookie.h" |
26 | 27 |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 329 } |
329 } | 330 } |
330 | 331 |
331 void AccountReconcilor::OnRefreshTokenAvailable(const std::string& account_id) { | 332 void AccountReconcilor::OnRefreshTokenAvailable(const std::string& account_id) { |
332 VLOG(1) << "AccountReconcilor::OnRefreshTokenAvailable: " << account_id; | 333 VLOG(1) << "AccountReconcilor::OnRefreshTokenAvailable: " << account_id; |
333 StartReconcile(); | 334 StartReconcile(); |
334 } | 335 } |
335 | 336 |
336 void AccountReconcilor::OnRefreshTokenRevoked(const std::string& account_id) { | 337 void AccountReconcilor::OnRefreshTokenRevoked(const std::string& account_id) { |
337 VLOG(1) << "AccountReconcilor::OnRefreshTokenRevoked: " << account_id; | 338 VLOG(1) << "AccountReconcilor::OnRefreshTokenRevoked: " << account_id; |
338 StartRemoveAction(account_id); | 339 PerformStartRemoveAction(account_id); |
339 } | 340 } |
340 | 341 |
341 void AccountReconcilor::OnRefreshTokensLoaded() {} | 342 void AccountReconcilor::OnRefreshTokensLoaded() {} |
342 | 343 |
343 void AccountReconcilor::GoogleSigninSucceeded(const std::string& username, | 344 void AccountReconcilor::GoogleSigninSucceeded(const std::string& username, |
344 const std::string& password) { | 345 const std::string& password) { |
345 VLOG(1) << "AccountReconcilor::GoogleSigninSucceeded: signed in"; | 346 VLOG(1) << "AccountReconcilor::GoogleSigninSucceeded: signed in"; |
346 RegisterForCookieChanges(); | 347 RegisterForCookieChanges(); |
347 RegisterWithTokenService(); | 348 RegisterWithTokenService(); |
348 } | 349 } |
349 | 350 |
350 void AccountReconcilor::GoogleSignedOut(const std::string& username) { | 351 void AccountReconcilor::GoogleSignedOut(const std::string& username) { |
351 VLOG(1) << "AccountReconcilor::GoogleSignedOut: signed out"; | 352 VLOG(1) << "AccountReconcilor::GoogleSignedOut: signed out"; |
352 gaia_fetcher_.reset(); | 353 gaia_fetcher_.reset(); |
353 get_gaia_accounts_callbacks_.clear(); | 354 get_gaia_accounts_callbacks_.clear(); |
354 AbortReconcile(); | 355 AbortReconcile(); |
355 UnregisterWithTokenService(); | 356 UnregisterWithTokenService(); |
356 UnregisterForCookieChanges(); | 357 UnregisterForCookieChanges(); |
357 PerformLogoutAllAccountsAction(); | 358 PerformLogoutAllAccountsAction(); |
358 } | 359 } |
359 | 360 |
360 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { | 361 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { |
| 362 if (!switches::IsNewProfileManagement()) |
| 363 return; |
361 VLOG(1) << "AccountReconcilor::PerformMergeAction: " << account_id; | 364 VLOG(1) << "AccountReconcilor::PerformMergeAction: " << account_id; |
362 merge_session_helper_.LogIn(account_id); | 365 merge_session_helper_.LogIn(account_id); |
363 } | 366 } |
364 | 367 |
365 void AccountReconcilor::StartRemoveAction(const std::string& account_id) { | 368 void AccountReconcilor::PerformStartRemoveAction( |
366 VLOG(1) << "AccountReconcilor::StartRemoveAction: " << account_id; | 369 const std::string& account_id) { |
367 GetAccountsFromCookie(base::Bind(&AccountReconcilor::FinishRemoveAction, | 370 VLOG(1) << "AccountReconcilor::PerformStartRemoveAction: " << account_id; |
368 base::Unretained(this), | 371 GetAccountsFromCookie(base::Bind( |
369 account_id)); | 372 &AccountReconcilor::PerformFinishRemoveAction, |
| 373 base::Unretained(this), |
| 374 account_id)); |
370 } | 375 } |
371 | 376 |
372 void AccountReconcilor::FinishRemoveAction( | 377 void AccountReconcilor::PerformFinishRemoveAction( |
373 const std::string& account_id, | 378 const std::string& account_id, |
374 const GoogleServiceAuthError& error, | 379 const GoogleServiceAuthError& error, |
375 const std::vector<std::pair<std::string, bool> >& accounts) { | 380 const std::vector<std::pair<std::string, bool> >& accounts) { |
376 VLOG(1) << "AccountReconcilor::FinishRemoveAction:" | 381 if (!switches::IsNewProfileManagement()) |
| 382 return; |
| 383 VLOG(1) << "AccountReconcilor::PerformFinishRemoveAction:" |
377 << " account=" << account_id << " error=" << error.ToString(); | 384 << " account=" << account_id << " error=" << error.ToString(); |
378 if (error.state() == GoogleServiceAuthError::NONE) { | 385 if (error.state() == GoogleServiceAuthError::NONE) { |
379 AbortReconcile(); | 386 AbortReconcile(); |
380 std::vector<std::string> accounts_only; | 387 std::vector<std::string> accounts_only; |
381 for (std::vector<std::pair<std::string, bool> >::const_iterator i = | 388 for (std::vector<std::pair<std::string, bool> >::const_iterator i = |
382 accounts.begin(); | 389 accounts.begin(); |
383 i != accounts.end(); | 390 i != accounts.end(); |
384 ++i) { | 391 ++i) { |
385 accounts_only.push_back(i->first); | 392 accounts_only.push_back(i->first); |
386 } | 393 } |
387 merge_session_helper_.LogOut(account_id, accounts_only); | 394 merge_session_helper_.LogOut(account_id, accounts_only); |
388 } | 395 } |
389 // Wait for the next ReconcileAction if there is an error. | 396 // Wait for the next ReconcileAction if there is an error. |
390 } | 397 } |
391 | 398 |
392 void AccountReconcilor::PerformAddToChromeAction(const std::string& account_id, | 399 void AccountReconcilor::PerformAddToChromeAction(const std::string& account_id, |
393 int session_index) { | 400 int session_index) { |
| 401 if (!switches::IsNewProfileManagement()) |
| 402 return; |
394 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:" | 403 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:" |
395 << " account=" << account_id << " session_index=" << session_index; | 404 << " account=" << account_id << " session_index=" << session_index; |
396 | 405 |
397 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 406 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
398 refresh_token_fetchers_.push_back( | 407 refresh_token_fetchers_.push_back( |
399 new RefreshTokenFetcher(this, account_id, session_index)); | 408 new RefreshTokenFetcher(this, account_id, session_index)); |
400 #endif | 409 #endif |
401 } | 410 } |
402 | 411 |
403 void AccountReconcilor::PerformLogoutAllAccountsAction() { | 412 void AccountReconcilor::PerformLogoutAllAccountsAction() { |
| 413 if (!switches::IsNewProfileManagement()) |
| 414 return; |
404 VLOG(1) << "AccountReconcilor::PerformLogoutAllAccountsAction"; | 415 VLOG(1) << "AccountReconcilor::PerformLogoutAllAccountsAction"; |
405 merge_session_helper_.LogOutAllAccounts(); | 416 merge_session_helper_.LogOutAllAccounts(); |
406 } | 417 } |
407 | 418 |
408 void AccountReconcilor::StartReconcile() { | 419 void AccountReconcilor::StartReconcile() { |
409 if (!IsProfileConnected() || is_reconcile_started_) | 420 if (!IsProfileConnected() || is_reconcile_started_) |
410 return; | 421 return; |
411 | 422 |
412 is_reconcile_started_ = true; | 423 is_reconcile_started_ = true; |
413 | 424 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 valid_chrome_accounts_.insert(account_id); | 718 valid_chrome_accounts_.insert(account_id); |
708 FinishReconcile(); | 719 FinishReconcile(); |
709 } | 720 } |
710 | 721 |
711 void AccountReconcilor::HandleFailedAccountIdCheck( | 722 void AccountReconcilor::HandleFailedAccountIdCheck( |
712 const std::string& account_id) { | 723 const std::string& account_id) { |
713 invalid_chrome_accounts_.insert(account_id); | 724 invalid_chrome_accounts_.insert(account_id); |
714 FinishReconcile(); | 725 FinishReconcile(); |
715 } | 726 } |
716 | 727 |
| 728 void AccountReconcilor::PerformAddAccountToTokenService( |
| 729 const std::string& account_id, |
| 730 const std::string& refresh_token) { |
| 731 // The flow should never get to this method if new_profile_management is |
| 732 // false, but better safe than sorry. |
| 733 if (!switches::IsNewProfileManagement()) |
| 734 return; |
| 735 token_service_->UpdateCredentials(account_id, refresh_token); |
| 736 } |
| 737 |
717 void AccountReconcilor::HandleRefreshTokenFetched( | 738 void AccountReconcilor::HandleRefreshTokenFetched( |
718 const std::string& account_id, | 739 const std::string& account_id, |
719 const std::string& refresh_token) { | 740 const std::string& refresh_token) { |
720 if (!refresh_token.empty()) { | 741 if (!refresh_token.empty()) { |
721 token_service_->UpdateCredentials(account_id, refresh_token); | 742 PerformAddAccountToTokenService(account_id, refresh_token); |
722 } | 743 } |
723 | |
724 // Remove the account from the list that is being updated. | 744 // Remove the account from the list that is being updated. |
725 for (std::vector<std::pair<std::string, int> >::iterator i = | 745 for (std::vector<std::pair<std::string, int> >::iterator i = |
726 add_to_chrome_.begin(); | 746 add_to_chrome_.begin(); |
727 i != add_to_chrome_.end(); | 747 i != add_to_chrome_.end(); |
728 ++i) { | 748 ++i) { |
729 if (gaia::AreEmailsSame(account_id, i->first)) { | 749 if (gaia::AreEmailsSame(account_id, i->first)) { |
730 add_to_chrome_.erase(i); | 750 add_to_chrome_.erase(i); |
731 break; | 751 break; |
732 } | 752 } |
733 } | 753 } |
734 | 754 |
735 CalculateIfReconcileIsDone(); | 755 CalculateIfReconcileIsDone(); |
736 } | 756 } |
OLD | NEW |