OLD | NEW |
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/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
9 #include "google_apis/gaia/gaia_auth_fetcher.h" | 9 #include "google_apis/gaia/gaia_auth_fetcher.h" |
10 #include "google_apis/gaia/gaia_constants.h" | 10 #include "google_apis/gaia/gaia_constants.h" |
11 | 11 |
12 GoogleAutoLoginHelper::GoogleAutoLoginHelper(Profile* profile) | 12 GoogleAutoLoginHelper::GoogleAutoLoginHelper(Profile* profile) |
13 : profile_(profile) {} | 13 : profile_(profile) {} |
14 | 14 |
15 GoogleAutoLoginHelper::~GoogleAutoLoginHelper() {} | 15 GoogleAutoLoginHelper::~GoogleAutoLoginHelper() { |
| 16 DCHECK(accounts_.empty()); |
| 17 } |
16 | 18 |
17 void GoogleAutoLoginHelper::LogIn() { | 19 void GoogleAutoLoginHelper::LogIn() { |
18 uber_token_fetcher_.reset(new UbertokenFetcher(profile_, this)); | 20 // This is the code path for non-mirror world. |
| 21 uber_token_fetcher_.reset(CreateNewUbertokenFetcher()); |
19 uber_token_fetcher_->StartFetchingToken(); | 22 uber_token_fetcher_->StartFetchingToken(); |
| 23 DCHECK(accounts_.empty()); |
20 } | 24 } |
21 | 25 |
22 void GoogleAutoLoginHelper::LogIn(const std::string& account_id) { | 26 void GoogleAutoLoginHelper::LogIn(const std::string& account_id) { |
23 uber_token_fetcher_.reset(new UbertokenFetcher(profile_, this)); | 27 if (uber_token_fetcher_.get()) { |
24 uber_token_fetcher_->StartFetchingToken(account_id); | 28 accounts_.push_back(account_id); |
| 29 } else { |
| 30 uber_token_fetcher_.reset(CreateNewUbertokenFetcher()); |
| 31 uber_token_fetcher_->StartFetchingToken(account_id); |
| 32 } |
25 } | 33 } |
26 | 34 |
27 void GoogleAutoLoginHelper::OnUbertokenSuccess(const std::string& uber_token) { | 35 void GoogleAutoLoginHelper::OnUbertokenSuccess(const std::string& uber_token) { |
28 gaia_auth_fetcher_.reset(new GaiaAuthFetcher( | 36 VLOG(1) << "GoogleAutoLoginHelper::OnUbertokenSuccess"; |
29 this, GaiaConstants::kChromeSource, profile_->GetRequestContext())); | 37 gaia_auth_fetcher_.reset(CreateNewGaiaAuthFetcher()); |
30 gaia_auth_fetcher_->StartMergeSession(uber_token); | 38 gaia_auth_fetcher_->StartMergeSession(uber_token); |
31 } | 39 } |
32 | 40 |
33 void GoogleAutoLoginHelper::OnUbertokenFailure( | 41 void GoogleAutoLoginHelper::OnUbertokenFailure( |
34 const GoogleServiceAuthError& error) { | 42 const GoogleServiceAuthError& error) { |
35 VLOG(1) << "Failed to retrieve ubertoken, error: " << error.ToString(); | 43 VLOG(1) << "Failed to retrieve ubertoken, error: " << error.ToString(); |
36 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 44 if (base::MessageLoop::current()) { |
| 45 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 46 } else { |
| 47 delete this; |
| 48 } |
37 } | 49 } |
38 | 50 |
39 void GoogleAutoLoginHelper::OnMergeSessionSuccess(const std::string& data) { | 51 void GoogleAutoLoginHelper::OnMergeSessionSuccess(const std::string& data) { |
40 DVLOG(1) << "MergeSession successful." << data; | 52 DVLOG(1) << "MergeSession successful." << data; |
41 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 53 if (accounts_.empty()) { |
| 54 if (base::MessageLoop::current()) { |
| 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 } |
42 } | 64 } |
43 | 65 |
44 void GoogleAutoLoginHelper::OnMergeSessionFailure( | 66 void GoogleAutoLoginHelper::OnMergeSessionFailure( |
45 const GoogleServiceAuthError& error) { | 67 const GoogleServiceAuthError& error) { |
46 VLOG(1) << "Failed MergeSession request, error: " << error.ToString(); | 68 VLOG(1) << "Failed MergeSession request, error: " << error.ToString(); |
47 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 69 // TODO(acleung): Depending on the return error we should probably |
| 70 // take different actions instead of just throw our hands up. |
| 71 |
| 72 // Clearning pending accounts for now. |
| 73 accounts_.clear(); |
| 74 |
| 75 if (base::MessageLoop::current()) { |
| 76 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 77 } else { |
| 78 delete this; |
| 79 } |
48 } | 80 } |
| 81 |
| 82 UbertokenFetcher* GoogleAutoLoginHelper::CreateNewUbertokenFetcher() { |
| 83 return new UbertokenFetcher(profile_, this); |
| 84 } |
| 85 |
| 86 GaiaAuthFetcher* GoogleAutoLoginHelper::CreateNewGaiaAuthFetcher() { |
| 87 return new GaiaAuthFetcher( |
| 88 this, GaiaConstants::kChromeSource, profile_->GetRequestContext()); |
| 89 } |
| 90 |
OLD | NEW |