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

Side by Side Diff: chrome/browser/chromeos/login/oauth2_login_verifier.cc

Issue 16998003: Update CrOS to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/chromeos/login/oauth2_login_verifier.h" 5 #include "chrome/browser/chromeos/login/oauth2_login_verifier.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 refresh_token_ = oauth2_refresh_token; 67 refresh_token_ = oauth2_refresh_token;
68 gaia_token_.clear(); 68 gaia_token_.clear();
69 StartFetchingOAuthLoginAccessToken(); 69 StartFetchingOAuthLoginAccessToken();
70 } 70 }
71 71
72 void OAuth2LoginVerifier::StartFetchingOAuthLoginAccessToken() { 72 void OAuth2LoginVerifier::StartFetchingOAuthLoginAccessToken() {
73 access_token_.clear(); 73 access_token_.clear();
74 gaia_token_.clear(); 74 gaia_token_.clear();
75 std::vector<std::string> scopes; 75 std::vector<std::string> scopes;
76 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope()); 76 scopes.push_back(GaiaUrls::GetInstance()->oauth1_login_scope());
77 token_fetcher_.reset(new OAuth2AccessTokenFetcher( 77 token_fetcher_
78 this, system_request_context_)), 78 .reset(new OAuth2AccessTokenFetcher(this, system_request_context_.get())),
79 token_fetcher_->Start(GaiaUrls::GetInstance()->oauth2_chrome_client_id(), 79 token_fetcher_
80 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), 80 ->Start(GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
81 refresh_token_, 81 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
82 scopes); 82 refresh_token_,
83 scopes);
83 } 84 }
84 85
85 void OAuth2LoginVerifier::OnGetTokenSuccess( 86 void OAuth2LoginVerifier::OnGetTokenSuccess(
86 const std::string& access_token, const base::Time& expiration_time) { 87 const std::string& access_token, const base::Time& expiration_time) {
87 LOG(INFO) << "Got OAuth2 access token!"; 88 LOG(INFO) << "Got OAuth2 access token!";
88 retry_count_ = 0; 89 retry_count_ = 0;
89 access_token_ = access_token; 90 access_token_ = access_token;
90 StartOAuthLoginForUberToken(); 91 StartOAuthLoginForUberToken();
91 } 92 }
92 93
93 void OAuth2LoginVerifier::OnGetTokenFailure( 94 void OAuth2LoginVerifier::OnGetTokenFailure(
94 const GoogleServiceAuthError& error) { 95 const GoogleServiceAuthError& error) {
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
96 LOG(ERROR) << "Failed to get OAuth2 access token, " 97 LOG(ERROR) << "Failed to get OAuth2 access token, "
97 << " error: " << error.state(); 98 << " error: " << error.state();
98 RetryOnError( 99 RetryOnError(
99 "GetOAuth2AccessToken", error, 100 "GetOAuth2AccessToken", error,
100 base::Bind(&OAuth2LoginVerifier::StartFetchingOAuthLoginAccessToken, 101 base::Bind(&OAuth2LoginVerifier::StartFetchingOAuthLoginAccessToken,
101 AsWeakPtr()), 102 AsWeakPtr()),
102 base::Bind(&Delegate::OnOAuthLoginFailure, 103 base::Bind(&Delegate::OnOAuthLoginFailure,
103 base::Unretained(delegate_))); 104 base::Unretained(delegate_)));
104 } 105 }
105 106
106 void OAuth2LoginVerifier::StartOAuthLoginForUberToken() { 107 void OAuth2LoginVerifier::StartOAuthLoginForUberToken() {
107 // No service will fetch us uber auth token. 108 // No service will fetch us uber auth token.
108 gaia_system_fetcher_.reset(new GaiaAuthFetcher( 109 gaia_system_fetcher_.reset(
109 this, std::string(GaiaConstants::kChromeOSSource), 110 new GaiaAuthFetcher(this,
110 system_request_context_)); 111 std::string(GaiaConstants::kChromeOSSource),
112 system_request_context_.get()));
111 gaia_system_fetcher_->StartTokenFetchForUberAuthExchange(access_token_); 113 gaia_system_fetcher_->StartTokenFetchForUberAuthExchange(access_token_);
112 } 114 }
113 115
114 116
115 void OAuth2LoginVerifier::OnUberAuthTokenSuccess( 117 void OAuth2LoginVerifier::OnUberAuthTokenSuccess(
116 const std::string& uber_token) { 118 const std::string& uber_token) {
117 LOG(INFO) << "OAuthLogin(uber_token) successful!"; 119 LOG(INFO) << "OAuthLogin(uber_token) successful!";
118 retry_count_ = 0; 120 retry_count_ = 0;
119 gaia_token_ = uber_token; 121 gaia_token_ = uber_token;
120 StartMergeSession(); 122 StartMergeSession();
121 } 123 }
122 124
123 void OAuth2LoginVerifier::OnUberAuthTokenFailure( 125 void OAuth2LoginVerifier::OnUberAuthTokenFailure(
124 const GoogleServiceAuthError& error) { 126 const GoogleServiceAuthError& error) {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
126 LOG(ERROR) << "OAuthLogin(uber_token) failed," 128 LOG(ERROR) << "OAuthLogin(uber_token) failed,"
127 << " error: " << error.state(); 129 << " error: " << error.state();
128 RetryOnError("OAuthLoginUberToken", error, 130 RetryOnError("OAuthLoginUberToken", error,
129 base::Bind(&OAuth2LoginVerifier::StartOAuthLoginForUberToken, 131 base::Bind(&OAuth2LoginVerifier::StartOAuthLoginForUberToken,
130 AsWeakPtr()), 132 AsWeakPtr()),
131 base::Bind(&Delegate::OnOAuthLoginFailure, 133 base::Bind(&Delegate::OnOAuthLoginFailure,
132 base::Unretained(delegate_))); 134 base::Unretained(delegate_)));
133 } 135 }
134 136
135 void OAuth2LoginVerifier::StartOAuthLoginForGaiaCredentials() { 137 void OAuth2LoginVerifier::StartOAuthLoginForGaiaCredentials() {
136 // No service will fetch us uber auth token. 138 // No service will fetch us uber auth token.
137 gaia_system_fetcher_.reset(new GaiaAuthFetcher( 139 gaia_system_fetcher_.reset(
138 this, std::string(GaiaConstants::kChromeOSSource), 140 new GaiaAuthFetcher(this,
139 system_request_context_)); 141 std::string(GaiaConstants::kChromeOSSource),
142 system_request_context_.get()));
140 gaia_system_fetcher_->StartOAuthLogin(access_token_, EmptyString()); 143 gaia_system_fetcher_->StartOAuthLogin(access_token_, EmptyString());
141 } 144 }
142 145
143 void OAuth2LoginVerifier::OnClientLoginSuccess( 146 void OAuth2LoginVerifier::OnClientLoginSuccess(
144 const ClientLoginResult& gaia_credentials) { 147 const ClientLoginResult& gaia_credentials) {
145 LOG(INFO) << "OAuthLogin(SID+LSID) successful!"; 148 LOG(INFO) << "OAuthLogin(SID+LSID) successful!";
146 retry_count_ = 0; 149 retry_count_ = 0;
147 gaia_credentials_ = gaia_credentials; 150 gaia_credentials_ = gaia_credentials;
148 delegate_->OnOAuthLoginSuccess(gaia_credentials_); 151 delegate_->OnOAuthLoginSuccess(gaia_credentials_);
149 } 152 }
150 153
151 void OAuth2LoginVerifier::OnClientLoginFailure( 154 void OAuth2LoginVerifier::OnClientLoginFailure(
152 const GoogleServiceAuthError& error) { 155 const GoogleServiceAuthError& error) {
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
154 LOG(ERROR) << "OAuthLogin(SID+LSID failed)," 157 LOG(ERROR) << "OAuthLogin(SID+LSID failed),"
155 << " error: " << error.state(); 158 << " error: " << error.state();
156 RetryOnError( 159 RetryOnError(
157 "OAuthLoginGaiaCred", error, 160 "OAuthLoginGaiaCred", error,
158 base::Bind(&OAuth2LoginVerifier::StartOAuthLoginForGaiaCredentials, 161 base::Bind(&OAuth2LoginVerifier::StartOAuthLoginForGaiaCredentials,
159 AsWeakPtr()), 162 AsWeakPtr()),
160 base::Bind(&Delegate::OnOAuthLoginFailure, 163 base::Bind(&Delegate::OnOAuthLoginFailure,
161 base::Unretained(delegate_))); 164 base::Unretained(delegate_)));
162 } 165 }
163 166
164 void OAuth2LoginVerifier::StartMergeSession() { 167 void OAuth2LoginVerifier::StartMergeSession() {
165 DCHECK(!gaia_token_.empty()); 168 DCHECK(!gaia_token_.empty());
166 gaia_fetcher_.reset(new GaiaAuthFetcher( 169 gaia_fetcher_.reset(
167 this, std::string(GaiaConstants::kChromeOSSource), 170 new GaiaAuthFetcher(this,
168 user_request_context_)); 171 std::string(GaiaConstants::kChromeOSSource),
172 user_request_context_.get()));
169 gaia_fetcher_->StartMergeSession(gaia_token_); 173 gaia_fetcher_->StartMergeSession(gaia_token_);
170 } 174 }
171 175
172 void OAuth2LoginVerifier::OnMergeSessionSuccess(const std::string& data) { 176 void OAuth2LoginVerifier::OnMergeSessionSuccess(const std::string& data) {
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
174 LOG(INFO) << "MergeSession successful."; 178 LOG(INFO) << "MergeSession successful.";
175 delegate_->OnSessionMergeSuccess(); 179 delegate_->OnSessionMergeSuccess();
176 // Get GAIA credentials needed to kick off TokenService and friends. 180 // Get GAIA credentials needed to kick off TokenService and friends.
177 StartOAuthLoginForGaiaCredentials(); 181 StartOAuthLoginForGaiaCredentials();
178 } 182 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 LOG(ERROR) << "Unrecoverable error or retry count max reached for " 218 LOG(ERROR) << "Unrecoverable error or retry count max reached for "
215 << operation_id; 219 << operation_id;
216 UMA_HISTOGRAM_ENUMERATION( 220 UMA_HISTOGRAM_ENUMERATION(
217 base::StringPrintf("OAuth2Login.%sFailure", operation_id), 221 base::StringPrintf("OAuth2Login.%sFailure", operation_id),
218 error.state(), 222 error.state(),
219 GoogleServiceAuthError::NUM_STATES); 223 GoogleServiceAuthError::NUM_STATES);
220 error_handler.Run(); 224 error_handler.Run();
221 } 225 }
222 226
223 } // namespace chromeos 227 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698