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

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

Issue 9982018: Move most TemplateURL data members to a new struct, TemplateURLData. This allows us to eliminate t… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | 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 3135 matching lines...) Expand 10 before | Expand all | Expand 10 after
3146 // If a version number exist in the preferences file, it overrides the 3146 // If a version number exist in the preferences file, it overrides the
3147 // version of the built-in data. 3147 // version of the built-in data.
3148 int version = 3148 int version =
3149 prefs->GetInteger(prefs::kSearchProviderOverridesVersion); 3149 prefs->GetInteger(prefs::kSearchProviderOverridesVersion);
3150 return (version >= 0) ? version : kCurrentDataVersion; 3150 return (version >= 0) ? version : kCurrentDataVersion;
3151 } 3151 }
3152 3152
3153 TemplateURL* MakePrepopulatedTemplateURL(const string16& name, 3153 TemplateURL* MakePrepopulatedTemplateURL(const string16& name,
3154 const string16& keyword, 3154 const string16& keyword,
3155 const base::StringPiece& search_url, 3155 const base::StringPiece& search_url,
3156 const base::StringPiece& favicon_url,
3157 const base::StringPiece& suggest_url, 3156 const base::StringPiece& suggest_url,
3158 const base::StringPiece& instant_url, 3157 const base::StringPiece& instant_url,
3158 const base::StringPiece& favicon_url,
3159 const base::StringPiece& encoding, 3159 const base::StringPiece& encoding,
3160 int id) { 3160 int id) {
3161 TemplateURL* new_turl = new TemplateURL(); 3161 TemplateURLData data;
3162 new_turl->SetURL(search_url.as_string()); 3162 data.short_name = name;
3163 new_turl->set_favicon_url(GURL(favicon_url.as_string()));
3164 new_turl->SetSuggestionsURL(suggest_url.as_string());
3165 new_turl->SetInstantURL(instant_url.as_string());
3166 new_turl->set_short_name(name);
3167 if (keyword.empty()) 3163 if (keyword.empty())
3168 new_turl->set_autogenerate_keyword(true); 3164 data.SetAutogenerateKeyword(true);
3169 else 3165 else
3170 new_turl->set_keyword(keyword); 3166 data.SetKeyword(keyword);
3171 new_turl->set_show_in_default_list(true); 3167 data.SetURL(search_url.as_string());
3172 new_turl->set_safe_for_autoreplace(true); 3168 data.suggestions_url = suggest_url.as_string();
3173 new_turl->set_date_created(base::Time()); 3169 data.instant_url = instant_url.as_string();
3174 new_turl->set_last_modified(base::Time()); 3170 data.favicon_url = GURL(favicon_url.as_string());
3175 std::vector<std::string> turl_encodings; 3171 data.show_in_default_list = true;
3176 turl_encodings.push_back(encoding.as_string()); 3172 data.safe_for_autoreplace = true;
3177 new_turl->set_input_encodings(turl_encodings); 3173 data.input_encodings.push_back(encoding.as_string());
3178 new_turl->SetPrepopulateId(id); 3174 data.date_created = base::Time();
3179 return new_turl; 3175 data.last_modified = base::Time();
3176 data.prepopulate_id = id;
3177 return new TemplateURL(data);
3180 } 3178 }
3181 3179
3182 void GetPrepopulatedTemplateFromPrefs(PrefService* prefs, 3180 void GetPrepopulatedTemplateFromPrefs(PrefService* prefs,
3183 std::vector<TemplateURL*>* t_urls) { 3181 std::vector<TemplateURL*>* t_urls) {
3184 if (!prefs) 3182 if (!prefs)
3185 return; 3183 return;
3186 3184
3187 const ListValue* list = 3185 const ListValue* list =
3188 prefs->GetList(prefs::kSearchProviderOverrides); 3186 prefs->GetList(prefs::kSearchProviderOverrides);
3189 if (!list) 3187 if (!list)
(...skipping 23 matching lines...) Expand all
3213 engine->Get("id", &val) && val->GetAsInteger(&id)) { 3211 engine->Get("id", &val) && val->GetAsInteger(&id)) {
3214 // These next fields are not allowed to be empty. 3212 // These next fields are not allowed to be empty.
3215 if (name.empty() || search_url.empty() || favicon_url.empty() || 3213 if (name.empty() || search_url.empty() || favicon_url.empty() ||
3216 encoding.empty()) 3214 encoding.empty())
3217 return; 3215 return;
3218 } else { 3216 } else {
3219 // Got a parsing error. No big deal. 3217 // Got a parsing error. No big deal.
3220 continue; 3218 continue;
3221 } 3219 }
3222 t_urls->push_back(MakePrepopulatedTemplateURL(name, keyword, search_url, 3220 t_urls->push_back(MakePrepopulatedTemplateURL(name, keyword, search_url,
3223 favicon_url, suggest_url, instant_url, encoding, id)); 3221 suggest_url, instant_url, favicon_url, encoding, id));
3224 } 3222 }
3225 } 3223 }
3226 3224
3227 // The caller owns the returned TemplateURL. 3225 // The caller owns the returned TemplateURL.
3228 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine( 3226 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine(
3229 const PrepopulatedEngine& engine) { 3227 const PrepopulatedEngine& engine) {
3230 return MakePrepopulatedTemplateURL(WideToUTF16(engine.name), 3228 return MakePrepopulatedTemplateURL(WideToUTF16(engine.name),
3231 WideToUTF16(engine.keyword), engine.search_url, engine.favicon_url, 3229 WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url,
3232 engine.suggest_url, engine.instant_url, engine.encoding, engine.id); 3230 engine.instant_url, engine.favicon_url, engine.encoding, engine.id);
3233 } 3231 }
3234 3232
3235 void GetPrepopulatedEngines(PrefService* prefs, 3233 void GetPrepopulatedEngines(PrefService* prefs,
3236 std::vector<TemplateURL*>* t_urls, 3234 std::vector<TemplateURL*>* t_urls,
3237 size_t* default_search_provider_index) { 3235 size_t* default_search_provider_index) {
3238 // If there is a set of search engines in the preferences file, it overrides 3236 // If there is a set of search engines in the preferences file, it overrides
3239 // the built-in set. 3237 // the built-in set.
3240 *default_search_provider_index = 0; 3238 *default_search_provider_index = 0;
3241 GetPrepopulatedTemplateFromPrefs(prefs, t_urls); 3239 GetPrepopulatedTemplateFromPrefs(prefs, t_urls);
3242 if (!t_urls->empty()) 3240 if (!t_urls->empty())
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3306 UTF8ToUTF16(as_gurl.host()) : 3304 UTF8ToUTF16(as_gurl.host()) :
3307 l10n_util::GetStringUTF16(IDS_UNKNOWN_SEARCH_ENGINE_NAME); 3305 l10n_util::GetStringUTF16(IDS_UNKNOWN_SEARCH_ENGINE_NAME);
3308 } 3306 }
3309 3307
3310 SearchEngineType GetEngineType(const std::string& url) { 3308 SearchEngineType GetEngineType(const std::string& url) {
3311 const PrepopulatedEngine* engine = GetEngineForURL(url); 3309 const PrepopulatedEngine* engine = GetEngineForURL(url);
3312 return engine ? engine->type : SEARCH_ENGINE_OTHER; 3310 return engine ? engine->type : SEARCH_ENGINE_OTHER;
3313 } 3311 }
3314 3312
3315 } // namespace TemplateURLPrepopulateData 3313 } // namespace TemplateURLPrepopulateData
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_parser_unittest.cc ('k') | chrome/browser/search_engines/template_url_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698