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 09cb58a6827945e21241be7770792d1d6e1c5ed4..1cf1cf2ec6ea914048a4a7ed6a04ee8cf87e14bf 100644 |
--- a/chrome/browser/signin/google_auto_login_helper.cc |
+++ b/chrome/browser/signin/google_auto_login_helper.cc |
@@ -12,37 +12,79 @@ |
GoogleAutoLoginHelper::GoogleAutoLoginHelper(Profile* profile) |
: profile_(profile) {} |
-GoogleAutoLoginHelper::~GoogleAutoLoginHelper() {} |
+GoogleAutoLoginHelper::~GoogleAutoLoginHelper() { |
+ DCHECK(accounts_.empty()); |
+} |
void GoogleAutoLoginHelper::LogIn() { |
- uber_token_fetcher_.reset(new UbertokenFetcher(profile_, this)); |
+ // This is the code path for non-mirror world. |
+ uber_token_fetcher_.reset(CreateNewUbertokenFetcher()); |
uber_token_fetcher_->StartFetchingToken(); |
+ DCHECK(accounts_.empty()); |
} |
void GoogleAutoLoginHelper::LogIn(const std::string& account_id) { |
- uber_token_fetcher_.reset(new UbertokenFetcher(profile_, this)); |
- uber_token_fetcher_->StartFetchingToken(account_id); |
+ if (uber_token_fetcher_.get()) { |
+ accounts_.push_back(account_id); |
+ } else { |
+ uber_token_fetcher_.reset(CreateNewUbertokenFetcher()); |
+ uber_token_fetcher_->StartFetchingToken(account_id); |
+ } |
} |
void GoogleAutoLoginHelper::OnUbertokenSuccess(const std::string& uber_token) { |
- gaia_auth_fetcher_.reset(new GaiaAuthFetcher( |
- this, GaiaConstants::kChromeSource, profile_->GetRequestContext())); |
+ VLOG(1) << "GoogleAutoLoginHelper::OnUbertokenSuccess"; |
+ gaia_auth_fetcher_.reset(CreateNewGaiaAuthFetcher()); |
gaia_auth_fetcher_->StartMergeSession(uber_token); |
} |
void GoogleAutoLoginHelper::OnUbertokenFailure( |
const GoogleServiceAuthError& error) { |
VLOG(1) << "Failed to retrieve ubertoken, error: " << error.ToString(); |
- base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
+ if (base::MessageLoop::current()) { |
+ base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
+ } else { |
+ delete this; |
+ } |
} |
void GoogleAutoLoginHelper::OnMergeSessionSuccess(const std::string& data) { |
DVLOG(1) << "MergeSession successful." << data; |
- base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
+ 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(); |
+ } |
} |
void GoogleAutoLoginHelper::OnMergeSessionFailure( |
const GoogleServiceAuthError& error) { |
VLOG(1) << "Failed MergeSession request, error: " << error.ToString(); |
- base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
+ // 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(); |
+ |
+ if (base::MessageLoop::current()) { |
+ base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
+ } else { |
+ delete this; |
+ } |
+} |
+ |
+UbertokenFetcher* GoogleAutoLoginHelper::CreateNewUbertokenFetcher() { |
+ return new UbertokenFetcher(profile_, this); |
+} |
+ |
+GaiaAuthFetcher* GoogleAutoLoginHelper::CreateNewGaiaAuthFetcher() { |
+ return new GaiaAuthFetcher( |
+ this, GaiaConstants::kChromeSource, profile_->GetRequestContext()); |
} |
+ |