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

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

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header 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
8 #include <utility> 9 #include <utility>
9 10
11 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" 15 #include "chrome/browser/extensions/api/settings_private/prefs_util.h"
14 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/extensions/api/autofill_private.h" 17 #include "chrome/common/extensions/api/autofill_private.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
17 #include "components/autofill/core/browser/autofill_profile.h" 19 #include "components/autofill/core/browser/autofill_profile.h"
18 #include "components/autofill/core/browser/autofill_type.h" 20 #include "components/autofill/core/browser/autofill_type.h"
19 #include "components/autofill/core/browser/credit_card.h" 21 #include "components/autofill/core/browser/credit_card.h"
20 #include "components/autofill/core/browser/field_types.h" 22 #include "components/autofill/core/browser/field_types.h"
21 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
22 #include "grit/components_strings.h" 24 #include "grit/components_strings.h"
23 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
24 26
25 namespace autofill_private = extensions::api::autofill_private; 27 namespace autofill_private = extensions::api::autofill_private;
26 28
27 namespace { 29 namespace {
28 30
29 // Get the multi-valued element for |type| and return it as a |vector|. 31 // Get the multi-valued element for |type| and return it as a |vector|.
30 // TODO(khorimoto): remove this function since multi-valued types are 32 // TODO(khorimoto): remove this function since multi-valued types are
31 // deprecated. 33 // deprecated.
32 scoped_ptr<std::vector<std::string>> GetValueList( 34 std::unique_ptr<std::vector<std::string>> GetValueList(
33 const autofill::AutofillProfile& profile, autofill::ServerFieldType type) { 35 const autofill::AutofillProfile& profile,
34 scoped_ptr<std::vector<std::string>> list(new std::vector<std::string>); 36 autofill::ServerFieldType type) {
37 std::unique_ptr<std::vector<std::string>> list(new std::vector<std::string>);
35 38
36 std::vector<base::string16> values; 39 std::vector<base::string16> values;
37 if (autofill::AutofillType(type).group() == autofill::NAME) { 40 if (autofill::AutofillType(type).group() == autofill::NAME) {
38 values.push_back( 41 values.push_back(
39 profile.GetInfo(autofill::AutofillType(type), 42 profile.GetInfo(autofill::AutofillType(type),
40 g_browser_process->GetApplicationLocale())); 43 g_browser_process->GetApplicationLocale()));
41 } else { 44 } else {
42 values.push_back(profile.GetRawInfo(type)); 45 values.push_back(profile.GetRawInfo(type));
43 } 46 }
44 47
45 // |Get[Raw]MultiInfo()| always returns at least one, potentially empty, item. 48 // |Get[Raw]MultiInfo()| always returns at least one, potentially empty, item.
46 // If this is the case, there is no info to return, so return an empty vector. 49 // If this is the case, there is no info to return, so return an empty vector.
47 if (values.size() == 1 && values.front().empty()) 50 if (values.size() == 1 && values.front().empty())
48 return list; 51 return list;
49 52
50 for (const base::string16& value16 : values) 53 for (const base::string16& value16 : values)
51 list->push_back(base::UTF16ToUTF8(value16)); 54 list->push_back(base::UTF16ToUTF8(value16));
52 55
53 return list; 56 return list;
54 } 57 }
55 58
56 // Gets the string corresponding to |type| from |profile|. 59 // Gets the string corresponding to |type| from |profile|.
57 scoped_ptr<std::string> GetStringFromProfile( 60 std::unique_ptr<std::string> GetStringFromProfile(
58 const autofill::AutofillProfile& profile, 61 const autofill::AutofillProfile& profile,
59 const autofill::ServerFieldType& type) { 62 const autofill::ServerFieldType& type) {
60 return make_scoped_ptr( 63 return base::WrapUnique(
61 new std::string(base::UTF16ToUTF8(profile.GetRawInfo(type)))); 64 new std::string(base::UTF16ToUTF8(profile.GetRawInfo(type))));
62 } 65 }
63 66
64 autofill_private::AddressEntry ProfileToAddressEntry( 67 autofill_private::AddressEntry ProfileToAddressEntry(
65 const autofill::AutofillProfile& profile, 68 const autofill::AutofillProfile& profile,
66 const base::string16& label) { 69 const base::string16& label) {
67 autofill_private::AddressEntry address; 70 autofill_private::AddressEntry address;
68 71
69 // Add all address fields to the entry. 72 // Add all address fields to the entry.
70 address.guid.reset(new std::string(profile.guid())); 73 address.guid.reset(new std::string(profile.guid()));
(...skipping 22 matching lines...) Expand all
93 address.email_addresses = GetValueList(profile, autofill::EMAIL_ADDRESS); 96 address.email_addresses = GetValueList(profile, autofill::EMAIL_ADDRESS);
94 address.language_code.reset(new std::string(profile.language_code())); 97 address.language_code.reset(new std::string(profile.language_code()));
95 98
96 // Parse |label| so that it can be used to create address metadata. 99 // Parse |label| so that it can be used to create address metadata.
97 base::string16 separator = 100 base::string16 separator =
98 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); 101 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR);
99 std::vector<base::string16> label_pieces; 102 std::vector<base::string16> label_pieces;
100 base::SplitStringUsingSubstr(label, separator, &label_pieces); 103 base::SplitStringUsingSubstr(label, separator, &label_pieces);
101 104
102 // Create address metadata and add it to |address|. 105 // Create address metadata and add it to |address|.
103 scoped_ptr<autofill_private::AutofillMetadata> 106 std::unique_ptr<autofill_private::AutofillMetadata> metadata(
104 metadata(new autofill_private::AutofillMetadata); 107 new autofill_private::AutofillMetadata);
105 metadata->summary_label = base::UTF16ToUTF8(label_pieces[0]); 108 metadata->summary_label = base::UTF16ToUTF8(label_pieces[0]);
106 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8( 109 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8(
107 label.substr(label_pieces[0].size())))); 110 label.substr(label_pieces[0].size()))));
108 metadata->is_local.reset(new bool( 111 metadata->is_local.reset(new bool(
109 profile.record_type() == autofill::AutofillProfile::LOCAL_PROFILE)); 112 profile.record_type() == autofill::AutofillProfile::LOCAL_PROFILE));
110 address.metadata = std::move(metadata); 113 address.metadata = std::move(metadata);
111 114
112 return address; 115 return address;
113 } 116 }
114 117
115 autofill_private::CreditCardEntry CreditCardToCreditCardEntry( 118 autofill_private::CreditCardEntry CreditCardToCreditCardEntry(
116 const autofill::CreditCard& credit_card) { 119 const autofill::CreditCard& credit_card) {
117 autofill_private::CreditCardEntry card; 120 autofill_private::CreditCardEntry card;
118 121
119 // Add all credit card fields to the entry. 122 // Add all credit card fields to the entry.
120 card.guid.reset(new std::string(credit_card.guid())); 123 card.guid.reset(new std::string(credit_card.guid()));
121 card.name.reset(new std::string(base::UTF16ToUTF8( 124 card.name.reset(new std::string(base::UTF16ToUTF8(
122 credit_card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)))); 125 credit_card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL))));
123 card.card_number.reset(new std::string( 126 card.card_number.reset(new std::string(
124 base::UTF16ToUTF8(credit_card.GetRawInfo(autofill::CREDIT_CARD_NUMBER)))); 127 base::UTF16ToUTF8(credit_card.GetRawInfo(autofill::CREDIT_CARD_NUMBER))));
125 card.expiration_month.reset(new std::string(base::UTF16ToUTF8( 128 card.expiration_month.reset(new std::string(base::UTF16ToUTF8(
126 credit_card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH)))); 129 credit_card.GetRawInfo(autofill::CREDIT_CARD_EXP_MONTH))));
127 card.expiration_year.reset(new std::string(base::UTF16ToUTF8( 130 card.expiration_year.reset(new std::string(base::UTF16ToUTF8(
128 credit_card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR)))); 131 credit_card.GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR))));
129 132
130 // Create address metadata and add it to |address|. 133 // Create address metadata and add it to |address|.
131 scoped_ptr<autofill_private::AutofillMetadata> 134 std::unique_ptr<autofill_private::AutofillMetadata> metadata(
132 metadata(new autofill_private::AutofillMetadata); 135 new autofill_private::AutofillMetadata);
133 std::pair<base::string16, base::string16> label_pieces = 136 std::pair<base::string16, base::string16> label_pieces =
134 credit_card.LabelPieces(); 137 credit_card.LabelPieces();
135 metadata->summary_label = base::UTF16ToUTF8(label_pieces.first); 138 metadata->summary_label = base::UTF16ToUTF8(label_pieces.first);
136 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8( 139 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8(
137 label_pieces.second))); 140 label_pieces.second)));
138 metadata->is_local.reset(new bool( 141 metadata->is_local.reset(new bool(
139 credit_card.record_type() == autofill::CreditCard::LOCAL_CARD)); 142 credit_card.record_type() == autofill::CreditCard::LOCAL_CARD));
140 metadata->is_cached.reset(new bool( 143 metadata->is_cached.reset(new bool(
141 credit_card.record_type() == autofill::CreditCard::FULL_SERVER_CARD)); 144 credit_card.record_type() == autofill::CreditCard::FULL_SERVER_CARD));
142 card.metadata = std::move(metadata); 145 card.metadata = std::move(metadata);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 CreditCardEntryList list; 179 CreditCardEntryList list;
177 for (const autofill::CreditCard* card : cards) 180 for (const autofill::CreditCard* card : cards)
178 list.push_back(CreditCardToCreditCardEntry(*card)); 181 list.push_back(CreditCardToCreditCardEntry(*card));
179 182
180 return list; 183 return list;
181 } 184 }
182 185
183 } // namespace autofill_util 186 } // namespace autofill_util
184 187
185 } // namespace extensions 188 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698