Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: chrome/browser/signin/account_reconcilor.cc

Issue 166433005: Add URL parameter so that /ListAccounts returns valid json. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ListAccount strings in tests Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/signin/account_reconcilor.h" 5 #include "chrome/browser/signin/account_reconcilor.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 VLOG(1) << "AccountReconcilor::StartRemoveAction: " << account_id; 355 VLOG(1) << "AccountReconcilor::StartRemoveAction: " << account_id;
356 GetAccountsFromCookie( 356 GetAccountsFromCookie(
357 base::Bind(&AccountReconcilor::FinishRemoveAction, 357 base::Bind(&AccountReconcilor::FinishRemoveAction,
358 base::Unretained(this), 358 base::Unretained(this),
359 account_id)); 359 account_id));
360 } 360 }
361 361
362 void AccountReconcilor::FinishRemoveAction( 362 void AccountReconcilor::FinishRemoveAction(
363 const std::string& account_id, 363 const std::string& account_id,
364 const GoogleServiceAuthError& error, 364 const GoogleServiceAuthError& error,
365 const std::vector<std::string>& accounts) { 365 const std::vector<std::pair<std::string, bool> >& accounts) {
366 VLOG(1) << "AccountReconcilor::FinishRemoveAction:" 366 VLOG(1) << "AccountReconcilor::FinishRemoveAction:"
367 << " account=" << account_id 367 << " account=" << account_id
368 << " error=" << error.ToString(); 368 << " error=" << error.ToString();
369 if (error.state() == GoogleServiceAuthError::NONE) { 369 if (error.state() == GoogleServiceAuthError::NONE) {
370 AbortReconcile(); 370 AbortReconcile();
371 merge_session_helper_.LogOut(account_id, accounts); 371 std::vector<std::string> accounts_only;
372 for (std::vector<std::pair<std::string, bool> >::const_iterator i =
373 accounts.begin(); i != accounts.end(); ++i) {
374 accounts_only.push_back(i->first);
375 }
376 merge_session_helper_.LogOut(account_id, accounts_only);
372 } 377 }
373 // Wait for the next ReconcileAction if there is an error. 378 // Wait for the next ReconcileAction if there is an error.
374 } 379 }
375 380
376 void AccountReconcilor::PerformAddToChromeAction( 381 void AccountReconcilor::PerformAddToChromeAction(
377 const std::string& account_id, 382 const std::string& account_id,
378 int session_index) { 383 int session_index) {
379 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:" 384 VLOG(1) << "AccountReconcilor::PerformAddToChromeAction:"
380 << " account=" << account_id 385 << " account=" << account_id
381 << " session_index=" << session_index; 386 << " session_index=" << session_index;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 gaia_fetcher_.reset(new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, 428 gaia_fetcher_.reset(new GaiaAuthFetcher(this, GaiaConstants::kChromeSource,
424 profile_->GetRequestContext())); 429 profile_->GetRequestContext()));
425 gaia_fetcher_->StartListAccounts(); 430 gaia_fetcher_->StartListAccounts();
426 } 431 }
427 } 432 }
428 433
429 void AccountReconcilor::OnListAccountsSuccess(const std::string& data) { 434 void AccountReconcilor::OnListAccountsSuccess(const std::string& data) {
430 gaia_fetcher_.reset(); 435 gaia_fetcher_.reset();
431 436
432 // Get account information from response data. 437 // Get account information from response data.
433 std::vector<std::string> gaia_accounts; 438 std::vector<std::pair<std::string, bool> > gaia_accounts;
434 bool valid_json = gaia::ParseListAccountsData(data, &gaia_accounts); 439 bool valid_json = gaia::ParseListAccountsData(data, &gaia_accounts);
435 if (!valid_json) { 440 if (!valid_json) {
436 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: parsing error"; 441 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: parsing error";
437 } else if (gaia_accounts.size() > 0) { 442 } else if (gaia_accounts.size() > 0) {
438 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: " 443 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: "
439 << "Gaia " << gaia_accounts.size() << " accounts, " 444 << "Gaia " << gaia_accounts.size() << " accounts, "
440 << "Primary is '" << gaia_accounts[0] << "'"; 445 << "Primary is '" << gaia_accounts[0].first << "'";
441 } else { 446 } else {
442 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: No accounts"; 447 VLOG(1) << "AccountReconcilor::OnListAccountsSuccess: No accounts";
443 } 448 }
444 449
445 // There must be at least one callback waiting for result. 450 // There must be at least one callback waiting for result.
446 DCHECK(!get_gaia_accounts_callbacks_.empty()); 451 DCHECK(!get_gaia_accounts_callbacks_.empty());
447 452
448 GoogleServiceAuthError error = !valid_json 453 GoogleServiceAuthError error = !valid_json
449 ? GoogleServiceAuthError( 454 ? GoogleServiceAuthError(
450 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE) 455 GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE)
451 : GoogleServiceAuthError::AuthErrorNone(); 456 : GoogleServiceAuthError::AuthErrorNone();
452 get_gaia_accounts_callbacks_.front().Run(error, gaia_accounts); 457 get_gaia_accounts_callbacks_.front().Run(error, gaia_accounts);
453 get_gaia_accounts_callbacks_.pop_front(); 458 get_gaia_accounts_callbacks_.pop_front();
454 459
455 MayBeDoNextListAccounts(); 460 MayBeDoNextListAccounts();
456 } 461 }
457 462
458 void AccountReconcilor::OnListAccountsFailure( 463 void AccountReconcilor::OnListAccountsFailure(
459 const GoogleServiceAuthError& error) { 464 const GoogleServiceAuthError& error) {
460 gaia_fetcher_.reset(); 465 gaia_fetcher_.reset();
461 VLOG(1) << "AccountReconcilor::OnListAccountsFailure: " << error.ToString(); 466 VLOG(1) << "AccountReconcilor::OnListAccountsFailure: " << error.ToString();
462 std::vector<std::string> empty_accounts; 467 std::vector<std::pair<std::string, bool> > empty_accounts;
463 468
464 // There must be at least one callback waiting for result. 469 // There must be at least one callback waiting for result.
465 DCHECK(!get_gaia_accounts_callbacks_.empty()); 470 DCHECK(!get_gaia_accounts_callbacks_.empty());
466 471
467 get_gaia_accounts_callbacks_.front().Run(error, empty_accounts); 472 get_gaia_accounts_callbacks_.front().Run(error, empty_accounts);
468 get_gaia_accounts_callbacks_.pop_front(); 473 get_gaia_accounts_callbacks_.pop_front();
469 474
470 MayBeDoNextListAccounts(); 475 MayBeDoNextListAccounts();
471 } 476 }
472 477
473 void AccountReconcilor::MayBeDoNextListAccounts() { 478 void AccountReconcilor::MayBeDoNextListAccounts() {
474 if (!get_gaia_accounts_callbacks_.empty()) { 479 if (!get_gaia_accounts_callbacks_.empty()) {
475 gaia_fetcher_.reset(new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, 480 gaia_fetcher_.reset(new GaiaAuthFetcher(this, GaiaConstants::kChromeSource,
476 profile_->GetRequestContext())); 481 profile_->GetRequestContext()));
477 gaia_fetcher_->StartListAccounts(); 482 gaia_fetcher_->StartListAccounts();
478 } 483 }
479 } 484 }
480 485
481 void AccountReconcilor::ContinueReconcileActionAfterGetGaiaAccounts( 486 void AccountReconcilor::ContinueReconcileActionAfterGetGaiaAccounts(
482 const GoogleServiceAuthError& error, 487 const GoogleServiceAuthError& error,
483 const std::vector<std::string>& accounts) { 488 const std::vector<std::pair<std::string, bool> >& accounts) {
484 if (error.state() == GoogleServiceAuthError::NONE) { 489 if (error.state() == GoogleServiceAuthError::NONE) {
485 gaia_accounts_ = accounts; 490 gaia_accounts_ = accounts;
486 are_gaia_accounts_set_ = true; 491 are_gaia_accounts_set_ = true;
487 FinishReconcile(); 492 FinishReconcile();
488 } else { 493 } else {
489 AbortReconcile(); 494 AbortReconcile();
490 } 495 }
491 } 496 }
492 497
493 void AccountReconcilor::ValidateAccountsFromTokenService() { 498 void AccountReconcilor::ValidateAccountsFromTokenService() {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 if (!are_gaia_accounts_set_ || !AreAllRefreshTokensChecked()) 567 if (!are_gaia_accounts_set_ || !AreAllRefreshTokensChecked())
563 return; 568 return;
564 569
565 VLOG(1) << "AccountReconcilor::FinishReconcile"; 570 VLOG(1) << "AccountReconcilor::FinishReconcile";
566 571
567 DeleteFetchers(); 572 DeleteFetchers();
568 573
569 DCHECK(add_to_cookie_.empty()); 574 DCHECK(add_to_cookie_.empty());
570 DCHECK(add_to_chrome_.empty()); 575 DCHECK(add_to_chrome_.empty());
571 bool are_primaries_equal = 576 bool are_primaries_equal =
572 gaia_accounts_.size() > 0 && primary_account_ == gaia_accounts_[0]; 577 gaia_accounts_.size() > 0 && primary_account_ == gaia_accounts_[0].first;
573 578
574 if (are_primaries_equal) { 579 if (are_primaries_equal) {
575 // Determine if we need to merge accounts from gaia cookie to chrome. 580 // Determine if we need to merge accounts from gaia cookie to chrome.
576 for (size_t i = 0; i < gaia_accounts_.size(); ++i) { 581 for (size_t i = 0; i < gaia_accounts_.size(); ++i) {
577 const std::string& gaia_account = gaia_accounts_[i]; 582 const std::string& gaia_account = gaia_accounts_[i].first;
578 if (valid_chrome_accounts_.find(gaia_account) == 583 if (gaia_accounts_[i].second &&
584 valid_chrome_accounts_.find(gaia_account) ==
579 valid_chrome_accounts_.end()) { 585 valid_chrome_accounts_.end()) {
580 add_to_chrome_.push_back(std::make_pair(gaia_account, i)); 586 add_to_chrome_.push_back(std::make_pair(gaia_account, i));
581 } 587 }
582 } 588 }
583 589
584 // Determine if we need to merge accounts from chrome into gaia cookie. 590 // Determine if we need to merge accounts from chrome into gaia cookie.
585 for (std::set<std::string>::const_iterator i = 591 for (std::set<std::string>::const_iterator i =
586 valid_chrome_accounts_.begin(); 592 valid_chrome_accounts_.begin();
587 i != valid_chrome_accounts_.end(); ++i) { 593 i != valid_chrome_accounts_.end(); ++i) {
588 if (std::find(gaia_accounts_.begin(), gaia_accounts_.end(), *i) == 594 bool add_to_cookie = true;
589 gaia_accounts_.end()) { 595 for (size_t j = 0; j < gaia_accounts_.size(); ++j) {
596 if (gaia_accounts_[j].first == *i) {
597 add_to_cookie = !gaia_accounts_[j].second;
598 break;
599 }
600 }
601 if (add_to_cookie)
590 add_to_cookie_.push_back(*i); 602 add_to_cookie_.push_back(*i);
591 }
592 } 603 }
593 } else { 604 } else {
594 VLOG(1) << "AccountReconcilor::FinishReconcile: rebuild cookie"; 605 VLOG(1) << "AccountReconcilor::FinishReconcile: rebuild cookie";
595 // Really messed up state. Blow away the gaia cookie completely and 606 // Really messed up state. Blow away the gaia cookie completely and
596 // rebuild it, making sure the primary account as specified by the 607 // rebuild it, making sure the primary account as specified by the
597 // SigninManager is the first session in the gaia cookie. 608 // SigninManager is the first session in the gaia cookie.
598 PerformLogoutAllAccountsAction(); 609 PerformLogoutAllAccountsAction();
599 add_to_cookie_.push_back(primary_account_); 610 add_to_cookie_.push_back(primary_account_);
600 for (std::set<std::string>::const_iterator i = 611 for (std::set<std::string>::const_iterator i =
601 valid_chrome_accounts_.begin(); 612 valid_chrome_accounts_.begin();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 add_to_chrome_.begin(); 690 add_to_chrome_.begin();
680 i != add_to_chrome_.end(); ++i) { 691 i != add_to_chrome_.end(); ++i) {
681 if (account_id == i->first) { 692 if (account_id == i->first) {
682 add_to_chrome_.erase(i); 693 add_to_chrome_.erase(i);
683 break; 694 break;
684 } 695 }
685 } 696 }
686 697
687 CalculateIfReconcileIsDone(); 698 CalculateIfReconcileIsDone();
688 } 699 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/account_reconcilor.h ('k') | chrome/browser/signin/account_reconcilor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698