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

Side by Side Diff: chrome/browser/ui/webui/options2/autofill_options_handler.cc

Issue 10837044: Correct const accessors in base/values.(h|cc), Part II (ListValue) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/options2/autofill_options_handler.h" 5 #include "chrome/browser/ui/webui/options2/autofill_options_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 ListValue* name = new ListValue; // owned by |list| 152 ListValue* name = new ListValue; // owned by |list|
153 name->Set(0, Value::CreateStringValue(first_names[i])); 153 name->Set(0, Value::CreateStringValue(first_names[i]));
154 name->Set(1, Value::CreateStringValue(middle_names[i])); 154 name->Set(1, Value::CreateStringValue(middle_names[i]));
155 name->Set(2, Value::CreateStringValue(last_names[i])); 155 name->Set(2, Value::CreateStringValue(last_names[i]));
156 (*names)->Set(i, name); 156 (*names)->Set(i, name);
157 } 157 }
158 } 158 }
159 159
160 // Set the multi-valued element for |type| from input |list| values. 160 // Set the multi-valued element for |type| from input |list| values.
161 void SetNameList(const ListValue* names, 161 void SetNameList(const ListValue* names,
162 AutofillProfile* profile) { 162 AutofillProfile* profile) {
dhollowa 2012/08/01 16:11:56 nit: this line can be unwrapped.
vabr (Chromium) 2012/08/03 07:08:23 Done.
163 const size_t size = names->GetSize(); 163 const size_t size = names->GetSize();
164 std::vector<string16> first_names(size); 164 std::vector<string16> first_names(size);
165 std::vector<string16> middle_names(size); 165 std::vector<string16> middle_names(size);
166 std::vector<string16> last_names(size); 166 std::vector<string16> last_names(size);
167 167
168 for (size_t i = 0; i < size; ++i) { 168 for (size_t i = 0; i < size; ++i) {
169 ListValue* name; 169 const ListValue* name;
170 bool success = names->GetList(i, &name); 170 bool success = names->GetList(i, &name);
171 DCHECK(success); 171 DCHECK(success);
172 172
173 string16 first_name; 173 string16 first_name;
174 success = name->GetString(0, &first_name); 174 success = name->GetString(0, &first_name);
175 DCHECK(success); 175 DCHECK(success);
176 first_names[i] = first_name; 176 first_names[i] = first_name;
177 177
178 string16 middle_name; 178 string16 middle_name;
179 success = name->GetString(1, &middle_name); 179 success = name->GetString(1, &middle_name);
180 DCHECK(success); 180 DCHECK(success);
181 middle_names[i] = middle_name; 181 middle_names[i] = middle_name;
182 182
183 string16 last_name; 183 string16 last_name;
184 success = name->GetString(2, &last_name); 184 success = name->GetString(2, &last_name);
185 DCHECK(success); 185 DCHECK(success);
186 last_names[i] = last_name; 186 last_names[i] = last_name;
187 } 187 }
188 188
189 profile->SetMultiInfo(NAME_FIRST, first_names); 189 profile->SetMultiInfo(NAME_FIRST, first_names);
190 profile->SetMultiInfo(NAME_MIDDLE, middle_names); 190 profile->SetMultiInfo(NAME_MIDDLE, middle_names);
191 profile->SetMultiInfo(NAME_LAST, last_names); 191 profile->SetMultiInfo(NAME_LAST, last_names);
192 } 192 }
193 193
194 // Pulls the phone number |index|, |phone_number_list|, and |country_code| from 194 // Pulls the phone number |index|, |phone_number_list|, and |country_code| from
195 // the |args| input. 195 // the |args| input.
196 void ExtractPhoneNumberInformation(const ListValue* args, 196 void ExtractPhoneNumberInformation(const ListValue* args,
197 size_t* index, 197 size_t* index,
198 ListValue** phone_number_list, 198 const ListValue** phone_number_list,
199 std::string* country_code) { 199 std::string* country_code) {
200 // Retrieve index as a |double|, as that is how it comes across from 200 // Retrieve index as a |double|, as that is how it comes across from
201 // JavaScript. 201 // JavaScript.
202 double number = 0.0; 202 double number = 0.0;
203 if (!args->GetDouble(0, &number)) { 203 if (!args->GetDouble(0, &number)) {
204 NOTREACHED(); 204 NOTREACHED();
205 return; 205 return;
206 } 206 }
207 *index = number; 207 *index = number;
208 208
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 242 }
243 is_duplicate = autofill_i18n::PhoneNumbersMatch(new_value, 243 is_duplicate = autofill_i18n::PhoneNumbersMatch(new_value,
244 existing_value, 244 existing_value,
245 country_code); 245 country_code);
246 } 246 }
247 247
248 if (is_duplicate) 248 if (is_duplicate)
249 list->Remove(index, NULL); 249 list->Remove(index, NULL);
250 } 250 }
251 251
252 void ValidatePhoneArguments(const ListValue* args, ListValue** list) { 252 scoped_ptr<ListValue> ValidatePhoneArguments(const ListValue* args) {
253 size_t index = 0; 253 size_t index = 0;
254 std::string country_code; 254 std::string country_code;
255 ExtractPhoneNumberInformation(args, &index, list, &country_code); 255 const ListValue* extracted_list = NULL;
256 ExtractPhoneNumberInformation(args, &index, &extracted_list, &country_code);
256 257
257 RemoveDuplicatePhoneNumberAtIndex(index, country_code, *list); 258 ListValue* list = extracted_list->DeepCopy();
dhollowa 2012/08/01 16:11:56 optional: I have a slight preference for creating
vabr (Chromium) 2012/08/03 07:08:24 Done.
259 RemoveDuplicatePhoneNumberAtIndex(index, country_code, list);
260 return scoped_ptr<ListValue>(list);
258 } 261 }
259 262
260 } // namespace 263 } // namespace
261 264
262 namespace options2 { 265 namespace options2 {
263 266
264 AutofillOptionsHandler::AutofillOptionsHandler() 267 AutofillOptionsHandler::AutofillOptionsHandler()
265 : personal_data_(NULL) { 268 : personal_data_(NULL) {
266 } 269 }
267 270
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 std::string guid; 546 std::string guid;
544 if (!args->GetString(0, &guid)) { 547 if (!args->GetString(0, &guid)) {
545 NOTREACHED(); 548 NOTREACHED();
546 return; 549 return;
547 } 550 }
548 551
549 AutofillProfile profile(guid); 552 AutofillProfile profile(guid);
550 553
551 std::string country_code; 554 std::string country_code;
552 string16 value; 555 string16 value;
553 ListValue* list_value; 556 const ListValue* list_value;
554 if (args->GetList(1, &list_value)) 557 if (args->GetList(1, &list_value))
555 SetNameList(list_value, &profile); 558 SetNameList(list_value, &profile);
556 if (args->GetString(2, &value)) 559 if (args->GetString(2, &value))
557 profile.SetInfo(COMPANY_NAME, value); 560 profile.SetInfo(COMPANY_NAME, value);
558 if (args->GetString(3, &value)) 561 if (args->GetString(3, &value))
559 profile.SetInfo(ADDRESS_HOME_LINE1, value); 562 profile.SetInfo(ADDRESS_HOME_LINE1, value);
560 if (args->GetString(4, &value)) 563 if (args->GetString(4, &value))
561 profile.SetInfo(ADDRESS_HOME_LINE2, value); 564 profile.SetInfo(ADDRESS_HOME_LINE2, value);
562 if (args->GetString(5, &value)) 565 if (args->GetString(5, &value))
563 profile.SetInfo(ADDRESS_HOME_CITY, value); 566 profile.SetInfo(ADDRESS_HOME_CITY, value);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 personal_data_->AddCreditCard(credit_card); 610 personal_data_->AddCreditCard(credit_card);
608 } else { 611 } else {
609 personal_data_->UpdateCreditCard(credit_card); 612 personal_data_->UpdateCreditCard(credit_card);
610 } 613 }
611 } 614 }
612 615
613 void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) { 616 void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) {
614 if (!IsPersonalDataLoaded()) 617 if (!IsPersonalDataLoaded())
615 return; 618 return;
616 619
617 ListValue* list_value = NULL; 620 scoped_ptr<ListValue> list_value = ValidatePhoneArguments(args);
618 ValidatePhoneArguments(args, &list_value);
619 621
620 web_ui()->CallJavascriptFunction( 622 web_ui()->CallJavascriptFunction(
621 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); 623 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value);
622 } 624 }
623 625
624 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { 626 bool AutofillOptionsHandler::IsPersonalDataLoaded() const {
625 return personal_data_ && personal_data_->IsDataLoaded(); 627 return personal_data_ && personal_data_->IsDataLoaded();
626 } 628 }
627 629
628 } // namespace options2 630 } // namespace options2
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/app_launcher_handler.cc ('k') | chrome/browser/ui/webui/options2/core_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698