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

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

Issue 11170007: Make some of the search engine configuration data from master_preferences optional. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3542 matching lines...) Expand 10 before | Expand all | Expand 10 after
3553 void GetPrepopulatedTemplateFromPrefs(Profile* profile, 3553 void GetPrepopulatedTemplateFromPrefs(Profile* profile,
3554 std::vector<TemplateURL*>* t_urls) { 3554 std::vector<TemplateURL*>* t_urls) {
3555 if (!profile) 3555 if (!profile)
3556 return; 3556 return;
3557 3557
3558 const ListValue* list = 3558 const ListValue* list =
3559 profile->GetPrefs()->GetList(prefs::kSearchProviderOverrides); 3559 profile->GetPrefs()->GetList(prefs::kSearchProviderOverrides);
3560 if (!list) 3560 if (!list)
3561 return; 3561 return;
3562 3562
3563 string16 name; 3563 string16 name;
Peter Kasting 2012/10/16 17:48:32 Nit: I suggest moving all these declarations insid
Joao da Silva 2012/10/16 18:53:36 Done.
3564 string16 keyword; 3564 string16 keyword;
3565 std::string search_url; 3565 std::string search_url;
3566 std::string suggest_url; 3566 std::string favicon;
Peter Kasting 2012/10/16 17:48:32 Nit: Leave this named "favicon_url"
Joao da Silva 2012/10/16 18:53:36 But but but then the line is 81 chars! (Done!)
3567 std::string instant_url;
3568 const ListValue* alternate_urls = NULL;
3569 std::string favicon_url;
3570 std::string encoding; 3567 std::string encoding;
3571 int id; 3568 int id;
3569 const ListValue kEmptyList;
Peter Kasting 2012/10/16 17:48:32 Nit: This one I'd declare just above |alternate_ur
Joao da Silva 2012/10/16 18:53:36 Done.
3572 3570
3573 size_t num_engines = list->GetSize(); 3571 size_t num_engines = list->GetSize();
3574 for (size_t i = 0; i != num_engines; ++i) { 3572 for (size_t i = 0; i != num_engines; ++i) {
3575 const DictionaryValue* engine; 3573 const DictionaryValue* engine;
3574 // The following fields are required for each search engine configuration.
3576 if (list->GetDictionary(i, &engine) && 3575 if (list->GetDictionary(i, &engine) &&
3577 engine->GetString("name", &name) && 3576 engine->GetString("name", &name) && !name.empty() &&
3578 engine->GetString("keyword", &keyword) && 3577 engine->GetString("keyword", &keyword) && !keyword.empty() &&
3579 engine->GetString("search_url", &search_url) && 3578 engine->GetString("search_url", &search_url) && !search_url.empty() &&
3580 engine->GetString("suggest_url", &suggest_url) && 3579 engine->GetString("favicon_url", &favicon) && !favicon.empty() &&
3581 engine->GetString("instant_url", &instant_url) && 3580 engine->GetString("encoding", &encoding) && !encoding.empty() &&
3582 engine->GetList("alternate_urls", &alternate_urls) &&
3583 engine->GetString("favicon_url", &favicon_url) &&
3584 engine->GetString("encoding", &encoding) &&
3585 engine->GetInteger("id", &id)) { 3581 engine->GetInteger("id", &id)) {
3586 // These next fields are not allowed to be empty. 3582 // These fields are optional.
3587 if (name.empty() || keyword.empty() || search_url.empty() || 3583 std::string suggest_url;
3588 favicon_url.empty() || encoding.empty()) 3584 std::string instant_url;
3589 return; 3585 const ListValue* alternate_urls = &kEmptyList;
3590 } else { 3586 engine->GetString("suggest_url", &suggest_url);
3591 // Got a parsing error. No big deal. 3587 engine->GetString("instant_url", &instant_url);
3592 continue; 3588 engine->GetList("alternate_urls", &alternate_urls);
3589 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword,
3590 search_url, suggest_url, instant_url, *alternate_urls, favicon,
3591 encoding, id));
3593 } 3592 }
3594 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword,
3595 search_url, suggest_url, instant_url, *alternate_urls, favicon_url,
3596 encoding, id));
3597 } 3593 }
3598 } 3594 }
3599 3595
3600 // The caller owns the returned TemplateURL. 3596 // The caller owns the returned TemplateURL.
3601 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine( 3597 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine(
3602 Profile* profile, 3598 Profile* profile,
3603 const PrepopulatedEngine& engine) { 3599 const PrepopulatedEngine& engine) {
3604 3600
3605 // Use an empty list if there are no alternate_urls. 3601 // Use an empty list if there are no alternate_urls.
3606 ListValue empty_list; 3602 ListValue empty_list;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3711 g_country_code_at_install = kCountryIDUnknown; 3707 g_country_code_at_install = kCountryIDUnknown;
3712 } else { 3708 } else {
3713 g_country_code_at_install = 3709 g_country_code_at_install =
3714 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); 3710 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]);
3715 } 3711 }
3716 } 3712 }
3717 3713
3718 #endif 3714 #endif
3719 3715
3720 } // namespace TemplateURLPrepopulateData 3716 } // namespace TemplateURLPrepopulateData
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698