| Index: chrome/browser/signin/google_auto_login_helper.cc
|
| diff --git a/chrome/browser/signin/google_auto_login_helper.cc b/chrome/browser/signin/google_auto_login_helper.cc
|
| index 1cf1cf2ec6ea914048a4a7ed6a04ee8cf87e14bf..158928859e60156edf20bfac49bcb175de9176ee 100644
|
| --- a/chrome/browser/signin/google_auto_login_helper.cc
|
| +++ b/chrome/browser/signin/google_auto_login_helper.cc
|
| @@ -5,86 +5,99 @@
|
| #include "chrome/browser/signin/google_auto_login_helper.h"
|
|
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/chrome_notification_types.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/browser/signin/profile_oauth2_token_service.h"
|
| +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
|
| +#include "content/public/browser/notification_service.h"
|
| #include "google_apis/gaia/gaia_auth_fetcher.h"
|
| #include "google_apis/gaia/gaia_constants.h"
|
|
|
| +GoogleAutoLoginHelper::MergeSessionDetails::MergeSessionDetails(
|
| + const std::string& account_id,
|
| + const GoogleServiceAuthError& error)
|
| + : account_id(account_id), error(error) {
|
| +}
|
| +
|
| GoogleAutoLoginHelper::GoogleAutoLoginHelper(Profile* profile)
|
| - : profile_(profile) {}
|
| + : profile_(profile),
|
| + auto_delete_when_done_(true) {}
|
|
|
| GoogleAutoLoginHelper::~GoogleAutoLoginHelper() {
|
| DCHECK(accounts_.empty());
|
| }
|
|
|
| void GoogleAutoLoginHelper::LogIn() {
|
| - // This is the code path for non-mirror world.
|
| - uber_token_fetcher_.reset(CreateNewUbertokenFetcher());
|
| - uber_token_fetcher_->StartFetchingToken();
|
| - DCHECK(accounts_.empty());
|
| + ProfileOAuth2TokenService* token_service =
|
| + ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
|
| + LogIn(token_service->GetPrimaryAccountId());
|
| }
|
|
|
| void GoogleAutoLoginHelper::LogIn(const std::string& account_id) {
|
| - if (uber_token_fetcher_.get()) {
|
| - accounts_.push_back(account_id);
|
| - } else {
|
| - uber_token_fetcher_.reset(CreateNewUbertokenFetcher());
|
| - uber_token_fetcher_->StartFetchingToken(account_id);
|
| - }
|
| + accounts_.push_back(account_id);
|
| + if (accounts_.size() == 1)
|
| + StartFetching();
|
| }
|
|
|
| void GoogleAutoLoginHelper::OnUbertokenSuccess(const std::string& uber_token) {
|
| - VLOG(1) << "GoogleAutoLoginHelper::OnUbertokenSuccess";
|
| - gaia_auth_fetcher_.reset(CreateNewGaiaAuthFetcher());
|
| + VLOG(1) << "GoogleAutoLoginHelper::OnUbertokenSuccess"
|
| + << " account=" << accounts_.front();
|
| + gaia_auth_fetcher_.reset(
|
| + new GaiaAuthFetcher(this, GaiaConstants::kChromeSource,
|
| + profile_->GetRequestContext()));
|
| gaia_auth_fetcher_->StartMergeSession(uber_token);
|
| }
|
|
|
| void GoogleAutoLoginHelper::OnUbertokenFailure(
|
| const GoogleServiceAuthError& error) {
|
| - VLOG(1) << "Failed to retrieve ubertoken, error: " << error.ToString();
|
| - if (base::MessageLoop::current()) {
|
| - base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
|
| - } else {
|
| - delete this;
|
| - }
|
| + VLOG(1) << "Failed to retrieve ubertoken"
|
| + << " account=" << accounts_.front()
|
| + << " error=" << error.ToString();
|
| + SignalComplete(error);
|
| + MergeNextAccount();
|
| }
|
|
|
| void GoogleAutoLoginHelper::OnMergeSessionSuccess(const std::string& data) {
|
| - DVLOG(1) << "MergeSession successful." << data;
|
| - if (accounts_.empty()) {
|
| - if (base::MessageLoop::current()) {
|
| - base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
|
| - } else {
|
| - delete this;
|
| - }
|
| - } else {
|
| - uber_token_fetcher_.reset(CreateNewUbertokenFetcher());
|
| - uber_token_fetcher_->StartFetchingToken(accounts_.front());
|
| - accounts_.pop_front();
|
| - }
|
| + DVLOG(1) << "MergeSession successful account=" << accounts_.front();
|
| + SignalComplete(GoogleServiceAuthError(GoogleServiceAuthError::NONE));
|
| + MergeNextAccount();
|
| }
|
|
|
| void GoogleAutoLoginHelper::OnMergeSessionFailure(
|
| const GoogleServiceAuthError& error) {
|
| - VLOG(1) << "Failed MergeSession request, error: " << error.ToString();
|
| - // TODO(acleung): Depending on the return error we should probably
|
| - // take different actions instead of just throw our hands up.
|
| -
|
| - // Clearning pending accounts for now.
|
| - accounts_.clear();
|
| + VLOG(1) << "Failed MergeSession request, error"
|
| + << " account=" << accounts_.front()
|
| + << " error=" << error.ToString();
|
| + SignalComplete(error);
|
| + MergeNextAccount();
|
| +}
|
|
|
| - if (base::MessageLoop::current()) {
|
| - base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
|
| - } else {
|
| - delete this;
|
| - }
|
| +void GoogleAutoLoginHelper::StartFetching() {
|
| + uber_token_fetcher_.reset(new UbertokenFetcher(profile_, this));
|
| + uber_token_fetcher_->StartFetchingToken(accounts_.front());
|
| }
|
|
|
| -UbertokenFetcher* GoogleAutoLoginHelper::CreateNewUbertokenFetcher() {
|
| - return new UbertokenFetcher(profile_, this);
|
| +void GoogleAutoLoginHelper::SignalComplete(
|
| + const GoogleServiceAuthError& error) {
|
| + MergeSessionDetails details(accounts_.front(), error);
|
| + content::NotificationService::current()->Notify(
|
| + chrome::NOTIFICATION_MERGE_SESSION_COMPLETE,
|
| + content::Source<Profile>(profile_),
|
| + content::Details<const MergeSessionDetails>(&details));
|
| }
|
|
|
| -GaiaAuthFetcher* GoogleAutoLoginHelper::CreateNewGaiaAuthFetcher() {
|
| - return new GaiaAuthFetcher(
|
| - this, GaiaConstants::kChromeSource, profile_->GetRequestContext());
|
| +void GoogleAutoLoginHelper::MergeNextAccount() {
|
| + gaia_auth_fetcher_.reset();
|
| + accounts_.pop_front();
|
| + if (accounts_.empty()) {
|
| + uber_token_fetcher_.reset();
|
| + AutoDeleteIfNeeded();
|
| + } else {
|
| + StartFetching();
|
| + }
|
| }
|
|
|
| +void GoogleAutoLoginHelper::AutoDeleteIfNeeded() {
|
| + if (auto_delete_when_done_)
|
| + base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
|
| +}
|
|
|