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

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"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
Dan Beam 2013/06/18 21:33:50 #include "base/strings/string_util.h"
aruslan 2013/06/18 23:05:25 base::StringSprintf isn't in string_util.h :)
Dan Beam 2013/06/19 06:53:58 i meant for LowerCaseEqualsASCII()
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "components/autofill/content/browser/wallet/wallet_service_url.h" 14 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
15 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega te.h" 15 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega te.h"
16 #include "google_apis/gaia/gaia_auth_fetcher.h" 16 #include "google_apis/gaia/gaia_auth_fetcher.h"
17 #include "google_apis/gaia/gaia_auth_util.h" 17 #include "google_apis/gaia/gaia_auth_util.h"
18 #include "google_apis/gaia/gaia_constants.h" 18 #include "google_apis/gaia/gaia_constants.h"
19 #include "google_apis/gaia/gaia_urls.h" 19 #include "google_apis/gaia/gaia_urls.h"
20 #include "google_apis/gaia/google_service_auth_error.h" 20 #include "google_apis/gaia/google_service_auth_error.h"
21 #include "net/base/escape.h" 21 #include "net/base/escape.h"
(...skipping 185 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 if (ParseSignInResponse()) {
218 state_ = PASSIVE_FETCHING_USERINFO; 218 url_fetcher_.reset();
219 StartFetchingUserNameFromSession(); 219 state_ = PASSIVE_FETCHING_USERINFO;
220 StartFetchingUserNameFromSession();
221 }
220 break; 222 break;
221 223
222 case AUTOMATIC_EXECUTING_SIGNIN: 224 case AUTOMATIC_EXECUTING_SIGNIN:
223 state_ = IDLE; 225 if (ParseSignInResponse()) {
224 url_fetcher_.reset(); 226 url_fetcher_.reset();
225 delegate_->OnAutomaticSigninSuccess(username_); 227 state_ = IDLE;
228 delegate_->OnAutomaticSigninSuccess(username_);
229 }
226 break; 230 break;
227 231
228 default: 232 default:
229 NOTREACHED() << "unexpected state_=" << state_; 233 NOTREACHED() << "unexpected state_=" << state_;
230 } 234 }
231 } 235 }
232 236
233 void WalletSigninHelper::StartFetchingUserNameFromSession() { 237 void WalletSigninHelper::StartFetchingUserNameFromSession() {
234 DCHECK(!gaia_fetcher_); 238 DCHECK(!gaia_fetcher_);
235 const int random_number = static_cast<int>(base::RandUint64() % INT_MAX); 239 const int random_number = static_cast<int>(base::RandUint64() % INT_MAX);
(...skipping 26 matching lines...) Expand all
262 266
263 case PASSIVE_FETCHING_USERINFO: 267 case PASSIVE_FETCHING_USERINFO:
264 delegate_->OnPassiveSigninSuccess(username_); 268 delegate_->OnPassiveSigninSuccess(username_);
265 break; 269 break;
266 270
267 default: 271 default:
268 NOTREACHED() << "unexpected state_=" << finishing_state; 272 NOTREACHED() << "unexpected state_=" << finishing_state;
269 } 273 }
270 } 274 }
271 275
276 bool WalletSigninHelper::ParseSignInResponse() {
277 DCHECK(url_fetcher_);
Dan Beam 2013/06/18 21:33:50 nit: to make local closer and reduce number of tim
aruslan 2013/06/18 23:05:25 Done.
278
279 std::string data;
280 if (!url_fetcher_ || !url_fetcher_->GetResponseAsString(&data)) {
281 LOG(ERROR) << "failed to GetResponseAsString";
Dan Beam 2013/06/18 21:33:50 remove or changed to DLOG(ERROR) or something
aruslan 2013/06/18 23:05:25 Done.
282 OnOtherError();
283 return false;
284 }
285
286 if (data != "YES") {
Dan Beam 2013/06/18 21:33:50 if (!LowerCaseEqualsASCII(data, "yes")) {
aruslan 2013/06/18 23:05:25 Done.
287 OnServiceError(
288 GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP));
289 return false;
290 }
291
292 return true;
293 }
294
272 bool WalletSigninHelper::ParseGetAccountInfoResponse( 295 bool WalletSigninHelper::ParseGetAccountInfoResponse(
273 const net::URLFetcher* fetcher, std::string* email) { 296 const net::URLFetcher* fetcher, std::string* email) {
274 DCHECK(email); 297 DCHECK(email);
275 298
276 std::string data; 299 std::string data;
277 if (!fetcher->GetResponseAsString(&data)) { 300 if (!fetcher->GetResponseAsString(&data)) {
278 LOG(ERROR) << "failed to GetResponseAsString"; 301 LOG(ERROR) << "failed to GetResponseAsString";
279 return false; 302 return false;
280 } 303 }
281 304
282 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); 305 scoped_ptr<base::Value> value(base::JSONReader::Read(data));
283 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) { 306 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) {
284 LOG(ERROR) << "failed to parse JSON response"; 307 LOG(ERROR) << "failed to parse JSON response";
285 return false; 308 return false;
286 } 309 }
287 310
288 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); 311 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get());
289 if (!dict->GetStringWithoutPathExpansion("email", email)) { 312 if (!dict->GetStringWithoutPathExpansion("email", email)) {
290 LOG(ERROR) << "no email in JSON response"; 313 LOG(ERROR) << "no email in JSON response";
291 return false; 314 return false;
292 } 315 }
293 316
294 return !email->empty(); 317 return !email->empty();
295 } 318 }
296 319
297 } // namespace wallet 320 } // namespace wallet
298 } // namespace autofill 321 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698