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

Side by Side 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 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/google_auto_login_helper.h" 5 #include "chrome/browser/signin/google_auto_login_helper.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "content/public/browser/notification_service.h"
9 #include "google_apis/gaia/gaia_auth_fetcher.h" 13 #include "google_apis/gaia/gaia_auth_fetcher.h"
10 #include "google_apis/gaia/gaia_constants.h" 14 #include "google_apis/gaia/gaia_constants.h"
11 15
16 GoogleAutoLoginHelper::MergeSessionDetails::MergeSessionDetails(
17 const std::string& account_id,
18 const GoogleServiceAuthError& error)
19 : account_id(account_id), error(error) {
20 }
21
12 GoogleAutoLoginHelper::GoogleAutoLoginHelper(Profile* profile) 22 GoogleAutoLoginHelper::GoogleAutoLoginHelper(Profile* profile)
13 : profile_(profile) {} 23 : profile_(profile),
24 auto_delete_when_done_(true) {}
14 25
15 GoogleAutoLoginHelper::~GoogleAutoLoginHelper() { 26 GoogleAutoLoginHelper::~GoogleAutoLoginHelper() {
16 DCHECK(accounts_.empty()); 27 DCHECK(accounts_.empty());
17 } 28 }
18 29
19 void GoogleAutoLoginHelper::LogIn() { 30 void GoogleAutoLoginHelper::LogIn() {
20 // This is the code path for non-mirror world. 31 ProfileOAuth2TokenService* token_service =
21 uber_token_fetcher_.reset(CreateNewUbertokenFetcher()); 32 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
22 uber_token_fetcher_->StartFetchingToken(); 33 LogIn(token_service->GetPrimaryAccountId());
23 DCHECK(accounts_.empty());
24 } 34 }
25 35
26 void GoogleAutoLoginHelper::LogIn(const std::string& account_id) { 36 void GoogleAutoLoginHelper::LogIn(const std::string& account_id) {
27 if (uber_token_fetcher_.get()) { 37 accounts_.push_back(account_id);
28 accounts_.push_back(account_id); 38 if (accounts_.size() == 1)
29 } else { 39 StartFetching();
30 uber_token_fetcher_.reset(CreateNewUbertokenFetcher());
31 uber_token_fetcher_->StartFetchingToken(account_id);
32 }
33 } 40 }
34 41
35 void GoogleAutoLoginHelper::OnUbertokenSuccess(const std::string& uber_token) { 42 void GoogleAutoLoginHelper::OnUbertokenSuccess(const std::string& uber_token) {
36 VLOG(1) << "GoogleAutoLoginHelper::OnUbertokenSuccess"; 43 VLOG(1) << "GoogleAutoLoginHelper::OnUbertokenSuccess"
37 gaia_auth_fetcher_.reset(CreateNewGaiaAuthFetcher()); 44 << " account=" << accounts_.front();
45 gaia_auth_fetcher_.reset(
46 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource,
47 profile_->GetRequestContext()));
38 gaia_auth_fetcher_->StartMergeSession(uber_token); 48 gaia_auth_fetcher_->StartMergeSession(uber_token);
39 } 49 }
40 50
41 void GoogleAutoLoginHelper::OnUbertokenFailure( 51 void GoogleAutoLoginHelper::OnUbertokenFailure(
42 const GoogleServiceAuthError& error) { 52 const GoogleServiceAuthError& error) {
43 VLOG(1) << "Failed to retrieve ubertoken, error: " << error.ToString(); 53 VLOG(1) << "Failed to retrieve ubertoken"
44 if (base::MessageLoop::current()) { 54 << " account=" << accounts_.front()
45 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 55 << " error=" << error.ToString();
46 } else { 56 SignalComplete(error);
47 delete this; 57 MergeNextAccount();
48 }
49 } 58 }
50 59
51 void GoogleAutoLoginHelper::OnMergeSessionSuccess(const std::string& data) { 60 void GoogleAutoLoginHelper::OnMergeSessionSuccess(const std::string& data) {
52 DVLOG(1) << "MergeSession successful." << data; 61 DVLOG(1) << "MergeSession successful account=" << accounts_.front();
53 if (accounts_.empty()) { 62 SignalComplete(GoogleServiceAuthError(GoogleServiceAuthError::NONE));
54 if (base::MessageLoop::current()) { 63 MergeNextAccount();
55 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
56 } else {
57 delete this;
58 }
59 } else {
60 uber_token_fetcher_.reset(CreateNewUbertokenFetcher());
61 uber_token_fetcher_->StartFetchingToken(accounts_.front());
62 accounts_.pop_front();
63 }
64 } 64 }
65 65
66 void GoogleAutoLoginHelper::OnMergeSessionFailure( 66 void GoogleAutoLoginHelper::OnMergeSessionFailure(
67 const GoogleServiceAuthError& error) { 67 const GoogleServiceAuthError& error) {
68 VLOG(1) << "Failed MergeSession request, error: " << error.ToString(); 68 VLOG(1) << "Failed MergeSession request, error"
69 // TODO(acleung): Depending on the return error we should probably 69 << " account=" << accounts_.front()
70 // take different actions instead of just throw our hands up. 70 << " error=" << error.ToString();
71 SignalComplete(error);
72 MergeNextAccount();
73 }
71 74
72 // Clearning pending accounts for now. 75 void GoogleAutoLoginHelper::StartFetching() {
73 accounts_.clear(); 76 uber_token_fetcher_.reset(new UbertokenFetcher(profile_, this));
77 uber_token_fetcher_->StartFetchingToken(accounts_.front());
78 }
74 79
75 if (base::MessageLoop::current()) { 80 void GoogleAutoLoginHelper::SignalComplete(
76 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 81 const GoogleServiceAuthError& error) {
82 MergeSessionDetails details(accounts_.front(), error);
83 content::NotificationService::current()->Notify(
84 chrome::NOTIFICATION_MERGE_SESSION_COMPLETE,
85 content::Source<Profile>(profile_),
86 content::Details<const MergeSessionDetails>(&details));
87 }
88
89 void GoogleAutoLoginHelper::MergeNextAccount() {
90 gaia_auth_fetcher_.reset();
91 accounts_.pop_front();
92 if (accounts_.empty()) {
93 uber_token_fetcher_.reset();
94 AutoDeleteIfNeeded();
77 } else { 95 } else {
78 delete this; 96 StartFetching();
79 } 97 }
80 } 98 }
81 99
82 UbertokenFetcher* GoogleAutoLoginHelper::CreateNewUbertokenFetcher() { 100 void GoogleAutoLoginHelper::AutoDeleteIfNeeded() {
83 return new UbertokenFetcher(profile_, this); 101 if (auto_delete_when_done_)
102 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
84 } 103 }
85
86 GaiaAuthFetcher* GoogleAutoLoginHelper::CreateNewGaiaAuthFetcher() {
87 return new GaiaAuthFetcher(
88 this, GaiaConstants::kChromeSource, profile_->GetRequestContext());
89 }
90
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698