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

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

Issue 10828401: Add a getter for search provider logos. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed enum and other nits. Created 8 years, 3 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 3267 matching lines...) Expand 10 before | Expand all | Expand 10 after
3278 UNHANDLED_COUNTRY(V, C) // Saint Vincent and the Grenadines 3278 UNHANDLED_COUNTRY(V, C) // Saint Vincent and the Grenadines
3279 UNHANDLED_COUNTRY(V, U) // Vanuatu 3279 UNHANDLED_COUNTRY(V, U) // Vanuatu
3280 UNHANDLED_COUNTRY(W, S) // Samoa 3280 UNHANDLED_COUNTRY(W, S) // Samoa
3281 UNHANDLED_COUNTRY(Z, M) // Zambia 3281 UNHANDLED_COUNTRY(Z, M) // Zambia
3282 case kCountryIDUnknown: 3282 case kCountryIDUnknown:
3283 default: // Unhandled location 3283 default: // Unhandled location
3284 END_UNHANDLED_COUNTRIES(def, ault) 3284 END_UNHANDLED_COUNTRIES(def, ault)
3285 } 3285 }
3286 } 3286 }
3287 3287
3288
3289 // Logo URLs ///////////////////////////////////////////////////////////////////
msw 2012/08/28 22:26:22 nit: this needs to be about 15 lines of ascii art
samarth 2012/08/28 23:29:20 You mean this? :) # # #### #### ##
3290
3291 struct LogoURLs {
3292 const char* const logo_100_percent_url;
3293 const char* const logo_200_percent_url;
3294 };
3295
3296 const LogoURLs google_logos = {
3297 "https://www.google.com/images/chrome_search/google_logo.png",
3298 "https://www.google.com/images/chrome_search/google_logo_2x.png",
3299 };
3300
3301
3302 ////////////////////////////////////////////////////////////////////////////////
3303
3288 } // namespace 3304 } // namespace
3289 3305
3290 namespace TemplateURLPrepopulateData { 3306 namespace TemplateURLPrepopulateData {
3291 3307
3292 // The following id is for UMA stats only. Please update 3308 // The following id is for UMA stats only. Please update
3293 // kMaxPrepopulatedEngineID if it changes upwards. 3309 // kMaxPrepopulatedEngineID if it changes upwards.
3294 const int kMaxPrepopulatedEngineID = 101; 3310 const int kMaxPrepopulatedEngineID = 101;
3295 3311
3296 void RegisterUserPrefs(PrefService* prefs) { 3312 void RegisterUserPrefs(PrefService* prefs) {
3297 prefs->RegisterIntegerPref(prefs::kCountryIDAtInstall, 3313 prefs->RegisterIntegerPref(prefs::kCountryIDAtInstall,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3357 string16 keyword; 3373 string16 keyword;
3358 std::string search_url; 3374 std::string search_url;
3359 std::string suggest_url; 3375 std::string suggest_url;
3360 std::string instant_url; 3376 std::string instant_url;
3361 std::string favicon_url; 3377 std::string favicon_url;
3362 std::string encoding; 3378 std::string encoding;
3363 int id; 3379 int id;
3364 3380
3365 size_t num_engines = list->GetSize(); 3381 size_t num_engines = list->GetSize();
3366 for (size_t i = 0; i != num_engines; ++i) { 3382 for (size_t i = 0; i != num_engines; ++i) {
3367 const Value* val;
3368 const DictionaryValue* engine; 3383 const DictionaryValue* engine;
3369 if (list->GetDictionary(i, &engine) && 3384 if (list->GetDictionary(i, &engine) &&
3370 engine->Get("name", &val) && val->GetAsString(&name) && 3385 engine->GetString("name", &name) &&
3371 engine->Get("keyword", &val) && val->GetAsString(&keyword) && 3386 engine->GetString("keyword", &keyword) &&
3372 engine->Get("search_url", &val) && val->GetAsString(&search_url) && 3387 engine->GetString("search_url", &search_url) &&
3373 engine->Get("suggest_url", &val) && val->GetAsString(&suggest_url) && 3388 engine->GetString("suggest_url", &suggest_url) &&
3374 engine->Get("instant_url", &val) && val->GetAsString(&instant_url) && 3389 engine->GetString("instant_url", &instant_url) &&
3375 engine->Get("favicon_url", &val) && val->GetAsString(&favicon_url) && 3390 engine->GetString("favicon_url", &favicon_url) &&
3376 engine->Get("encoding", &val) && val->GetAsString(&encoding) && 3391 engine->GetString("encoding", &encoding) &&
3377 engine->Get("id", &val) && val->GetAsInteger(&id)) { 3392 engine->GetInteger("id", &id)) {
3378 // These next fields are not allowed to be empty. 3393 // These next fields are not allowed to be empty.
3379 if (name.empty() || keyword.empty() || search_url.empty() || 3394 if (name.empty() || keyword.empty() || search_url.empty() ||
3380 favicon_url.empty() || encoding.empty()) 3395 favicon_url.empty() || encoding.empty())
3381 return; 3396 return;
3382 } else { 3397 } else {
3383 // Got a parsing error. No big deal. 3398 // Got a parsing error. No big deal.
3384 continue; 3399 continue;
3385 } 3400 }
3386 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, 3401 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword,
3387 search_url, suggest_url, instant_url, favicon_url, encoding, id)); 3402 search_url, suggest_url, instant_url, favicon_url, encoding, id));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3464 GURL origin(as_gurl.GetOrigin()); 3479 GURL origin(as_gurl.GetOrigin());
3465 for (size_t i = 0; i < arraysize(kAllEngines); ++i) { 3480 for (size_t i = 0; i < arraysize(kAllEngines); ++i) {
3466 GURL engine_url(kAllEngines[i]->search_url); 3481 GURL engine_url(kAllEngines[i]->search_url);
3467 if (engine_url.is_valid() && (origin == engine_url.GetOrigin())) 3482 if (engine_url.is_valid() && (origin == engine_url.GetOrigin()))
3468 return kAllEngines[i]->type; 3483 return kAllEngines[i]->type;
3469 } 3484 }
3470 3485
3471 return SEARCH_ENGINE_OTHER; 3486 return SEARCH_ENGINE_OTHER;
3472 } 3487 }
3473 3488
3489 GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) {
3490 if (GetEngineType(template_url.url()) == SEARCH_ENGINE_GOOGLE) {
3491 if (size == LOGO_100_PERCENT) {
3492 return GURL(google_logos.logo_100_percent_url);
3493 } else if (size == LOGO_200_PERCENT) {
Peter Kasting 2012/08/28 23:20:20 Nit: No else after return. Just do this: ret
samarth 2012/08/28 23:29:20 This style could easily break if we added more siz
Peter Kasting 2012/08/28 23:32:54 I think it's nice to be brief since we don't have
3494 return GURL(google_logos.logo_200_percent_url);
3495 }
3496 }
3497 return GURL();
3498 }
3499
3474 #if defined(OS_ANDROID) 3500 #if defined(OS_ANDROID)
3475 3501
3476 void InitCountryCode(const std::string& country_code) { 3502 void InitCountryCode(const std::string& country_code) {
3477 if (country_code.size() != 2) { 3503 if (country_code.size() != 2) {
3478 DLOG(ERROR) << "Invalid country code: " << country_code; 3504 DLOG(ERROR) << "Invalid country code: " << country_code;
3479 g_country_code_at_install = kCountryIDUnknown; 3505 g_country_code_at_install = kCountryIDUnknown;
3480 } else { 3506 } else {
3481 g_country_code_at_install = 3507 g_country_code_at_install =
3482 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); 3508 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]);
3483 } 3509 }
3484 } 3510 }
3485 3511
3486 #endif 3512 #endif
3487 3513
3488 } // namespace TemplateURLPrepopulateData 3514 } // namespace TemplateURLPrepopulateData
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698