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

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