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