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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 6673079: Reduce boxing and unboxing of AutofillFieldType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile on Windows. Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 4184 matching lines...) Expand 10 before | Expand all | Expand 10 after
4195 // For each AutofillProfile, transform it to a dictionary object to return. 4195 // For each AutofillProfile, transform it to a dictionary object to return.
4196 for (std::vector<AutofillProfile*>::const_iterator it = 4196 for (std::vector<AutofillProfile*>::const_iterator it =
4197 autofill_profiles.begin(); 4197 autofill_profiles.begin();
4198 it != autofill_profiles.end(); ++it) { 4198 it != autofill_profiles.end(); ++it) {
4199 AutofillProfile* profile = *it; 4199 AutofillProfile* profile = *it;
4200 DictionaryValue* profile_info = new DictionaryValue; 4200 DictionaryValue* profile_info = new DictionaryValue;
4201 // For each of the types, if it has a value, add it to the dictionary. 4201 // For each of the types, if it has a value, add it to the dictionary.
4202 for (std::map<AutofillFieldType, std::string>::iterator 4202 for (std::map<AutofillFieldType, std::string>::iterator
4203 type_it = autofill_type_to_string.begin(); 4203 type_it = autofill_type_to_string.begin();
4204 type_it != autofill_type_to_string.end(); ++type_it) { 4204 type_it != autofill_type_to_string.end(); ++type_it) {
4205 string16 value = profile->GetFieldText(AutofillType(type_it->first)); 4205 string16 value = profile->GetFieldText(type_it->first);
4206 if (value.length()) { // If there was something stored for that value. 4206 if (value.length()) { // If there was something stored for that value.
4207 profile_info->SetString(type_it->second, value); 4207 profile_info->SetString(type_it->second, value);
4208 } 4208 }
4209 } 4209 }
4210 profiles->Append(profile_info); 4210 profiles->Append(profile_info);
4211 } 4211 }
4212 return profiles; 4212 return profiles;
4213 } 4213 }
4214 4214
4215 /* static */ 4215 /* static */
4216 ListValue* TestingAutomationProvider::GetListFromCreditCards( 4216 ListValue* TestingAutomationProvider::GetListFromCreditCards(
4217 const std::vector<CreditCard*>& credit_cards) { 4217 const std::vector<CreditCard*>& credit_cards) {
4218 ListValue* cards = new ListValue; 4218 ListValue* cards = new ListValue;
4219 4219
4220 std::map<AutofillFieldType, std::string> credit_card_type_to_string = 4220 std::map<AutofillFieldType, std::string> credit_card_type_to_string =
4221 GetCreditCardFieldToStringMap(); 4221 GetCreditCardFieldToStringMap();
4222 4222
4223 // For each AutofillProfile, transform it to a dictionary object to return. 4223 // For each AutofillProfile, transform it to a dictionary object to return.
4224 for (std::vector<CreditCard*>::const_iterator it = 4224 for (std::vector<CreditCard*>::const_iterator it =
4225 credit_cards.begin(); 4225 credit_cards.begin();
4226 it != credit_cards.end(); ++it) { 4226 it != credit_cards.end(); ++it) {
4227 CreditCard* card = *it; 4227 CreditCard* card = *it;
4228 DictionaryValue* card_info = new DictionaryValue; 4228 DictionaryValue* card_info = new DictionaryValue;
4229 // For each of the types, if it has a value, add it to the dictionary. 4229 // For each of the types, if it has a value, add it to the dictionary.
4230 for (std::map<AutofillFieldType, std::string>::iterator type_it = 4230 for (std::map<AutofillFieldType, std::string>::iterator type_it =
4231 credit_card_type_to_string.begin(); 4231 credit_card_type_to_string.begin();
4232 type_it != credit_card_type_to_string.end(); ++type_it) { 4232 type_it != credit_card_type_to_string.end(); ++type_it) {
4233 string16 value = card->GetFieldText(AutofillType(type_it->first)); 4233 string16 value = card->GetFieldText(type_it->first);
4234 // If there was something stored for that value. 4234 // If there was something stored for that value.
4235 if (value.length()) { 4235 if (value.length()) {
4236 card_info->SetString(type_it->second, value); 4236 card_info->SetString(type_it->second, value);
4237 } 4237 }
4238 } 4238 }
4239 cards->Append(card_info); 4239 cards->Append(card_info);
4240 } 4240 }
4241 return cards; 4241 return cards;
4242 } 4242 }
4243 4243
(...skipping 12 matching lines...) Expand all
4256 for (int i = 0; i < num_profiles; i++) { 4256 for (int i = 0; i < num_profiles; i++) {
4257 profiles.GetDictionary(i, &profile_info); 4257 profiles.GetDictionary(i, &profile_info);
4258 AutofillProfile profile; 4258 AutofillProfile profile;
4259 // Loop through the possible profile types and add those provided. 4259 // Loop through the possible profile types and add those provided.
4260 for (std::map<AutofillFieldType, std::string>::iterator type_it = 4260 for (std::map<AutofillFieldType, std::string>::iterator type_it =
4261 autofill_type_to_string.begin(); 4261 autofill_type_to_string.begin();
4262 type_it != autofill_type_to_string.end(); ++type_it) { 4262 type_it != autofill_type_to_string.end(); ++type_it) {
4263 if (profile_info->HasKey(type_it->second)) { 4263 if (profile_info->HasKey(type_it->second)) {
4264 if (profile_info->GetString(type_it->second, 4264 if (profile_info->GetString(type_it->second,
4265 &current_value)) { 4265 &current_value)) {
4266 profile.SetInfo(AutofillType(type_it->first), current_value); 4266 profile.SetInfo(type_it->first, current_value);
4267 } else { 4267 } else {
4268 *error_message= "All values must be strings"; 4268 *error_message= "All values must be strings";
4269 break; 4269 break;
4270 } 4270 }
4271 } 4271 }
4272 } 4272 }
4273 autofill_profiles.push_back(profile); 4273 autofill_profiles.push_back(profile);
4274 } 4274 }
4275 return autofill_profiles; 4275 return autofill_profiles;
4276 } 4276 }
(...skipping 11 matching lines...) Expand all
4288 int num_credit_cards = cards.GetSize(); 4288 int num_credit_cards = cards.GetSize();
4289 for (int i = 0; i < num_credit_cards; i++) { 4289 for (int i = 0; i < num_credit_cards; i++) {
4290 cards.GetDictionary(i, &card_info); 4290 cards.GetDictionary(i, &card_info);
4291 CreditCard card; 4291 CreditCard card;
4292 // Loop through the possible credit card fields and add those provided. 4292 // Loop through the possible credit card fields and add those provided.
4293 for (std::map<AutofillFieldType, std::string>::iterator type_it = 4293 for (std::map<AutofillFieldType, std::string>::iterator type_it =
4294 credit_card_type_to_string.begin(); 4294 credit_card_type_to_string.begin();
4295 type_it != credit_card_type_to_string.end(); ++type_it) { 4295 type_it != credit_card_type_to_string.end(); ++type_it) {
4296 if (card_info->HasKey(type_it->second)) { 4296 if (card_info->HasKey(type_it->second)) {
4297 if (card_info->GetString(type_it->second, &current_value)) { 4297 if (card_info->GetString(type_it->second, &current_value)) {
4298 card.SetInfo(AutofillType(type_it->first), current_value); 4298 card.SetInfo(type_it->first, current_value);
4299 } else { 4299 } else {
4300 *error_message= "All values must be strings"; 4300 *error_message= "All values must be strings";
4301 break; 4301 break;
4302 } 4302 }
4303 } 4303 }
4304 } 4304 }
4305 credit_cards.push_back(card); 4305 credit_cards.push_back(card);
4306 } 4306 }
4307 return credit_cards; 4307 return credit_cards;
4308 } 4308 }
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
5196 // If you change this, update Observer for NotificationType::SESSION_END 5196 // If you change this, update Observer for NotificationType::SESSION_END
5197 // below. 5197 // below.
5198 MessageLoop::current()->PostTask(FROM_HERE, 5198 MessageLoop::current()->PostTask(FROM_HERE,
5199 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 5199 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
5200 } 5200 }
5201 } 5201 }
5202 5202
5203 void TestingAutomationProvider::OnRemoveProvider() { 5203 void TestingAutomationProvider::OnRemoveProvider() {
5204 AutomationProviderList::GetInstance()->RemoveProvider(this); 5204 AutomationProviderList::GetInstance()->RemoveProvider(this);
5205 } 5205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698