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

Unified Diff: chrome/browser/signin/google_auto_login_helper.cc

Issue 110373007: Delay loading the NTP after sign in until MergeSession has been performed in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years 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 side-by-side diff with in-line comments
Download patch
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);
+}

Powered by Google App Engine
This is Rietveld 408576698