| 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 "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/string_util.h" |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "base/time.h" | 13 #include "base/time.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "components/autofill/content/browser/wallet/wallet_service_url.h" | 15 #include "components/autofill/content/browser/wallet/wallet_service_url.h" |
| 15 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega
te.h" | 16 #include "components/autofill/content/browser/wallet/wallet_signin_helper_delega
te.h" |
| 16 #include "google_apis/gaia/gaia_auth_fetcher.h" | 17 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 17 #include "google_apis/gaia/gaia_auth_util.h" | 18 #include "google_apis/gaia/gaia_auth_util.h" |
| 18 #include "google_apis/gaia/gaia_constants.h" | 19 #include "google_apis/gaia/gaia_constants.h" |
| 19 #include "google_apis/gaia/gaia_urls.h" | 20 #include "google_apis/gaia/gaia_urls.h" |
| 20 #include "google_apis/gaia/google_service_auth_error.h" | 21 #include "google_apis/gaia/google_service_auth_error.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 return; | 208 return; |
| 208 } | 209 } |
| 209 | 210 |
| 210 switch (state_) { | 211 switch (state_) { |
| 211 case USERNAME_FETCHING_USERINFO: /*FALLTHROUGH*/ | 212 case USERNAME_FETCHING_USERINFO: /*FALLTHROUGH*/ |
| 212 case PASSIVE_FETCHING_USERINFO: | 213 case PASSIVE_FETCHING_USERINFO: |
| 213 ProcessGetAccountInfoResponseAndFinish(); | 214 ProcessGetAccountInfoResponseAndFinish(); |
| 214 break; | 215 break; |
| 215 | 216 |
| 216 case PASSIVE_EXECUTING_SIGNIN: | 217 case PASSIVE_EXECUTING_SIGNIN: |
| 217 url_fetcher_.reset(); | 218 if (ParseSignInResponse()) { |
| 218 state_ = PASSIVE_FETCHING_USERINFO; | 219 url_fetcher_.reset(); |
| 219 StartFetchingUserNameFromSession(); | 220 state_ = PASSIVE_FETCHING_USERINFO; |
| 221 StartFetchingUserNameFromSession(); |
| 222 } |
| 220 break; | 223 break; |
| 221 | 224 |
| 222 case AUTOMATIC_EXECUTING_SIGNIN: | 225 case AUTOMATIC_EXECUTING_SIGNIN: |
| 223 state_ = IDLE; | 226 if (ParseSignInResponse()) { |
| 224 url_fetcher_.reset(); | 227 url_fetcher_.reset(); |
| 225 delegate_->OnAutomaticSigninSuccess(username_); | 228 state_ = IDLE; |
| 229 delegate_->OnAutomaticSigninSuccess(username_); |
| 230 } |
| 226 break; | 231 break; |
| 227 | 232 |
| 228 default: | 233 default: |
| 229 NOTREACHED() << "unexpected state_=" << state_; | 234 NOTREACHED() << "unexpected state_=" << state_; |
| 230 } | 235 } |
| 231 } | 236 } |
| 232 | 237 |
| 233 void WalletSigninHelper::StartFetchingUserNameFromSession() { | 238 void WalletSigninHelper::StartFetchingUserNameFromSession() { |
| 234 DCHECK(!gaia_fetcher_); | 239 DCHECK(!gaia_fetcher_); |
| 235 const int random_number = static_cast<int>(base::RandUint64() % INT_MAX); | 240 const int random_number = static_cast<int>(base::RandUint64() % INT_MAX); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 262 | 267 |
| 263 case PASSIVE_FETCHING_USERINFO: | 268 case PASSIVE_FETCHING_USERINFO: |
| 264 delegate_->OnPassiveSigninSuccess(username_); | 269 delegate_->OnPassiveSigninSuccess(username_); |
| 265 break; | 270 break; |
| 266 | 271 |
| 267 default: | 272 default: |
| 268 NOTREACHED() << "unexpected state_=" << finishing_state; | 273 NOTREACHED() << "unexpected state_=" << finishing_state; |
| 269 } | 274 } |
| 270 } | 275 } |
| 271 | 276 |
| 277 bool WalletSigninHelper::ParseSignInResponse() { |
| 278 if (!url_fetcher_) { |
| 279 NOTREACHED(); |
| 280 return false; |
| 281 } |
| 282 |
| 283 std::string data; |
| 284 if (!url_fetcher_->GetResponseAsString(&data)) { |
| 285 DVLOG(1) << "failed to GetResponseAsString"; |
| 286 OnOtherError(); |
| 287 return false; |
| 288 } |
| 289 |
| 290 if (!LowerCaseEqualsASCII(data, "yes")) { |
| 291 OnServiceError( |
| 292 GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP)); |
| 293 return false; |
| 294 } |
| 295 |
| 296 return true; |
| 297 } |
| 298 |
| 272 bool WalletSigninHelper::ParseGetAccountInfoResponse( | 299 bool WalletSigninHelper::ParseGetAccountInfoResponse( |
| 273 const net::URLFetcher* fetcher, std::string* email) { | 300 const net::URLFetcher* fetcher, std::string* email) { |
| 274 DCHECK(email); | 301 DCHECK(email); |
| 275 | 302 |
| 276 std::string data; | 303 std::string data; |
| 277 if (!fetcher->GetResponseAsString(&data)) { | 304 if (!fetcher->GetResponseAsString(&data)) { |
| 278 LOG(ERROR) << "failed to GetResponseAsString"; | 305 DVLOG(1) << "failed to GetResponseAsString"; |
| 279 return false; | 306 return false; |
| 280 } | 307 } |
| 281 | 308 |
| 282 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 309 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
| 283 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) { | 310 if (!value.get() || value->GetType() != base::Value::TYPE_DICTIONARY) { |
| 284 LOG(ERROR) << "failed to parse JSON response"; | 311 DVLOG(1) << "failed to parse JSON response"; |
| 285 return false; | 312 return false; |
| 286 } | 313 } |
| 287 | 314 |
| 288 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 315 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
| 289 if (!dict->GetStringWithoutPathExpansion("email", email)) { | 316 if (!dict->GetStringWithoutPathExpansion("email", email)) { |
| 290 LOG(ERROR) << "no email in JSON response"; | 317 DVLOG(1) << "no email in JSON response"; |
| 291 return false; | 318 return false; |
| 292 } | 319 } |
| 293 | 320 |
| 294 return !email->empty(); | 321 return !email->empty(); |
| 295 } | 322 } |
| 296 | 323 |
| 297 } // namespace wallet | 324 } // namespace wallet |
| 298 } // namespace autofill | 325 } // namespace autofill |
| OLD | NEW |