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

Side by Side Diff: chrome/browser/search_engines/template_url_prepopulate_data.cc

Issue 11552020: Add search_terms_replacement_key field to TemplateURL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with protector removal Created 8 years 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) 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/search_engines/template_url_prepopulate_data.h" 5 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
6 6
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) 7 #if defined(OS_POSIX) && !defined(OS_MACOSX)
8 #include <locale.h> 8 #include <locale.h>
9 #endif 9 #endif
10 10
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 PrefService::UNSYNCABLE_PREF); 1103 PrefService::UNSYNCABLE_PREF);
1104 } 1104 }
1105 1105
1106 int GetDataVersion(PrefService* prefs) { 1106 int GetDataVersion(PrefService* prefs) {
1107 // Allow tests to override the local version. 1107 // Allow tests to override the local version.
1108 return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ? 1108 return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ?
1109 prefs->GetInteger(prefs::kSearchProviderOverridesVersion) : 1109 prefs->GetInteger(prefs::kSearchProviderOverridesVersion) :
1110 kCurrentDataVersion; 1110 kCurrentDataVersion;
1111 } 1111 }
1112 1112
1113 TemplateURL* MakePrepopulatedTemplateURL(Profile* profile, 1113 TemplateURL* MakePrepopulatedTemplateURL(
1114 const string16& name, 1114 Profile* profile,
1115 const string16& keyword, 1115 const string16& name,
1116 const base::StringPiece& search_url, 1116 const string16& keyword,
1117 const base::StringPiece& suggest_url, 1117 const base::StringPiece& search_url,
1118 const base::StringPiece& instant_url, 1118 const base::StringPiece& suggest_url,
1119 const ListValue& alternate_urls, 1119 const base::StringPiece& instant_url,
1120 const base::StringPiece& favicon_url, 1120 const ListValue& alternate_urls,
1121 const base::StringPiece& encoding, 1121 const base::StringPiece& search_terms_replacement_key,
1122 int id) { 1122 const base::StringPiece& favicon_url,
1123 const base::StringPiece& encoding,
1124 int id) {
1123 1125
1124 TemplateURLData data; 1126 TemplateURLData data;
1125 1127
1126 data.short_name = name; 1128 data.short_name = name;
1127 data.SetKeyword(keyword); 1129 data.SetKeyword(keyword);
1128 data.SetURL(search_url.as_string()); 1130 data.SetURL(search_url.as_string());
1129 data.suggestions_url = suggest_url.as_string(); 1131 data.suggestions_url = suggest_url.as_string();
1130 data.instant_url = instant_url.as_string(); 1132 data.instant_url = instant_url.as_string();
1131 for (size_t i = 0; i < alternate_urls.GetSize(); ++i) { 1133 for (size_t i = 0; i < alternate_urls.GetSize(); ++i) {
1132 std::string alternate_url; 1134 std::string alternate_url;
1133 alternate_urls.GetString(i, &alternate_url); 1135 alternate_urls.GetString(i, &alternate_url);
1134 DCHECK(!alternate_url.empty()); 1136 DCHECK(!alternate_url.empty());
1135 data.alternate_urls.push_back(alternate_url); 1137 data.alternate_urls.push_back(alternate_url);
1136 } 1138 }
1139 data.search_terms_replacement_key = search_terms_replacement_key.as_string();
Peter Kasting 2012/12/18 01:54:43 Nit: Set this member in the same order that the Te
beaudoin 2012/12/20 04:23:29 Fixed alternate_urls at the same time. Done.
1137 data.favicon_url = GURL(favicon_url.as_string()); 1140 data.favicon_url = GURL(favicon_url.as_string());
1138 data.show_in_default_list = true; 1141 data.show_in_default_list = true;
1139 data.safe_for_autoreplace = true; 1142 data.safe_for_autoreplace = true;
1140 data.input_encodings.push_back(encoding.as_string()); 1143 data.input_encodings.push_back(encoding.as_string());
1141 data.date_created = base::Time(); 1144 data.date_created = base::Time();
1142 data.last_modified = base::Time(); 1145 data.last_modified = base::Time();
1143 data.prepopulate_id = id; 1146 data.prepopulate_id = id;
1144 return new TemplateURL(profile, data); 1147 return new TemplateURL(profile, data);
1145 } 1148 }
1146 1149
(...skipping 21 matching lines...) Expand all
1168 engine->GetString("name", &name) && !name.empty() && 1171 engine->GetString("name", &name) && !name.empty() &&
1169 engine->GetString("keyword", &keyword) && !keyword.empty() && 1172 engine->GetString("keyword", &keyword) && !keyword.empty() &&
1170 engine->GetString("search_url", &search_url) && !search_url.empty() && 1173 engine->GetString("search_url", &search_url) && !search_url.empty() &&
1171 engine->GetString("favicon_url", &favicon_url) && 1174 engine->GetString("favicon_url", &favicon_url) &&
1172 !favicon_url.empty() && 1175 !favicon_url.empty() &&
1173 engine->GetString("encoding", &encoding) && !encoding.empty() && 1176 engine->GetString("encoding", &encoding) && !encoding.empty() &&
1174 engine->GetInteger("id", &id)) { 1177 engine->GetInteger("id", &id)) {
1175 // These fields are optional. 1178 // These fields are optional.
1176 std::string suggest_url; 1179 std::string suggest_url;
1177 std::string instant_url; 1180 std::string instant_url;
1181 std::string search_terms_replacement_key;
1178 ListValue empty_list; 1182 ListValue empty_list;
1179 const ListValue* alternate_urls = &empty_list; 1183 const ListValue* alternate_urls = &empty_list;
1180 engine->GetString("suggest_url", &suggest_url); 1184 engine->GetString("suggest_url", &suggest_url);
1181 engine->GetString("instant_url", &instant_url); 1185 engine->GetString("instant_url", &instant_url);
1182 engine->GetList("alternate_urls", &alternate_urls); 1186 engine->GetList("alternate_urls", &alternate_urls);
1187 engine->GetString("search_terms_replacement_key",
1188 &search_terms_replacement_key);
1183 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, 1189 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword,
1184 search_url, suggest_url, instant_url, *alternate_urls, favicon_url, 1190 search_url, suggest_url, instant_url, *alternate_urls,
1185 encoding, id)); 1191 search_terms_replacement_key, favicon_url, encoding, id));
1186 } 1192 }
1187 } 1193 }
1188 } 1194 }
1189 1195
1190 // The caller owns the returned TemplateURL. 1196 // The caller owns the returned TemplateURL.
1191 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine( 1197 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine(
1192 Profile* profile, 1198 Profile* profile,
1193 const PrepopulatedEngine& engine) { 1199 const PrepopulatedEngine& engine) {
1194 1200
1195 ListValue alternate_urls; 1201 ListValue alternate_urls;
1196 if (engine.alternate_urls) { 1202 if (engine.alternate_urls) {
1197 for (size_t i = 0; i < engine.alternate_urls_size; ++i) 1203 for (size_t i = 0; i < engine.alternate_urls_size; ++i)
1198 alternate_urls.AppendString(std::string(engine.alternate_urls[i])); 1204 alternate_urls.AppendString(std::string(engine.alternate_urls[i]));
1199 } 1205 }
1200 1206
1201 return MakePrepopulatedTemplateURL(profile, WideToUTF16(engine.name), 1207 return MakePrepopulatedTemplateURL(profile, WideToUTF16(engine.name),
1202 WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url, 1208 WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url,
1203 engine.instant_url, alternate_urls, 1209 engine.instant_url, alternate_urls, engine.search_terms_replacement_key,
1204 engine.favicon_url, engine.encoding, engine.id); 1210 engine.favicon_url, engine.encoding, engine.id);
1205 } 1211 }
1206 1212
1207 void GetPrepopulatedEngines(Profile* profile, 1213 void GetPrepopulatedEngines(Profile* profile,
1208 std::vector<TemplateURL*>* t_urls, 1214 std::vector<TemplateURL*>* t_urls,
1209 size_t* default_search_provider_index) { 1215 size_t* default_search_provider_index) {
1210 // If there is a set of search engines in the preferences file, it overrides 1216 // If there is a set of search engines in the preferences file, it overrides
1211 // the built-in set. 1217 // the built-in set.
1212 *default_search_provider_index = 0; 1218 *default_search_provider_index = 0;
1213 GetPrepopulatedTemplateFromPrefs(profile, t_urls); 1219 GetPrepopulatedTemplateFromPrefs(profile, t_urls);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) { 1287 GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) {
1282 if (GetEngineType(template_url.url()) == SEARCH_ENGINE_GOOGLE) { 1288 if (GetEngineType(template_url.url()) == SEARCH_ENGINE_GOOGLE) {
1283 return GURL((size == LOGO_200_PERCENT) ? 1289 return GURL((size == LOGO_200_PERCENT) ?
1284 google_logos.logo_200_percent_url : 1290 google_logos.logo_200_percent_url :
1285 google_logos.logo_100_percent_url); 1291 google_logos.logo_100_percent_url);
1286 } 1292 }
1287 return GURL(); 1293 return GURL();
1288 } 1294 }
1289 1295
1290 } // namespace TemplateURLPrepopulateData 1296 } // namespace TemplateURLPrepopulateData
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698