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

Side by Side Diff: components/payments/core/payment_method_data.cc

Issue 2797833002: [Payments] base::string16 -> std::string in PaymentMethodData (Closed)
Patch Set: Clean Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/payments/core/payment_method_data.h" 5 #include "components/payments/core/payment_method_data.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 9 #include "base/values.h"
11 10
12 namespace payments { 11 namespace payments {
13 12
14 namespace { 13 namespace {
15 14
16 // These are defined as part of the spec at: 15 // These are defined as part of the spec at:
17 // https://w3c.github.io/browser-payment-api/#paymentmethoddata-dictionary 16 // https://w3c.github.io/browser-payment-api/#paymentmethoddata-dictionary
18 static const char kMethodDataData[] = "data"; 17 static const char kMethodDataData[] = "data";
19 static const char kSupportedMethods[] = "supportedMethods"; 18 static const char kSupportedMethods[] = "supportedMethods";
(...skipping 23 matching lines...) Expand all
43 this->supported_networks.clear(); 42 this->supported_networks.clear();
44 this->supported_types.clear(); 43 this->supported_types.clear();
45 44
46 const base::ListValue* supported_methods_list = nullptr; 45 const base::ListValue* supported_methods_list = nullptr;
47 // At least one supported method is required. 46 // At least one supported method is required.
48 if (!value.GetList(kSupportedMethods, &supported_methods_list) || 47 if (!value.GetList(kSupportedMethods, &supported_methods_list) ||
49 supported_methods_list->GetSize() == 0) { 48 supported_methods_list->GetSize() == 0) {
50 return false; 49 return false;
51 } 50 }
52 for (size_t i = 0; i < supported_methods_list->GetSize(); ++i) { 51 for (size_t i = 0; i < supported_methods_list->GetSize(); ++i) {
53 base::string16 supported_method; 52 std::string supported_method;
54 if (!supported_methods_list->GetString(i, &supported_method)) { 53 if (!supported_methods_list->GetString(i, &supported_method)) {
55 return false; 54 return false;
56 } 55 }
57 this->supported_methods.push_back(supported_method); 56 this->supported_methods.push_back(supported_method);
58 } 57 }
59 58
60 // Data is optional, but if a dictionary is present, save a stringified 59 // Data is optional, but if a dictionary is present, save a stringified
61 // version and attempt to parse supportedNetworks/supportedTypes. 60 // version and attempt to parse supportedNetworks/supportedTypes.
62 const base::DictionaryValue* data_dict = nullptr; 61 const base::DictionaryValue* data_dict = nullptr;
63 if (value.GetDictionary(kMethodDataData, &data_dict)) { 62 if (value.GetDictionary(kMethodDataData, &data_dict)) {
64 std::string json_data; 63 std::string json_data;
65 base::JSONWriter::Write(*data_dict, &json_data); 64 base::JSONWriter::Write(*data_dict, &json_data);
66 this->data = base::UTF8ToUTF16(json_data); 65 this->data = json_data;
67 const base::ListValue* supported_networks_list = nullptr; 66 const base::ListValue* supported_networks_list = nullptr;
68 if (data_dict->GetList(kSupportedNetworks, &supported_networks_list)) { 67 if (data_dict->GetList(kSupportedNetworks, &supported_networks_list)) {
69 for (size_t i = 0; i < supported_networks_list->GetSize(); ++i) { 68 for (size_t i = 0; i < supported_networks_list->GetSize(); ++i) {
70 base::string16 supported_network; 69 std::string supported_network;
71 if (!supported_networks_list->GetString(i, &supported_network)) { 70 if (!supported_networks_list->GetString(i, &supported_network)) {
72 return false; 71 return false;
73 } 72 }
74 this->supported_networks.push_back(supported_network); 73 this->supported_networks.push_back(supported_network);
75 } 74 }
76 } 75 }
77 const base::ListValue* supported_types_list = nullptr; 76 const base::ListValue* supported_types_list = nullptr;
78 if (data_dict->GetList(kSupportedTypes, &supported_types_list)) { 77 if (data_dict->GetList(kSupportedTypes, &supported_types_list)) {
79 for (size_t i = 0; i < supported_types_list->GetSize(); ++i) { 78 for (size_t i = 0; i < supported_types_list->GetSize(); ++i) {
80 base::string16 supported_type; 79 std::string supported_type;
81 if (!supported_types_list->GetString(i, &supported_type)) { 80 if (!supported_types_list->GetString(i, &supported_type)) {
82 return false; 81 return false;
83 } 82 }
84 this->supported_types.push_back(supported_type); 83 this->supported_types.push_back(supported_type);
85 } 84 }
86 } 85 }
87 } 86 }
88 return true; 87 return true;
89 } 88 }
90 89
91 } // namespace payments 90 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698