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

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

Issue 1549233002: Convert Pass()→std::move() in //chrome/browser/extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 12 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 9
9 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" 14 #include "chrome/browser/extensions/api/settings_private/prefs_util.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/extensions/api/autofill_private.h" 16 #include "chrome/common/extensions/api/autofill_private.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "components/autofill/core/browser/autofill_profile.h" 18 #include "components/autofill/core/browser/autofill_profile.h"
(...skipping 19 matching lines...) Expand all
37 values.push_back( 38 values.push_back(
38 profile.GetInfo(autofill::AutofillType(type), 39 profile.GetInfo(autofill::AutofillType(type),
39 g_browser_process->GetApplicationLocale())); 40 g_browser_process->GetApplicationLocale()));
40 } else { 41 } else {
41 values.push_back(profile.GetRawInfo(type)); 42 values.push_back(profile.GetRawInfo(type));
42 } 43 }
43 44
44 // |Get[Raw]MultiInfo()| always returns at least one, potentially empty, item. 45 // |Get[Raw]MultiInfo()| always returns at least one, potentially empty, item.
45 // If this is the case, there is no info to return, so return an empty vector. 46 // If this is the case, there is no info to return, so return an empty vector.
46 if (values.size() == 1 && values.front().empty()) 47 if (values.size() == 1 && values.front().empty())
47 return list.Pass(); 48 return list;
48 49
49 for (const base::string16& value16 : values) 50 for (const base::string16& value16 : values)
50 list->push_back(base::UTF16ToUTF8(value16)); 51 list->push_back(base::UTF16ToUTF8(value16));
51 52
52 return list.Pass(); 53 return list;
53 } 54 }
54 55
55 // Gets the string corresponding to |type| from |profile|. 56 // Gets the string corresponding to |type| from |profile|.
56 scoped_ptr<std::string> GetStringFromProfile( 57 scoped_ptr<std::string> GetStringFromProfile(
57 const autofill::AutofillProfile& profile, 58 const autofill::AutofillProfile& profile,
58 const autofill::ServerFieldType& type) { 59 const autofill::ServerFieldType& type) {
59 return make_scoped_ptr( 60 return make_scoped_ptr(
60 new std::string(base::UTF16ToUTF8(profile.GetRawInfo(type)))); 61 new std::string(base::UTF16ToUTF8(profile.GetRawInfo(type))));
61 } 62 }
62 63
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 base::SplitStringUsingSubstr(label, separator, &label_pieces); 99 base::SplitStringUsingSubstr(label, separator, &label_pieces);
99 100
100 // Create address metadata and add it to |address|. 101 // Create address metadata and add it to |address|.
101 scoped_ptr<autofill_private::AutofillMetadata> 102 scoped_ptr<autofill_private::AutofillMetadata>
102 metadata(new autofill_private::AutofillMetadata); 103 metadata(new autofill_private::AutofillMetadata);
103 metadata->summary_label = base::UTF16ToUTF8(label_pieces[0]); 104 metadata->summary_label = base::UTF16ToUTF8(label_pieces[0]);
104 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8( 105 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8(
105 label.substr(label_pieces[0].size())))); 106 label.substr(label_pieces[0].size()))));
106 metadata->is_local.reset(new bool( 107 metadata->is_local.reset(new bool(
107 profile.record_type() == autofill::AutofillProfile::LOCAL_PROFILE)); 108 profile.record_type() == autofill::AutofillProfile::LOCAL_PROFILE));
108 address->metadata = metadata.Pass(); 109 address->metadata = std::move(metadata);
109 110
110 return address.Pass(); 111 return address;
111 } 112 }
112 113
113 scoped_ptr<autofill_private::CreditCardEntry> CreditCardToCreditCardEntry( 114 scoped_ptr<autofill_private::CreditCardEntry> CreditCardToCreditCardEntry(
114 const autofill::CreditCard& credit_card) { 115 const autofill::CreditCard& credit_card) {
115 scoped_ptr<autofill_private::CreditCardEntry> 116 scoped_ptr<autofill_private::CreditCardEntry>
116 card(new autofill_private::CreditCardEntry); 117 card(new autofill_private::CreditCardEntry);
117 118
118 // Add all credit card fields to the entry. 119 // Add all credit card fields to the entry.
119 card->guid.reset(new std::string(credit_card.guid())); 120 card->guid.reset(new std::string(credit_card.guid()));
120 card->name.reset(new std::string(base::UTF16ToUTF8( 121 card->name.reset(new std::string(base::UTF16ToUTF8(
(...skipping 10 matching lines...) Expand all
131 metadata(new autofill_private::AutofillMetadata); 132 metadata(new autofill_private::AutofillMetadata);
132 std::pair<base::string16, base::string16> label_pieces = 133 std::pair<base::string16, base::string16> label_pieces =
133 credit_card.LabelPieces(); 134 credit_card.LabelPieces();
134 metadata->summary_label = base::UTF16ToUTF8(label_pieces.first); 135 metadata->summary_label = base::UTF16ToUTF8(label_pieces.first);
135 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8( 136 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8(
136 label_pieces.second))); 137 label_pieces.second)));
137 metadata->is_local.reset(new bool( 138 metadata->is_local.reset(new bool(
138 credit_card.record_type() == autofill::CreditCard::LOCAL_CARD)); 139 credit_card.record_type() == autofill::CreditCard::LOCAL_CARD));
139 metadata->is_cached.reset(new bool( 140 metadata->is_cached.reset(new bool(
140 credit_card.record_type() == autofill::CreditCard::FULL_SERVER_CARD)); 141 credit_card.record_type() == autofill::CreditCard::FULL_SERVER_CARD));
141 card->metadata = metadata.Pass(); 142 card->metadata = std::move(metadata);
142 143
143 return card.Pass(); 144 return card;
144 } 145 }
145 146
146 } // namespace 147 } // namespace
147 148
148 namespace extensions { 149 namespace extensions {
149 150
150 namespace autofill_util { 151 namespace autofill_util {
151 152
152 scoped_ptr<AddressEntryList> GenerateAddressList( 153 scoped_ptr<AddressEntryList> GenerateAddressList(
153 const autofill::PersonalDataManager& personal_data) { 154 const autofill::PersonalDataManager& personal_data) {
154 const std::vector<autofill::AutofillProfile*>& profiles = 155 const std::vector<autofill::AutofillProfile*>& profiles =
155 personal_data.GetProfiles(); 156 personal_data.GetProfiles();
156 std::vector<base::string16> labels; 157 std::vector<base::string16> labels;
157 autofill::AutofillProfile::CreateDifferentiatingLabels( 158 autofill::AutofillProfile::CreateDifferentiatingLabels(
158 profiles, 159 profiles,
159 g_browser_process->GetApplicationLocale(), 160 g_browser_process->GetApplicationLocale(),
160 &labels); 161 &labels);
161 DCHECK_EQ(labels.size(), profiles.size()); 162 DCHECK_EQ(labels.size(), profiles.size());
162 163
163 scoped_ptr<AddressEntryList> list(new AddressEntryList); 164 scoped_ptr<AddressEntryList> list(new AddressEntryList);
164 for (size_t i = 0; i < profiles.size(); ++i) { 165 for (size_t i = 0; i < profiles.size(); ++i) {
165 autofill_private::AddressEntry* entry = 166 autofill_private::AddressEntry* entry =
166 ProfileToAddressEntry(*profiles[i], labels[i]).release(); 167 ProfileToAddressEntry(*profiles[i], labels[i]).release();
167 list->push_back(linked_ptr<autofill_private::AddressEntry>(entry)); 168 list->push_back(linked_ptr<autofill_private::AddressEntry>(entry));
168 } 169 }
169 170
170 return list.Pass(); 171 return list;
171 } 172 }
172 173
173 scoped_ptr<CreditCardEntryList> GenerateCreditCardList( 174 scoped_ptr<CreditCardEntryList> GenerateCreditCardList(
174 const autofill::PersonalDataManager& personal_data) { 175 const autofill::PersonalDataManager& personal_data) {
175 const std::vector<autofill::CreditCard*>& cards = 176 const std::vector<autofill::CreditCard*>& cards =
176 personal_data.GetCreditCards(); 177 personal_data.GetCreditCards();
177 178
178 scoped_ptr<CreditCardEntryList> list(new CreditCardEntryList); 179 scoped_ptr<CreditCardEntryList> list(new CreditCardEntryList);
179 for (const autofill::CreditCard* card : cards) { 180 for (const autofill::CreditCard* card : cards) {
180 autofill_private::CreditCardEntry* entry = 181 autofill_private::CreditCardEntry* entry =
181 CreditCardToCreditCardEntry(*card).release(); 182 CreditCardToCreditCardEntry(*card).release();
182 list->push_back(linked_ptr<autofill_private::CreditCardEntry>(entry)); 183 list->push_back(linked_ptr<autofill_private::CreditCardEntry>(entry));
183 } 184 }
184 185
185 return list.Pass(); 186 return list;
186 } 187 }
187 188
188 } // namespace autofill_util 189 } // namespace autofill_util
189 190
190 } // namespace extensions 191 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698