| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/core/browser/payments/payments_client.h" | 5 #include "components/autofill/core/browser/payments/payments_client.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 11 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "components/autofill/core/browser/autofill_data_model.h" | 20 #include "components/autofill/core/browser/autofill_data_model.h" |
| 20 #include "components/autofill/core/browser/autofill_type.h" | 21 #include "components/autofill/core/browser/autofill_type.h" |
| 21 #include "components/autofill/core/browser/credit_card.h" | 22 #include "components/autofill/core/browser/credit_card.h" |
| 22 #include "components/autofill/core/browser/payments/payments_request.h" | 23 #include "components/autofill/core/browser/payments/payments_request.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 "--sync-url. You likely want to enable the sync sandbox " | 89 "--sync-url. You likely want to enable the sync sandbox " |
| 89 "or switch to production Payments. Both are controlled in " | 90 "or switch to production Payments. Both are controlled in " |
| 90 "about:flags."; | 91 "about:flags."; |
| 91 } | 92 } |
| 92 | 93 |
| 93 GURL base(IsPaymentsProductionEnabled() ? kPaymentsRequestHost | 94 GURL base(IsPaymentsProductionEnabled() ? kPaymentsRequestHost |
| 94 : kPaymentsRequestHostSandbox); | 95 : kPaymentsRequestHostSandbox); |
| 95 return base.Resolve(path); | 96 return base.Resolve(path); |
| 96 } | 97 } |
| 97 | 98 |
| 98 scoped_ptr<base::DictionaryValue> BuildRiskDictionary( | 99 std::unique_ptr<base::DictionaryValue> BuildRiskDictionary( |
| 99 const std::string& encoded_risk_data) { | 100 const std::string& encoded_risk_data) { |
| 100 scoped_ptr<base::DictionaryValue> risk_data(new base::DictionaryValue()); | 101 std::unique_ptr<base::DictionaryValue> risk_data(new base::DictionaryValue()); |
| 101 #if defined(OS_IOS) | 102 #if defined(OS_IOS) |
| 102 // Browser fingerprinting is not available on iOS. Instead, we generate | 103 // Browser fingerprinting is not available on iOS. Instead, we generate |
| 103 // RiskAdvisoryData. | 104 // RiskAdvisoryData. |
| 104 risk_data->SetString("message_type", "RISK_ADVISORY_DATA"); | 105 risk_data->SetString("message_type", "RISK_ADVISORY_DATA"); |
| 105 risk_data->SetString("encoding_type", "BASE_64_URL"); | 106 risk_data->SetString("encoding_type", "BASE_64_URL"); |
| 106 #else | 107 #else |
| 107 risk_data->SetString("message_type", "BROWSER_NATIVE_FINGERPRINTING"); | 108 risk_data->SetString("message_type", "BROWSER_NATIVE_FINGERPRINTING"); |
| 108 risk_data->SetString("encoding_type", "BASE_64"); | 109 risk_data->SetString("encoding_type", "BASE_64"); |
| 109 #endif | 110 #endif |
| 110 | 111 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 125 | 126 |
| 126 void AppendStringIfNotEmpty(const AutofillProfile& profile, | 127 void AppendStringIfNotEmpty(const AutofillProfile& profile, |
| 127 const ServerFieldType& type, | 128 const ServerFieldType& type, |
| 128 const std::string& app_locale, | 129 const std::string& app_locale, |
| 129 base::ListValue* list) { | 130 base::ListValue* list) { |
| 130 const base::string16 value = profile.GetInfo(AutofillType(type), app_locale); | 131 const base::string16 value = profile.GetInfo(AutofillType(type), app_locale); |
| 131 if (!value.empty()) | 132 if (!value.empty()) |
| 132 list->AppendString(value); | 133 list->AppendString(value); |
| 133 } | 134 } |
| 134 | 135 |
| 135 scoped_ptr<base::DictionaryValue> BuildAddressDictionary( | 136 std::unique_ptr<base::DictionaryValue> BuildAddressDictionary( |
| 136 const AutofillProfile& profile, | 137 const AutofillProfile& profile, |
| 137 const std::string& app_locale) { | 138 const std::string& app_locale) { |
| 138 scoped_ptr<base::DictionaryValue> postal_address(new base::DictionaryValue()); | 139 std::unique_ptr<base::DictionaryValue> postal_address( |
| 140 new base::DictionaryValue()); |
| 139 | 141 |
| 140 SetStringIfNotEmpty(profile, NAME_FULL, app_locale, "recipient_name", | 142 SetStringIfNotEmpty(profile, NAME_FULL, app_locale, "recipient_name", |
| 141 postal_address.get()); | 143 postal_address.get()); |
| 142 | 144 |
| 143 scoped_ptr<base::ListValue> address_lines(new base::ListValue()); | 145 std::unique_ptr<base::ListValue> address_lines(new base::ListValue()); |
| 144 AppendStringIfNotEmpty(profile, ADDRESS_HOME_LINE1, app_locale, | 146 AppendStringIfNotEmpty(profile, ADDRESS_HOME_LINE1, app_locale, |
| 145 address_lines.get()); | 147 address_lines.get()); |
| 146 AppendStringIfNotEmpty(profile, ADDRESS_HOME_LINE2, app_locale, | 148 AppendStringIfNotEmpty(profile, ADDRESS_HOME_LINE2, app_locale, |
| 147 address_lines.get()); | 149 address_lines.get()); |
| 148 AppendStringIfNotEmpty(profile, ADDRESS_HOME_LINE3, app_locale, | 150 AppendStringIfNotEmpty(profile, ADDRESS_HOME_LINE3, app_locale, |
| 149 address_lines.get()); | 151 address_lines.get()); |
| 150 if (!address_lines->empty()) | 152 if (!address_lines->empty()) |
| 151 postal_address->Set("address_line", std::move(address_lines)); | 153 postal_address->Set("address_line", std::move(address_lines)); |
| 152 | 154 |
| 153 SetStringIfNotEmpty(profile, ADDRESS_HOME_CITY, app_locale, "locality_name", | 155 SetStringIfNotEmpty(profile, ADDRESS_HOME_CITY, app_locale, "locality_name", |
| 154 postal_address.get()); | 156 postal_address.get()); |
| 155 SetStringIfNotEmpty(profile, ADDRESS_HOME_STATE, app_locale, | 157 SetStringIfNotEmpty(profile, ADDRESS_HOME_STATE, app_locale, |
| 156 "administrative_area_name", postal_address.get()); | 158 "administrative_area_name", postal_address.get()); |
| 157 SetStringIfNotEmpty(profile, ADDRESS_HOME_ZIP, app_locale, | 159 SetStringIfNotEmpty(profile, ADDRESS_HOME_ZIP, app_locale, |
| 158 "postal_code_number", postal_address.get()); | 160 "postal_code_number", postal_address.get()); |
| 159 | 161 |
| 160 // Use GetRawInfo to get a country code instead of the country name: | 162 // Use GetRawInfo to get a country code instead of the country name: |
| 161 const base::string16 country_code = profile.GetRawInfo(ADDRESS_HOME_COUNTRY); | 163 const base::string16 country_code = profile.GetRawInfo(ADDRESS_HOME_COUNTRY); |
| 162 if (!country_code.empty()) | 164 if (!country_code.empty()) |
| 163 postal_address->SetString("country_name_code", country_code); | 165 postal_address->SetString("country_name_code", country_code); |
| 164 | 166 |
| 165 scoped_ptr<base::DictionaryValue> address(new base::DictionaryValue()); | 167 std::unique_ptr<base::DictionaryValue> address(new base::DictionaryValue()); |
| 166 address->Set("postal_address", std::move(postal_address)); | 168 address->Set("postal_address", std::move(postal_address)); |
| 167 SetStringIfNotEmpty(profile, PHONE_HOME_WHOLE_NUMBER, app_locale, | 169 SetStringIfNotEmpty(profile, PHONE_HOME_WHOLE_NUMBER, app_locale, |
| 168 "phone_number", address.get()); | 170 "phone_number", address.get()); |
| 169 | 171 |
| 170 return address; | 172 return address; |
| 171 } | 173 } |
| 172 | 174 |
| 173 class UnmaskCardRequest : public PaymentsRequest { | 175 class UnmaskCardRequest : public PaymentsRequest { |
| 174 public: | 176 public: |
| 175 UnmaskCardRequest(const PaymentsClient::UnmaskRequestDetails& request_details) | 177 UnmaskCardRequest(const PaymentsClient::UnmaskRequestDetails& request_details) |
| 176 : request_details_(request_details) { | 178 : request_details_(request_details) { |
| 177 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, | 179 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, |
| 178 request_details.card.record_type()); | 180 request_details.card.record_type()); |
| 179 } | 181 } |
| 180 ~UnmaskCardRequest() override {} | 182 ~UnmaskCardRequest() override {} |
| 181 | 183 |
| 182 std::string GetRequestUrlPath() override { return kUnmaskCardRequestPath; } | 184 std::string GetRequestUrlPath() override { return kUnmaskCardRequestPath; } |
| 183 | 185 |
| 184 std::string GetRequestContentType() override { | 186 std::string GetRequestContentType() override { |
| 185 return "application/x-www-form-urlencoded"; | 187 return "application/x-www-form-urlencoded"; |
| 186 } | 188 } |
| 187 | 189 |
| 188 std::string GetRequestContent() override { | 190 std::string GetRequestContent() override { |
| 189 base::DictionaryValue request_dict; | 191 base::DictionaryValue request_dict; |
| 190 request_dict.SetString("encrypted_cvc", "__param:s7e_13_cvc"); | 192 request_dict.SetString("encrypted_cvc", "__param:s7e_13_cvc"); |
| 191 request_dict.SetString("credit_card_id", request_details_.card.server_id()); | 193 request_dict.SetString("credit_card_id", request_details_.card.server_id()); |
| 192 request_dict.Set("risk_data_encoded", | 194 request_dict.Set("risk_data_encoded", |
| 193 BuildRiskDictionary(request_details_.risk_data)); | 195 BuildRiskDictionary(request_details_.risk_data)); |
| 194 request_dict.Set("context", make_scoped_ptr(new base::DictionaryValue())); | 196 request_dict.Set("context", base::WrapUnique(new base::DictionaryValue())); |
| 195 | 197 |
| 196 int value = 0; | 198 int value = 0; |
| 197 if (base::StringToInt(request_details_.user_response.exp_month, &value)) | 199 if (base::StringToInt(request_details_.user_response.exp_month, &value)) |
| 198 request_dict.SetInteger("expiration_month", value); | 200 request_dict.SetInteger("expiration_month", value); |
| 199 if (base::StringToInt(request_details_.user_response.exp_year, &value)) | 201 if (base::StringToInt(request_details_.user_response.exp_year, &value)) |
| 200 request_dict.SetInteger("expiration_year", value); | 202 request_dict.SetInteger("expiration_year", value); |
| 201 | 203 |
| 202 std::string json_request; | 204 std::string json_request; |
| 203 base::JSONWriter::Write(request_dict, &json_request); | 205 base::JSONWriter::Write(request_dict, &json_request); |
| 204 std::string request_content = base::StringPrintf( | 206 std::string request_content = base::StringPrintf( |
| 205 kUnmaskCardRequestFormat, | 207 kUnmaskCardRequestFormat, |
| 206 net::EscapeUrlEncodedData(json_request, true).c_str(), | 208 net::EscapeUrlEncodedData(json_request, true).c_str(), |
| 207 net::EscapeUrlEncodedData( | 209 net::EscapeUrlEncodedData( |
| 208 base::UTF16ToASCII(request_details_.user_response.cvc), true) | 210 base::UTF16ToASCII(request_details_.user_response.cvc), true) |
| 209 .c_str()); | 211 .c_str()); |
| 210 VLOG(3) << "getrealpan request body: " << request_content; | 212 VLOG(3) << "getrealpan request body: " << request_content; |
| 211 return request_content; | 213 return request_content; |
| 212 } | 214 } |
| 213 | 215 |
| 214 void ParseResponse(scoped_ptr<base::DictionaryValue> response) override { | 216 void ParseResponse(std::unique_ptr<base::DictionaryValue> response) override { |
| 215 response->GetString("pan", &real_pan_); | 217 response->GetString("pan", &real_pan_); |
| 216 } | 218 } |
| 217 | 219 |
| 218 bool IsResponseComplete() override { return !real_pan_.empty(); } | 220 bool IsResponseComplete() override { return !real_pan_.empty(); } |
| 219 | 221 |
| 220 void RespondToDelegate(PaymentsClientDelegate* delegate, | 222 void RespondToDelegate(PaymentsClientDelegate* delegate, |
| 221 AutofillClient::PaymentsRpcResult result) override { | 223 AutofillClient::PaymentsRpcResult result) override { |
| 222 delegate->OnDidGetRealPan(result, real_pan_); | 224 delegate->OnDidGetRealPan(result, real_pan_); |
| 223 } | 225 } |
| 224 | 226 |
| 225 private: | 227 private: |
| 226 PaymentsClient::UnmaskRequestDetails request_details_; | 228 PaymentsClient::UnmaskRequestDetails request_details_; |
| 227 std::string real_pan_; | 229 std::string real_pan_; |
| 228 }; | 230 }; |
| 229 | 231 |
| 230 class GetUploadDetailsRequest : public PaymentsRequest { | 232 class GetUploadDetailsRequest : public PaymentsRequest { |
| 231 public: | 233 public: |
| 232 GetUploadDetailsRequest(const std::string& app_locale) | 234 GetUploadDetailsRequest(const std::string& app_locale) |
| 233 : app_locale_(app_locale) {} | 235 : app_locale_(app_locale) {} |
| 234 ~GetUploadDetailsRequest() override {} | 236 ~GetUploadDetailsRequest() override {} |
| 235 | 237 |
| 236 std::string GetRequestUrlPath() override { | 238 std::string GetRequestUrlPath() override { |
| 237 return kGetUploadDetailsRequestPath; | 239 return kGetUploadDetailsRequestPath; |
| 238 } | 240 } |
| 239 | 241 |
| 240 std::string GetRequestContentType() override { return "application/json"; } | 242 std::string GetRequestContentType() override { return "application/json"; } |
| 241 | 243 |
| 242 std::string GetRequestContent() override { | 244 std::string GetRequestContent() override { |
| 243 base::DictionaryValue request_dict; | 245 base::DictionaryValue request_dict; |
| 244 scoped_ptr<base::DictionaryValue> context(new base::DictionaryValue()); | 246 std::unique_ptr<base::DictionaryValue> context(new base::DictionaryValue()); |
| 245 context->SetString("language_code", app_locale_); | 247 context->SetString("language_code", app_locale_); |
| 246 request_dict.Set("context", std::move(context)); | 248 request_dict.Set("context", std::move(context)); |
| 247 | 249 |
| 248 std::string request_content; | 250 std::string request_content; |
| 249 base::JSONWriter::Write(request_dict, &request_content); | 251 base::JSONWriter::Write(request_dict, &request_content); |
| 250 VLOG(3) << "getdetailsforsavecard request body: " << request_content; | 252 VLOG(3) << "getdetailsforsavecard request body: " << request_content; |
| 251 return request_content; | 253 return request_content; |
| 252 } | 254 } |
| 253 | 255 |
| 254 void ParseResponse(scoped_ptr<base::DictionaryValue> response) override { | 256 void ParseResponse(std::unique_ptr<base::DictionaryValue> response) override { |
| 255 response->GetString("context_token", &context_token_); | 257 response->GetString("context_token", &context_token_); |
| 256 base::DictionaryValue* unowned_legal_message; | 258 base::DictionaryValue* unowned_legal_message; |
| 257 if (response->GetDictionary("legal_message", &unowned_legal_message)) | 259 if (response->GetDictionary("legal_message", &unowned_legal_message)) |
| 258 legal_message_ = unowned_legal_message->CreateDeepCopy(); | 260 legal_message_ = unowned_legal_message->CreateDeepCopy(); |
| 259 } | 261 } |
| 260 | 262 |
| 261 bool IsResponseComplete() override { | 263 bool IsResponseComplete() override { |
| 262 return !context_token_.empty() && legal_message_; | 264 return !context_token_.empty() && legal_message_; |
| 263 } | 265 } |
| 264 | 266 |
| 265 void RespondToDelegate(PaymentsClientDelegate* delegate, | 267 void RespondToDelegate(PaymentsClientDelegate* delegate, |
| 266 AutofillClient::PaymentsRpcResult result) override { | 268 AutofillClient::PaymentsRpcResult result) override { |
| 267 delegate->OnDidGetUploadDetails(result, context_token_, | 269 delegate->OnDidGetUploadDetails(result, context_token_, |
| 268 std::move(legal_message_)); | 270 std::move(legal_message_)); |
| 269 } | 271 } |
| 270 | 272 |
| 271 private: | 273 private: |
| 272 std::string app_locale_; | 274 std::string app_locale_; |
| 273 base::string16 context_token_; | 275 base::string16 context_token_; |
| 274 scoped_ptr<base::DictionaryValue> legal_message_; | 276 std::unique_ptr<base::DictionaryValue> legal_message_; |
| 275 }; | 277 }; |
| 276 | 278 |
| 277 class UploadCardRequest : public PaymentsRequest { | 279 class UploadCardRequest : public PaymentsRequest { |
| 278 public: | 280 public: |
| 279 UploadCardRequest(const PaymentsClient::UploadRequestDetails& request_details) | 281 UploadCardRequest(const PaymentsClient::UploadRequestDetails& request_details) |
| 280 : request_details_(request_details) {} | 282 : request_details_(request_details) {} |
| 281 ~UploadCardRequest() override {} | 283 ~UploadCardRequest() override {} |
| 282 | 284 |
| 283 std::string GetRequestUrlPath() override { return kUploadCardRequestPath; } | 285 std::string GetRequestUrlPath() override { return kUploadCardRequestPath; } |
| 284 | 286 |
| 285 std::string GetRequestContentType() override { | 287 std::string GetRequestContentType() override { |
| 286 return "application/x-www-form-urlencoded"; | 288 return "application/x-www-form-urlencoded"; |
| 287 } | 289 } |
| 288 | 290 |
| 289 std::string GetRequestContent() override { | 291 std::string GetRequestContent() override { |
| 290 base::DictionaryValue request_dict; | 292 base::DictionaryValue request_dict; |
| 291 request_dict.SetString("encrypted_pan", "__param:s7e_1_pan"); | 293 request_dict.SetString("encrypted_pan", "__param:s7e_1_pan"); |
| 292 request_dict.SetString("encrypted_cvc", "__param:s7e_13_cvc"); | 294 request_dict.SetString("encrypted_cvc", "__param:s7e_13_cvc"); |
| 293 request_dict.Set("risk_data_encoded", | 295 request_dict.Set("risk_data_encoded", |
| 294 BuildRiskDictionary(request_details_.risk_data)); | 296 BuildRiskDictionary(request_details_.risk_data)); |
| 295 | 297 |
| 296 const std::string& app_locale = request_details_.app_locale; | 298 const std::string& app_locale = request_details_.app_locale; |
| 297 scoped_ptr<base::DictionaryValue> context(new base::DictionaryValue()); | 299 std::unique_ptr<base::DictionaryValue> context(new base::DictionaryValue()); |
| 298 context->SetString("language_code", app_locale); | 300 context->SetString("language_code", app_locale); |
| 299 request_dict.Set("context", std::move(context)); | 301 request_dict.Set("context", std::move(context)); |
| 300 | 302 |
| 301 SetStringIfNotEmpty(request_details_.card, CREDIT_CARD_NAME_FULL, | 303 SetStringIfNotEmpty(request_details_.card, CREDIT_CARD_NAME_FULL, |
| 302 app_locale, "cardholder_name", &request_dict); | 304 app_locale, "cardholder_name", &request_dict); |
| 303 | 305 |
| 304 scoped_ptr<base::ListValue> addresses(new base::ListValue()); | 306 std::unique_ptr<base::ListValue> addresses(new base::ListValue()); |
| 305 for (const AutofillProfile& profile : request_details_.profiles) { | 307 for (const AutofillProfile& profile : request_details_.profiles) { |
| 306 addresses->Append(BuildAddressDictionary(profile, app_locale)); | 308 addresses->Append(BuildAddressDictionary(profile, app_locale)); |
| 307 } | 309 } |
| 308 request_dict.Set("address", std::move(addresses)); | 310 request_dict.Set("address", std::move(addresses)); |
| 309 | 311 |
| 310 request_dict.SetString("context_token", request_details_.context_token); | 312 request_dict.SetString("context_token", request_details_.context_token); |
| 311 | 313 |
| 312 int value = 0; | 314 int value = 0; |
| 313 const base::string16 exp_month = request_details_.card.GetInfo( | 315 const base::string16 exp_month = request_details_.card.GetInfo( |
| 314 AutofillType(CREDIT_CARD_EXP_MONTH), app_locale); | 316 AutofillType(CREDIT_CARD_EXP_MONTH), app_locale); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 327 kUploadCardRequestFormat, | 329 kUploadCardRequestFormat, |
| 328 net::EscapeUrlEncodedData(json_request, true).c_str(), | 330 net::EscapeUrlEncodedData(json_request, true).c_str(), |
| 329 net::EscapeUrlEncodedData(base::UTF16ToASCII(pan), true).c_str(), | 331 net::EscapeUrlEncodedData(base::UTF16ToASCII(pan), true).c_str(), |
| 330 net::EscapeUrlEncodedData(base::UTF16ToASCII(request_details_.cvc), | 332 net::EscapeUrlEncodedData(base::UTF16ToASCII(request_details_.cvc), |
| 331 true) | 333 true) |
| 332 .c_str()); | 334 .c_str()); |
| 333 VLOG(3) << "savecard request body: " << request_content; | 335 VLOG(3) << "savecard request body: " << request_content; |
| 334 return request_content; | 336 return request_content; |
| 335 } | 337 } |
| 336 | 338 |
| 337 void ParseResponse(scoped_ptr<base::DictionaryValue> response) override {} | 339 void ParseResponse(std::unique_ptr<base::DictionaryValue> response) override { |
| 340 } |
| 338 | 341 |
| 339 bool IsResponseComplete() override { return true; } | 342 bool IsResponseComplete() override { return true; } |
| 340 | 343 |
| 341 void RespondToDelegate(PaymentsClientDelegate* delegate, | 344 void RespondToDelegate(PaymentsClientDelegate* delegate, |
| 342 AutofillClient::PaymentsRpcResult result) override { | 345 AutofillClient::PaymentsRpcResult result) override { |
| 343 delegate->OnDidUploadCard(result); | 346 delegate->OnDidUploadCard(result); |
| 344 } | 347 } |
| 345 | 348 |
| 346 private: | 349 private: |
| 347 PaymentsClient::UploadRequestDetails request_details_; | 350 PaymentsClient::UploadRequestDetails request_details_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 369 | 372 |
| 370 PaymentsClient::~PaymentsClient() {} | 373 PaymentsClient::~PaymentsClient() {} |
| 371 | 374 |
| 372 void PaymentsClient::Prepare() { | 375 void PaymentsClient::Prepare() { |
| 373 if (access_token_.empty()) | 376 if (access_token_.empty()) |
| 374 StartTokenFetch(false); | 377 StartTokenFetch(false); |
| 375 } | 378 } |
| 376 | 379 |
| 377 void PaymentsClient::UnmaskCard( | 380 void PaymentsClient::UnmaskCard( |
| 378 const PaymentsClient::UnmaskRequestDetails& request_details) { | 381 const PaymentsClient::UnmaskRequestDetails& request_details) { |
| 379 IssueRequest(make_scoped_ptr(new UnmaskCardRequest(request_details)), true); | 382 IssueRequest(base::WrapUnique(new UnmaskCardRequest(request_details)), true); |
| 380 } | 383 } |
| 381 | 384 |
| 382 void PaymentsClient::GetUploadDetails(const std::string& app_locale) { | 385 void PaymentsClient::GetUploadDetails(const std::string& app_locale) { |
| 383 IssueRequest(make_scoped_ptr(new GetUploadDetailsRequest(app_locale)), false); | 386 IssueRequest(base::WrapUnique(new GetUploadDetailsRequest(app_locale)), |
| 387 false); |
| 384 } | 388 } |
| 385 | 389 |
| 386 void PaymentsClient::UploadCard( | 390 void PaymentsClient::UploadCard( |
| 387 const PaymentsClient::UploadRequestDetails& request_details) { | 391 const PaymentsClient::UploadRequestDetails& request_details) { |
| 388 IssueRequest(make_scoped_ptr(new UploadCardRequest(request_details)), true); | 392 IssueRequest(base::WrapUnique(new UploadCardRequest(request_details)), true); |
| 389 } | 393 } |
| 390 | 394 |
| 391 void PaymentsClient::IssueRequest(scoped_ptr<PaymentsRequest> request, | 395 void PaymentsClient::IssueRequest(std::unique_ptr<PaymentsRequest> request, |
| 392 bool authenticate) { | 396 bool authenticate) { |
| 393 request_ = std::move(request); | 397 request_ = std::move(request); |
| 394 has_retried_authorization_ = false; | 398 has_retried_authorization_ = false; |
| 395 InitializeUrlFetcher(); | 399 InitializeUrlFetcher(); |
| 396 | 400 |
| 397 if (!authenticate) | 401 if (!authenticate) |
| 398 url_fetcher_->Start(); | 402 url_fetcher_->Start(); |
| 399 else if (access_token_.empty()) | 403 else if (access_token_.empty()) |
| 400 StartTokenFetch(false); | 404 StartTokenFetch(false); |
| 401 else | 405 else |
| (...skipping 22 matching lines...) Expand all Loading... |
| 424 access_token_request_.reset(); | 428 access_token_request_.reset(); |
| 425 access_token_.clear(); | 429 access_token_.clear(); |
| 426 has_retried_authorization_ = false; | 430 has_retried_authorization_ = false; |
| 427 } | 431 } |
| 428 | 432 |
| 429 void PaymentsClient::OnURLFetchComplete(const net::URLFetcher* source) { | 433 void PaymentsClient::OnURLFetchComplete(const net::URLFetcher* source) { |
| 430 DCHECK_EQ(source, url_fetcher_.get()); | 434 DCHECK_EQ(source, url_fetcher_.get()); |
| 431 | 435 |
| 432 // |url_fetcher_|, which is aliased to |source|, might continue to be used in | 436 // |url_fetcher_|, which is aliased to |source|, might continue to be used in |
| 433 // this method, but should be freed once control leaves the method. | 437 // this method, but should be freed once control leaves the method. |
| 434 scoped_ptr<net::URLFetcher> scoped_url_fetcher(std::move(url_fetcher_)); | 438 std::unique_ptr<net::URLFetcher> scoped_url_fetcher(std::move(url_fetcher_)); |
| 435 scoped_ptr<base::DictionaryValue> response_dict; | 439 std::unique_ptr<base::DictionaryValue> response_dict; |
| 436 int response_code = source->GetResponseCode(); | 440 int response_code = source->GetResponseCode(); |
| 437 std::string data; | 441 std::string data; |
| 438 source->GetResponseAsString(&data); | 442 source->GetResponseAsString(&data); |
| 439 VLOG(2) << "Got data: " << data; | 443 VLOG(2) << "Got data: " << data; |
| 440 | 444 |
| 441 AutofillClient::PaymentsRpcResult result = AutofillClient::SUCCESS; | 445 AutofillClient::PaymentsRpcResult result = AutofillClient::SUCCESS; |
| 442 | 446 |
| 443 switch (response_code) { | 447 switch (response_code) { |
| 444 // Valid response. | 448 // Valid response. |
| 445 case net::HTTP_OK: { | 449 case net::HTTP_OK: { |
| 446 std::string error_code; | 450 std::string error_code; |
| 447 scoped_ptr<base::Value> message_value = base::JSONReader::Read(data); | 451 std::unique_ptr<base::Value> message_value = base::JSONReader::Read(data); |
| 448 if (message_value.get() && | 452 if (message_value.get() && |
| 449 message_value->IsType(base::Value::TYPE_DICTIONARY)) { | 453 message_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 450 response_dict.reset( | 454 response_dict.reset( |
| 451 static_cast<base::DictionaryValue*>(message_value.release())); | 455 static_cast<base::DictionaryValue*>(message_value.release())); |
| 452 response_dict->GetString("error.code", &error_code); | 456 response_dict->GetString("error.code", &error_code); |
| 453 request_->ParseResponse(std::move(response_dict)); | 457 request_->ParseResponse(std::move(response_dict)); |
| 454 } | 458 } |
| 455 | 459 |
| 456 if (base::LowerCaseEqualsASCII(error_code, "internal")) | 460 if (base::LowerCaseEqualsASCII(error_code, "internal")) |
| 457 result = AutofillClient::TRY_AGAIN_FAILURE; | 461 result = AutofillClient::TRY_AGAIN_FAILURE; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 543 |
| 540 void PaymentsClient::SetOAuth2TokenAndStartRequest() { | 544 void PaymentsClient::SetOAuth2TokenAndStartRequest() { |
| 541 url_fetcher_->AddExtraRequestHeader(net::HttpRequestHeaders::kAuthorization + | 545 url_fetcher_->AddExtraRequestHeader(net::HttpRequestHeaders::kAuthorization + |
| 542 std::string(": Bearer ") + access_token_); | 546 std::string(": Bearer ") + access_token_); |
| 543 | 547 |
| 544 url_fetcher_->Start(); | 548 url_fetcher_->Start(); |
| 545 } | 549 } |
| 546 | 550 |
| 547 } // namespace payments | 551 } // namespace payments |
| 548 } // namespace autofill | 552 } // namespace autofill |
| OLD | NEW |