Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 3266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3277 UNHANDLED_COUNTRY(U, G) // Uganda | 3277 UNHANDLED_COUNTRY(U, G) // Uganda |
| 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 |
|
Peter Kasting
2012/08/28 00:04:07
Nit: Two blank lines above these section dividers
samarth
2012/08/28 16:18:15
Done.
| |
| 3288 // Logo URLs /////////////////////////////////////////////////////////////////// | |
| 3289 | |
| 3290 struct LogoURLs { | |
| 3291 const char* const logo_100_percent_url; | |
| 3292 const char* const logo_200_percent_url; | |
| 3293 }; | |
| 3294 | |
| 3295 const LogoURLs google_logos = { | |
| 3296 "https://www.google.com/images/chrome_search/google_logo.png", | |
| 3297 "https://www.google.com/images/chrome_search/google_logo_2x.png", | |
| 3298 }; | |
| 3299 | |
| 3288 } // namespace | 3300 } // namespace |
| 3289 | 3301 |
|
Peter Kasting
2012/08/28 00:04:07
Nit: Can you add a ////////// nameless divider her
samarth
2012/08/28 16:18:15
Done.
| |
| 3290 namespace TemplateURLPrepopulateData { | 3302 namespace TemplateURLPrepopulateData { |
| 3291 | 3303 |
| 3292 // The following id is for UMA stats only. Please update | 3304 // The following id is for UMA stats only. Please update |
| 3293 // kMaxPrepopulatedEngineID if it changes upwards. | 3305 // kMaxPrepopulatedEngineID if it changes upwards. |
| 3294 const int kMaxPrepopulatedEngineID = 101; | 3306 const int kMaxPrepopulatedEngineID = 101; |
| 3295 | 3307 |
| 3296 void RegisterUserPrefs(PrefService* prefs) { | 3308 void RegisterUserPrefs(PrefService* prefs) { |
| 3297 prefs->RegisterIntegerPref(prefs::kCountryIDAtInstall, | 3309 prefs->RegisterIntegerPref(prefs::kCountryIDAtInstall, |
| 3298 kCountryIDUnknown, | 3310 kCountryIDUnknown, |
| 3299 PrefService::UNSYNCABLE_PREF); | 3311 PrefService::UNSYNCABLE_PREF); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3357 string16 keyword; | 3369 string16 keyword; |
| 3358 std::string search_url; | 3370 std::string search_url; |
| 3359 std::string suggest_url; | 3371 std::string suggest_url; |
| 3360 std::string instant_url; | 3372 std::string instant_url; |
| 3361 std::string favicon_url; | 3373 std::string favicon_url; |
| 3362 std::string encoding; | 3374 std::string encoding; |
| 3363 int id; | 3375 int id; |
| 3364 | 3376 |
| 3365 size_t num_engines = list->GetSize(); | 3377 size_t num_engines = list->GetSize(); |
| 3366 for (size_t i = 0; i != num_engines; ++i) { | 3378 for (size_t i = 0; i != num_engines; ++i) { |
| 3367 const Value* val; | |
| 3368 const DictionaryValue* engine; | 3379 const DictionaryValue* engine; |
| 3369 if (list->GetDictionary(i, &engine) && | 3380 if (list->GetDictionary(i, &engine) && |
| 3370 engine->Get("name", &val) && val->GetAsString(&name) && | 3381 engine->GetString("name", &name) && |
| 3371 engine->Get("keyword", &val) && val->GetAsString(&keyword) && | 3382 engine->GetString("keyword", &keyword) && |
| 3372 engine->Get("search_url", &val) && val->GetAsString(&search_url) && | 3383 engine->GetString("search_url", &search_url) && |
| 3373 engine->Get("suggest_url", &val) && val->GetAsString(&suggest_url) && | 3384 engine->GetString("suggest_url", &suggest_url) && |
| 3374 engine->Get("instant_url", &val) && val->GetAsString(&instant_url) && | 3385 engine->GetString("instant_url", &instant_url) && |
| 3375 engine->Get("favicon_url", &val) && val->GetAsString(&favicon_url) && | 3386 engine->GetString("favicon_url", &favicon_url) && |
| 3376 engine->Get("encoding", &val) && val->GetAsString(&encoding) && | 3387 engine->GetString("encoding", &encoding) && |
| 3377 engine->Get("id", &val) && val->GetAsInteger(&id)) { | 3388 engine->GetInteger("id", &id)) { |
| 3378 // These next fields are not allowed to be empty. | 3389 // These next fields are not allowed to be empty. |
| 3379 if (name.empty() || keyword.empty() || search_url.empty() || | 3390 if (name.empty() || keyword.empty() || search_url.empty() || |
| 3380 favicon_url.empty() || encoding.empty()) | 3391 favicon_url.empty() || encoding.empty()) |
| 3381 return; | 3392 return; |
| 3382 } else { | 3393 } else { |
| 3383 // Got a parsing error. No big deal. | 3394 // Got a parsing error. No big deal. |
| 3384 continue; | 3395 continue; |
| 3385 } | 3396 } |
| 3386 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, | 3397 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, |
| 3387 search_url, suggest_url, instant_url, favicon_url, encoding, id)); | 3398 search_url, suggest_url, instant_url, favicon_url, encoding, id)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3464 GURL origin(as_gurl.GetOrigin()); | 3475 GURL origin(as_gurl.GetOrigin()); |
| 3465 for (size_t i = 0; i < arraysize(kAllEngines); ++i) { | 3476 for (size_t i = 0; i < arraysize(kAllEngines); ++i) { |
| 3466 GURL engine_url(kAllEngines[i]->search_url); | 3477 GURL engine_url(kAllEngines[i]->search_url); |
| 3467 if (engine_url.is_valid() && (origin == engine_url.GetOrigin())) | 3478 if (engine_url.is_valid() && (origin == engine_url.GetOrigin())) |
| 3468 return kAllEngines[i]->type; | 3479 return kAllEngines[i]->type; |
| 3469 } | 3480 } |
| 3470 | 3481 |
| 3471 return SEARCH_ENGINE_OTHER; | 3482 return SEARCH_ENGINE_OTHER; |
| 3472 } | 3483 } |
| 3473 | 3484 |
| 3485 GURL GetLogoURL(const std::string& url) { | |
| 3486 // Restricted to UI thread because GetEngineType() is so restricted. | |
|
msw
2012/08/27 21:57:26
nit: There doesn't seem to be much value in DCHECK
samarth
2012/08/28 16:18:15
Done.
| |
| 3487 using content::BrowserThread; | |
| 3488 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || | |
| 3489 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 3490 | |
| 3491 switch (GetEngineType(url)) { | |
|
Peter Kasting
2012/08/28 00:04:07
Nit: For now, use "if (GetEngineType(url) == SEARC
samarth
2012/08/28 16:18:15
Done.
| |
| 3492 case SEARCH_ENGINE_GOOGLE: | |
| 3493 return GURL(google_logos.logo_100_percent_url); | |
| 3494 default: | |
| 3495 return GURL(""); | |
|
msw
2012/08/27 21:57:26
nit: remove empty string literal.
samarth
2012/08/28 16:18:15
Done.
| |
| 3496 } | |
| 3497 } | |
|
msw
2012/08/27 21:57:26
nit: some compilers may complain about not all pat
samarth
2012/08/28 16:18:15
Done.
| |
| 3498 | |
| 3499 GURL GetLogo200PercentURL(const std::string& url) { | |
| 3500 // Restricted to UI thread because GetEngineType() is so restricted. | |
|
msw
2012/08/27 21:57:26
ditto: (nit: remove DCHECKs)
samarth
2012/08/28 16:18:15
Done.
| |
| 3501 using content::BrowserThread; | |
| 3502 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || | |
| 3503 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 3504 | |
| 3505 switch (GetEngineType(url)) { | |
| 3506 case SEARCH_ENGINE_GOOGLE: | |
| 3507 return GURL(google_logos.logo_200_percent_url); | |
| 3508 default: | |
| 3509 return GURL(""); | |
|
msw
2012/08/27 21:57:26
ditto (nit: remove empty string literal)
samarth
2012/08/28 16:18:15
Done.
| |
| 3510 } | |
| 3511 } | |
|
msw
2012/08/27 21:57:26
ditto (nit: return GURL() here)
samarth
2012/08/28 16:18:15
Done.
| |
| 3512 | |
| 3474 #if defined(OS_ANDROID) | 3513 #if defined(OS_ANDROID) |
| 3475 | 3514 |
| 3476 void InitCountryCode(const std::string& country_code) { | 3515 void InitCountryCode(const std::string& country_code) { |
| 3477 if (country_code.size() != 2) { | 3516 if (country_code.size() != 2) { |
| 3478 DLOG(ERROR) << "Invalid country code: " << country_code; | 3517 DLOG(ERROR) << "Invalid country code: " << country_code; |
| 3479 g_country_code_at_install = kCountryIDUnknown; | 3518 g_country_code_at_install = kCountryIDUnknown; |
| 3480 } else { | 3519 } else { |
| 3481 g_country_code_at_install = | 3520 g_country_code_at_install = |
| 3482 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); | 3521 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); |
| 3483 } | 3522 } |
| 3484 } | 3523 } |
| 3485 | 3524 |
| 3486 #endif | 3525 #endif |
| 3487 | 3526 |
| 3488 } // namespace TemplateURLPrepopulateData | 3527 } // namespace TemplateURLPrepopulateData |
| OLD | NEW |