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

Side by Side Diff: chrome/browser/extensions/api/autofill_private/autofill_util.cc

Issue 1825263002: [Extensions] Convert APIs to use movable types [1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Antony's Created 4 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 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 "chrome/browser/extensions/api/autofill_private/autofill_util.h" 5 #include "chrome/browser/extensions/api/autofill_private/autofill_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 55
56 // Gets the string corresponding to |type| from |profile|. 56 // Gets the string corresponding to |type| from |profile|.
57 scoped_ptr<std::string> GetStringFromProfile( 57 scoped_ptr<std::string> GetStringFromProfile(
58 const autofill::AutofillProfile& profile, 58 const autofill::AutofillProfile& profile,
59 const autofill::ServerFieldType& type) { 59 const autofill::ServerFieldType& type) {
60 return make_scoped_ptr( 60 return make_scoped_ptr(
61 new std::string(base::UTF16ToUTF8(profile.GetRawInfo(type)))); 61 new std::string(base::UTF16ToUTF8(profile.GetRawInfo(type))));
62 } 62 }
63 63
64 scoped_ptr<autofill_private::AddressEntry> ProfileToAddressEntry( 64 autofill_private::AddressEntry ProfileToAddressEntry(
65 const autofill::AutofillProfile& profile, 65 const autofill::AutofillProfile& profile,
66 const base::string16& label) { 66 const base::string16& label) {
67 scoped_ptr<autofill_private::AddressEntry> 67 autofill_private::AddressEntry address;
68 address(new autofill_private::AddressEntry);
69 68
70 // Add all address fields to the entry. 69 // Add all address fields to the entry.
71 address->guid.reset(new std::string(profile.guid())); 70 address.guid.reset(new std::string(profile.guid()));
72 address->full_names = GetValueList(profile, autofill::NAME_FULL); 71 address.full_names = GetValueList(profile, autofill::NAME_FULL);
73 address->company_name.reset(GetStringFromProfile( 72 address.company_name.reset(
74 profile, autofill::COMPANY_NAME).release()); 73 GetStringFromProfile(profile, autofill::COMPANY_NAME).release());
75 address->address_lines.reset(GetStringFromProfile( 74 address.address_lines.reset(
76 profile, autofill::ADDRESS_HOME_STREET_ADDRESS).release()); 75 GetStringFromProfile(profile, autofill::ADDRESS_HOME_STREET_ADDRESS)
77 address->address_level1.reset(GetStringFromProfile( 76 .release());
78 profile, autofill::ADDRESS_HOME_STATE).release()); 77 address.address_level1.reset(
79 address->address_level2.reset(GetStringFromProfile( 78 GetStringFromProfile(profile, autofill::ADDRESS_HOME_STATE).release());
80 profile, autofill::ADDRESS_HOME_CITY).release()); 79 address.address_level2.reset(
81 address->address_level3.reset(GetStringFromProfile( 80 GetStringFromProfile(profile, autofill::ADDRESS_HOME_CITY).release());
82 profile, autofill::ADDRESS_HOME_DEPENDENT_LOCALITY).release()); 81 address.address_level3.reset(
83 address->postal_code.reset(GetStringFromProfile( 82 GetStringFromProfile(profile, autofill::ADDRESS_HOME_DEPENDENT_LOCALITY)
84 profile, autofill::ADDRESS_HOME_ZIP).release()); 83 .release());
85 address->sorting_code.reset(GetStringFromProfile( 84 address.postal_code.reset(
86 profile, autofill::ADDRESS_HOME_SORTING_CODE).release()); 85 GetStringFromProfile(profile, autofill::ADDRESS_HOME_ZIP).release());
87 address->country_code.reset(GetStringFromProfile( 86 address.sorting_code.reset(
88 profile, autofill::ADDRESS_HOME_COUNTRY).release()); 87 GetStringFromProfile(profile, autofill::ADDRESS_HOME_SORTING_CODE)
89 address->phone_numbers = 88 .release());
89 address.country_code.reset(
90 GetStringFromProfile(profile, autofill::ADDRESS_HOME_COUNTRY).release());
91 address.phone_numbers =
90 GetValueList(profile, autofill::PHONE_HOME_WHOLE_NUMBER); 92 GetValueList(profile, autofill::PHONE_HOME_WHOLE_NUMBER);
91 address->email_addresses = 93 address.email_addresses = GetValueList(profile, autofill::EMAIL_ADDRESS);
92 GetValueList(profile, autofill::EMAIL_ADDRESS); 94 address.language_code.reset(new std::string(profile.language_code()));
93 address->language_code.reset(new std::string(profile.language_code()));
94 95
95 // Parse |label| so that it can be used to create address metadata. 96 // Parse |label| so that it can be used to create address metadata.
96 base::string16 separator = 97 base::string16 separator =
97 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); 98 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR);
98 std::vector<base::string16> label_pieces; 99 std::vector<base::string16> label_pieces;
99 base::SplitStringUsingSubstr(label, separator, &label_pieces); 100 base::SplitStringUsingSubstr(label, separator, &label_pieces);
100 101
101 // Create address metadata and add it to |address|. 102 // Create address metadata and add it to |address|.
102 scoped_ptr<autofill_private::AutofillMetadata> 103 scoped_ptr<autofill_private::AutofillMetadata>
103 metadata(new autofill_private::AutofillMetadata); 104 metadata(new autofill_private::AutofillMetadata);
104 metadata->summary_label = base::UTF16ToUTF8(label_pieces[0]); 105 metadata->summary_label = base::UTF16ToUTF8(label_pieces[0]);
105 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8( 106 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8(
106 label.substr(label_pieces[0].size())))); 107 label.substr(label_pieces[0].size()))));
107 metadata->is_local.reset(new bool( 108 metadata->is_local.reset(new bool(
108 profile.record_type() == autofill::AutofillProfile::LOCAL_PROFILE)); 109 profile.record_type() == autofill::AutofillProfile::LOCAL_PROFILE));
109 address->metadata = std::move(metadata); 110 address.metadata = std::move(metadata);
110 111
111 return address; 112 return address;
112 } 113 }
113 114
114 scoped_ptr<autofill_private::CreditCardEntry> CreditCardToCreditCardEntry( 115 autofill_private::CreditCardEntry CreditCardToCreditCardEntry(
115 const autofill::CreditCard& credit_card) { 116 const autofill::CreditCard& credit_card) {
116 scoped_ptr<autofill_private::CreditCardEntry> 117 autofill_private::CreditCardEntry card;
117 card(new autofill_private::CreditCardEntry);
118 118
119 // Add all credit card fields to the entry. 119 // Add all credit card fields to the entry.
120 card->guid.reset(new std::string(credit_card.guid())); 120 card.guid.reset(new std::string(credit_card.guid()));
121 card->name.reset(new std::string(base::UTF16ToUTF8( 121 card.name.reset(new std::string(base::UTF16ToUTF8(
122 credit_card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)))); 122 credit_card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL))));
123 card->card_number.reset(new std::string(base::UTF16ToUTF8( 123 card.card_number.reset(new std::string(
124 credit_card.GetRawInfo(autofill::CREDIT_CARD_NUMBER)))); 124 base::UTF16ToUTF8(credit_card.GetRawInfo(autofill::CREDIT_CARD_NUMBER))));
125 card->expiration_month.reset(new std::string(base::UTF16ToUTF8( 125 card.expiration_month.reset(new std::string(base::UTF16ToUTF8(
126 credit_card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH)))); 126 credit_card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH))));
127 card->expiration_year.reset(new std::string(base::UTF16ToUTF8( 127 card.expiration_year.reset(new std::string(base::UTF16ToUTF8(
128 credit_card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR)))); 128 credit_card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR))));
129 129
130 // Create address metadata and add it to |address|. 130 // Create address metadata and add it to |address|.
131 scoped_ptr<autofill_private::AutofillMetadata> 131 scoped_ptr<autofill_private::AutofillMetadata>
132 metadata(new autofill_private::AutofillMetadata); 132 metadata(new autofill_private::AutofillMetadata);
133 std::pair<base::string16, base::string16> label_pieces = 133 std::pair<base::string16, base::string16> label_pieces =
134 credit_card.LabelPieces(); 134 credit_card.LabelPieces();
135 metadata->summary_label = base::UTF16ToUTF8(label_pieces.first); 135 metadata->summary_label = base::UTF16ToUTF8(label_pieces.first);
136 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8( 136 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8(
137 label_pieces.second))); 137 label_pieces.second)));
138 metadata->is_local.reset(new bool( 138 metadata->is_local.reset(new bool(
139 credit_card.record_type() == autofill::CreditCard::LOCAL_CARD)); 139 credit_card.record_type() == autofill::CreditCard::LOCAL_CARD));
140 metadata->is_cached.reset(new bool( 140 metadata->is_cached.reset(new bool(
141 credit_card.record_type() == autofill::CreditCard::FULL_SERVER_CARD)); 141 credit_card.record_type() == autofill::CreditCard::FULL_SERVER_CARD));
142 card->metadata = std::move(metadata); 142 card.metadata = std::move(metadata);
143 143
144 return card; 144 return card;
145 } 145 }
146 146
147 } // namespace 147 } // namespace
148 148
149 namespace extensions { 149 namespace extensions {
150 150
151 namespace autofill_util { 151 namespace autofill_util {
152 152
153 scoped_ptr<AddressEntryList> GenerateAddressList( 153 AddressEntryList GenerateAddressList(
154 const autofill::PersonalDataManager& personal_data) { 154 const autofill::PersonalDataManager& personal_data) {
155 const std::vector<autofill::AutofillProfile*>& profiles = 155 const std::vector<autofill::AutofillProfile*>& profiles =
156 personal_data.GetProfiles(); 156 personal_data.GetProfiles();
157 std::vector<base::string16> labels; 157 std::vector<base::string16> labels;
158 autofill::AutofillProfile::CreateDifferentiatingLabels( 158 autofill::AutofillProfile::CreateDifferentiatingLabels(
159 profiles, 159 profiles,
160 g_browser_process->GetApplicationLocale(), 160 g_browser_process->GetApplicationLocale(),
161 &labels); 161 &labels);
162 DCHECK_EQ(labels.size(), profiles.size()); 162 DCHECK_EQ(labels.size(), profiles.size());
163 163
164 scoped_ptr<AddressEntryList> list(new AddressEntryList); 164 AddressEntryList list;
165 for (size_t i = 0; i < profiles.size(); ++i) { 165 for (size_t i = 0; i < profiles.size(); ++i)
166 autofill_private::AddressEntry* entry = 166 list.push_back(ProfileToAddressEntry(*profiles[i], labels[i]));
167 ProfileToAddressEntry(*profiles[i], labels[i]).release();
168 list->push_back(linked_ptr<autofill_private::AddressEntry>(entry));
169 }
170 167
171 return list; 168 return list;
172 } 169 }
173 170
174 scoped_ptr<CreditCardEntryList> GenerateCreditCardList( 171 CreditCardEntryList GenerateCreditCardList(
175 const autofill::PersonalDataManager& personal_data) { 172 const autofill::PersonalDataManager& personal_data) {
176 const std::vector<autofill::CreditCard*>& cards = 173 const std::vector<autofill::CreditCard*>& cards =
177 personal_data.GetCreditCards(); 174 personal_data.GetCreditCards();
178 175
179 scoped_ptr<CreditCardEntryList> list(new CreditCardEntryList); 176 CreditCardEntryList list;
180 for (const autofill::CreditCard* card : cards) { 177 for (const autofill::CreditCard* card : cards)
181 autofill_private::CreditCardEntry* entry = 178 list.push_back(CreditCardToCreditCardEntry(*card));
182 CreditCardToCreditCardEntry(*card).release();
183 list->push_back(linked_ptr<autofill_private::CreditCardEntry>(entry));
184 }
185 179
186 return list; 180 return list;
187 } 181 }
188 182
189 } // namespace autofill_util 183 } // namespace autofill_util
190 184
191 } // namespace extensions 185 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698