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

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

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 years, 7 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
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_client.h" 5 #include "components/autofill/content/browser/wallet/wallet_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 288
289 void WalletClient::AuthenticateInstrument( 289 void WalletClient::AuthenticateInstrument(
290 const std::string& instrument_id, 290 const std::string& instrument_id,
291 const std::string& card_verification_number) { 291 const std::string& card_verification_number) {
292 base::DictionaryValue request_dict; 292 base::DictionaryValue request_dict;
293 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey()); 293 request_dict.SetString(kApiKeyKey, google_apis::GetAPIKey());
294 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData()); 294 request_dict.SetString(kRiskParamsKey, delegate_->GetRiskData());
295 request_dict.SetString(kInstrumentIdKey, instrument_id); 295 request_dict.SetString(kInstrumentIdKey, instrument_id);
296 296
297 std::string json_payload; 297 std::string json_payload;
298 base::JSONWriter::Write(&request_dict, &json_payload); 298 base::JSONWriter::Write(request_dict, &json_payload);
299 299
300 std::string escaped_card_verification_number = net::EscapeUrlEncodedData( 300 std::string escaped_card_verification_number = net::EscapeUrlEncodedData(
301 card_verification_number, true); 301 card_verification_number, true);
302 302
303 std::string post_body = base::StringPrintf( 303 std::string post_body = base::StringPrintf(
304 kEscrowCardVerificationNumberFormat, 304 kEscrowCardVerificationNumberFormat,
305 net::EscapeUrlEncodedData(json_payload, true).c_str(), 305 net::EscapeUrlEncodedData(json_payload, true).c_str(),
306 escaped_card_verification_number.c_str()); 306 escaped_card_verification_number.c_str());
307 307
308 MakeWalletRequest(GetAuthenticateInstrumentUrl(user_index_), 308 MakeWalletRequest(GetAuthenticateInstrumentUrl(user_index_),
(...skipping 23 matching lines...) Expand all
332 scoped_ptr<base::ListValue> risk_capabilities_list(new base::ListValue()); 332 scoped_ptr<base::ListValue> risk_capabilities_list(new base::ListValue());
333 for (std::vector<RiskCapability>::const_iterator it = 333 for (std::vector<RiskCapability>::const_iterator it =
334 full_wallet_request.risk_capabilities.begin(); 334 full_wallet_request.risk_capabilities.begin();
335 it != full_wallet_request.risk_capabilities.end(); 335 it != full_wallet_request.risk_capabilities.end();
336 ++it) { 336 ++it) {
337 risk_capabilities_list->AppendString(RiskCapabilityToString(*it)); 337 risk_capabilities_list->AppendString(RiskCapabilityToString(*it));
338 } 338 }
339 request_dict.Set(kRiskCapabilitiesKey, risk_capabilities_list.release()); 339 request_dict.Set(kRiskCapabilitiesKey, risk_capabilities_list.release());
340 340
341 std::string json_payload; 341 std::string json_payload;
342 base::JSONWriter::Write(&request_dict, &json_payload); 342 base::JSONWriter::Write(request_dict, &json_payload);
343 343
344 crypto::RandBytes(&(one_time_pad_[0]), one_time_pad_.size()); 344 crypto::RandBytes(&(one_time_pad_[0]), one_time_pad_.size());
345 345
346 size_t num_bits = one_time_pad_.size() * 8; 346 size_t num_bits = one_time_pad_.size() * 8;
347 DCHECK_LE(num_bits, kMaxBits); 347 DCHECK_LE(num_bits, kMaxBits);
348 DCHECK_GE(num_bits, kMinBits); 348 DCHECK_GE(num_bits, kMinBits);
349 349
350 std::string post_body = base::StringPrintf( 350 std::string post_body = base::StringPrintf(
351 kGetFullWalletRequestFormat, 351 kGetFullWalletRequestFormat,
352 net::EscapeUrlEncodedData(json_payload, true).c_str(), 352 net::EscapeUrlEncodedData(json_payload, true).c_str(),
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 if (address) { 424 if (address) {
425 if (reference_address) { 425 if (reference_address) {
426 address->set_object_id(reference_address->object_id()); 426 address->set_object_id(reference_address->object_id());
427 DCHECK(!address->object_id().empty()); 427 DCHECK(!address->object_id().empty());
428 } 428 }
429 request_dict.Set(kShippingAddressKey, 429 request_dict.Set(kShippingAddressKey,
430 address->ToDictionaryWithID().release()); 430 address->ToDictionaryWithID().release());
431 } 431 }
432 432
433 std::string json_payload; 433 std::string json_payload;
434 base::JSONWriter::Write(&request_dict, &json_payload); 434 base::JSONWriter::Write(request_dict, &json_payload);
435 435
436 if (!card_verification_number.empty()) { 436 if (!card_verification_number.empty()) {
437 std::string post_body; 437 std::string post_body;
438 if (!primary_account_number.empty()) { 438 if (!primary_account_number.empty()) {
439 post_body = base::StringPrintf( 439 post_body = base::StringPrintf(
440 kEscrowNewInstrumentFormat, 440 kEscrowNewInstrumentFormat,
441 net::EscapeUrlEncodedData(json_payload, true).c_str(), 441 net::EscapeUrlEncodedData(json_payload, true).c_str(),
442 card_verification_number.c_str(), 442 card_verification_number.c_str(),
443 primary_account_number.c_str()); 443 primary_account_number.c_str());
444 } else { 444 } else {
(...skipping 24 matching lines...) Expand all
469 delegate_->IsShippingAddressRequired()); 469 delegate_->IsShippingAddressRequired());
470 request_dict.SetBoolean(kUseMinimalAddresses, false); 470 request_dict.SetBoolean(kUseMinimalAddresses, false);
471 request_dict.SetBoolean(kPhoneNumberRequired, true); 471 request_dict.SetBoolean(kPhoneNumberRequired, true);
472 472
473 if (!amount.empty()) 473 if (!amount.empty())
474 request_dict.SetString(kTransactionAmountKey, amount); 474 request_dict.SetString(kTransactionAmountKey, amount);
475 if (!currency.empty()) 475 if (!currency.empty())
476 request_dict.SetString(kTransactionCurrencyKey, currency); 476 request_dict.SetString(kTransactionCurrencyKey, currency);
477 477
478 std::string post_body; 478 std::string post_body;
479 base::JSONWriter::Write(&request_dict, &post_body); 479 base::JSONWriter::Write(request_dict, &post_body);
480 480
481 MakeWalletRequest(GetGetWalletItemsUrl(user_index_), 481 MakeWalletRequest(GetGetWalletItemsUrl(user_index_),
482 post_body, 482 post_body,
483 kJsonMimeType, 483 kJsonMimeType,
484 GET_WALLET_ITEMS); 484 GET_WALLET_ITEMS);
485 } 485 }
486 486
487 bool WalletClient::HasRequestInProgress() const { 487 bool WalletClient::HasRequestInProgress() const {
488 return request_; 488 return request_;
489 } 489 }
(...skipping 18 matching lines...) Expand all
508 source_url_.GetWithEmptyPath().spec()); 508 source_url_.GetWithEmptyPath().spec());
509 scoped_ptr<base::ListValue> docs_list(new base::ListValue()); 509 scoped_ptr<base::ListValue> docs_list(new base::ListValue());
510 for (std::vector<std::string>::const_iterator it = document_ids.begin(); 510 for (std::vector<std::string>::const_iterator it = document_ids.begin();
511 it != document_ids.end(); ++it) { 511 it != document_ids.end(); ++it) {
512 if (!it->empty()) 512 if (!it->empty())
513 docs_list->AppendString(*it); 513 docs_list->AppendString(*it);
514 } 514 }
515 request_dict.Set(kAcceptedLegalDocumentKey, docs_list.release()); 515 request_dict.Set(kAcceptedLegalDocumentKey, docs_list.release());
516 516
517 std::string post_body; 517 std::string post_body;
518 base::JSONWriter::Write(&request_dict, &post_body); 518 base::JSONWriter::Write(request_dict, &post_body);
519 519
520 MakeWalletRequest(GetAcceptLegalDocumentsUrl(user_index_), 520 MakeWalletRequest(GetAcceptLegalDocumentsUrl(user_index_),
521 post_body, 521 post_body,
522 kJsonMimeType, 522 kJsonMimeType,
523 ACCEPT_LEGAL_DOCUMENTS); 523 ACCEPT_LEGAL_DOCUMENTS);
524 } 524 }
525 525
526 void WalletClient::MakeWalletRequest(const GURL& url, 526 void WalletClient::MakeWalletRequest(const GURL& url,
527 const std::string& post_body, 527 const std::string& post_body,
528 const std::string& mime_type, 528 const std::string& mime_type,
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 NOTREACHED(); 798 NOTREACHED();
799 return AutofillMetrics::UNKNOWN_API_CALL; 799 return AutofillMetrics::UNKNOWN_API_CALL;
800 } 800 }
801 801
802 NOTREACHED(); 802 NOTREACHED();
803 return AutofillMetrics::UNKNOWN_API_CALL; 803 return AutofillMetrics::UNKNOWN_API_CALL;
804 } 804 }
805 805
806 } // namespace wallet 806 } // namespace wallet
807 } // namespace autofill 807 } // namespace autofill
OLDNEW
« no previous file with comments | « cloud_print/service/win/service_listener.cc ('k') | components/autofill/content/browser/wallet/wallet_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698