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

Side by Side Diff: components/autofill/content/browser/wallet/wallet_signin_helper.cc

Issue 16858016: Respect the new Online Wallet sign-in response. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 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 "components/autofill/content/browser/wallet/wallet_signin_helper.h" 5 #include "components/autofill/content/browser/wallet/wallet_signin_helper.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return; 207 return;
208 } 208 }
209 209
210 switch (state_) { 210 switch (state_) {
211 case USERNAME_FETCHING_USERINFO: /*FALLTHROUGH*/ 211 case USERNAME_FETCHING_USERINFO: /*FALLTHROUGH*/
212 case PASSIVE_FETCHING_USERINFO: 212 case PASSIVE_FETCHING_USERINFO:
213 ProcessGetAccountInfoResponseAndFinish(); 213 ProcessGetAccountInfoResponseAndFinish();
214 break; 214 break;
215 215
216 case PASSIVE_EXECUTING_SIGNIN: 216 case PASSIVE_EXECUTING_SIGNIN:
217 url_fetcher_.reset(); 217 ProcessPassiveSignInResponseAndFetchUserName();
218 state_ = PASSIVE_FETCHING_USERINFO;
219 StartFetchingUserNameFromSession();
220 break; 218 break;
221 219
222 case AUTOMATIC_EXECUTING_SIGNIN: 220 case AUTOMATIC_EXECUTING_SIGNIN:
223 state_ = IDLE; 221 ProcessAutomaticSignInResponseAndFinish();
224 url_fetcher_.reset();
225 delegate_->OnAutomaticSigninSuccess(username_);
226 break; 222 break;
227 223
228 default: 224 default:
229 NOTREACHED() << "unexpected state_=" << state_; 225 NOTREACHED() << "unexpected state_=" << state_;
230 } 226 }
231 } 227 }
232 228
233 void WalletSigninHelper::StartFetchingUserNameFromSession() { 229 void WalletSigninHelper::StartFetchingUserNameFromSession() {
234 DCHECK(!gaia_fetcher_); 230 DCHECK(!gaia_fetcher_);
235 const int random_number = static_cast<int>(base::RandUint64() % INT_MAX); 231 const int random_number = static_cast<int>(base::RandUint64() % INT_MAX);
236 url_fetcher_.reset( 232 url_fetcher_.reset(
237 net::URLFetcher::Create( 233 net::URLFetcher::Create(
238 0, 234 0,
239 GURL(base::StringPrintf(kGetAccountInfoUrlFormat, random_number)), 235 GURL(base::StringPrintf(kGetAccountInfoUrlFormat, random_number)),
240 net::URLFetcher::GET, 236 net::URLFetcher::GET,
241 this)); 237 this));
242 url_fetcher_->SetRequestContext(getter_); 238 url_fetcher_->SetRequestContext(getter_);
243 url_fetcher_->Start(); // This will result in OnURLFetchComplete callback. 239 url_fetcher_->Start(); // This will result in OnURLFetchComplete callback.
244 } 240 }
245 241
242 void WalletSigninHelper::ProcessPassiveSignInResponseAndFetchUserName() {
243 GoogleServiceAuthError error(GoogleServiceAuthError::AuthErrorNone());
244 if (!ParsePassiveSignInResponse(&error)) {
245 OnServiceError(error);
246 return;
247 }
248
249 url_fetcher_.reset();
250 state_ = PASSIVE_FETCHING_USERINFO;
251 StartFetchingUserNameFromSession();
252 }
253
254 void WalletSigninHelper::ProcessAutomaticSignInResponseAndFinish() {
255 GoogleServiceAuthError error(GoogleServiceAuthError::AuthErrorNone());
256 if (!ParsePassiveSignInResponse(&error)) {
257 OnServiceError(error);
258 return;
259 }
260
261 url_fetcher_.reset();
262 state_ = IDLE;
263 delegate_->OnAutomaticSigninSuccess(username_);
264 }
265
246 void WalletSigninHelper::ProcessGetAccountInfoResponseAndFinish() { 266 void WalletSigninHelper::ProcessGetAccountInfoResponseAndFinish() {
247 std::string email; 267 std::string email;
248 if (!ParseGetAccountInfoResponse(url_fetcher_.get(), &email)) { 268 if (!ParseGetAccountInfoResponse(url_fetcher_.get(), &email)) {
249 LOG(ERROR) << "failed to get the user email"; 269 LOG(ERROR) << "failed to get the user email";
250 OnOtherError(); 270 OnOtherError();
251 return; 271 return;
252 } 272 }
253 273
254 username_ = email; 274 username_ = email;
255 const State finishing_state = state_; 275 const State finishing_state = state_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 307
288 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); 308 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get());
289 if (!dict->GetStringWithoutPathExpansion("email", email)) { 309 if (!dict->GetStringWithoutPathExpansion("email", email)) {
290 LOG(ERROR) << "no email in JSON response"; 310 LOG(ERROR) << "no email in JSON response";
291 return false; 311 return false;
292 } 312 }
293 313
294 return !email->empty(); 314 return !email->empty();
295 } 315 }
296 316
317 bool WalletSigninHelper::ParsePassiveSignInResponse(
318 GoogleServiceAuthError* error) {
ahutter 2013/06/13 23:52:10 Should you DCHECK(error)?
aruslan 2013/06/18 21:21:47 Done.
319 std::string data;
320 if (!url_fetcher_->GetResponseAsString(&data)) {
321 LOG(ERROR) << "failed to GetResponseAsString";
322 *error = GoogleServiceAuthError::AuthErrorNone();
323 return false;
324 }
325
326 if (data != "YES") {
327 *error =
328 GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
329 return false;
330 }
331
332 return true;
333 }
334
297 } // namespace wallet 335 } // namespace wallet
298 } // namespace autofill 336 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698