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

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

Issue 10697087: Remove content->app dependency in template_url_prepopulate_data.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | « chrome/browser/search_engines/template_url_prepopulate_data.h ('k') | no next file » | 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
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h"
12 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
13 #include "base/string16.h" 14 #include "base/string16.h"
14 #include "base/string_piece.h" 15 #include "base/string_piece.h"
15 #include "base/string_util.h" 16 #include "base/string_util.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
18 #include "chrome/browser/google/google_util.h" 19 #include "chrome/browser/google/google_util.h"
19 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/search_engines/search_engine_type.h" 22 #include "chrome/browser/search_engines/search_engine_type.h"
(...skipping 2693 matching lines...) Expand 10 before | Expand all | Expand 10 after
2715 2716
2716 2717
2717 // Geographic mappings ///////////////////////////////////////////////////////// 2718 // Geographic mappings /////////////////////////////////////////////////////////
2718 2719
2719 // Please refer to ISO 3166-1 for information about the two-character country 2720 // Please refer to ISO 3166-1 for information about the two-character country
2720 // codes; http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 is useful. In the 2721 // codes; http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 is useful. In the
2721 // following (C++) code, we pack the two letters of the country code into an int 2722 // following (C++) code, we pack the two letters of the country code into an int
2722 // value we call the CountryID. 2723 // value we call the CountryID.
2723 2724
2724 const int kCountryIDUnknown = -1; 2725 const int kCountryIDUnknown = -1;
2726 const int kCountryIDNotSet = 0;
2725 2727
2726 inline int CountryCharsToCountryID(char c1, char c2) { 2728 inline int CountryCharsToCountryID(char c1, char c2) {
2727 return c1 << 8 | c2; 2729 return c1 << 8 | c2;
2728 } 2730 }
2729 2731
2730 int CountryCharsToCountryIDWithUpdate(char c1, char c2) { 2732 int CountryCharsToCountryIDWithUpdate(char c1, char c2) {
2731 // SPECIAL CASE: In 2003, Yugoslavia renamed itself to Serbia and Montenegro. 2733 // SPECIAL CASE: In 2003, Yugoslavia renamed itself to Serbia and Montenegro.
2732 // Serbia and Montenegro dissolved their union in June 2006. Yugoslavia was 2734 // Serbia and Montenegro dissolved their union in June 2006. Yugoslavia was
2733 // ISO 'YU' and Serbia and Montenegro were ISO 'CS'. Serbia was subsequently 2735 // ISO 'YU' and Serbia and Montenegro were ISO 'CS'. Serbia was subsequently
2734 // issued 'RS' and Montenegro 'ME'. Windows XP and Mac OS X Leopard still use 2736 // issued 'RS' and Montenegro 'ME'. Windows XP and Mac OS X Leopard still use
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2822 UniChar isobuf[2]; 2824 UniChar isobuf[2];
2823 CFRange char_range = CFRangeMake(0, 2); 2825 CFRange char_range = CFRangeMake(0, 2);
2824 CFStringGetCharacters(country, char_range, isobuf); 2826 CFStringGetCharacters(country, char_range, isobuf);
2825 2827
2826 return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]), 2828 return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]),
2827 static_cast<char>(isobuf[1])); 2829 static_cast<char>(isobuf[1]));
2828 } 2830 }
2829 2831
2830 #elif defined(OS_ANDROID) 2832 #elif defined(OS_ANDROID)
2831 2833
2834 // Initialized by InitCountryCode().
2835 int g_country_code_at_install = kCountryIDNotSet;
2836
2832 int GetCurrentCountryID() { 2837 int GetCurrentCountryID() {
2833 const std::string country_code_at_install = 2838 DCHECK(g_country_code_at_install != kCountryIDNotSet);
2834 TemplateURLPrepopulateData::GetCountryCodeAtInstall(); 2839 return g_country_code_at_install;
2835 return country_code_at_install.empty() ? kCountryIDUnknown :
2836 CountryCharsToCountryIDWithUpdate(country_code_at_install[0],
2837 country_code_at_install[1]);
2838 } 2840 }
2839 2841
2840 #elif defined(OS_POSIX) 2842 #elif defined(OS_POSIX)
2841 2843
2842 int GetCurrentCountryID() { 2844 int GetCurrentCountryID() {
2843 const char* locale = setlocale(LC_MESSAGES, NULL); 2845 const char* locale = setlocale(LC_MESSAGES, NULL);
2844 2846
2845 if (!locale) 2847 if (!locale)
2846 return kCountryIDUnknown; 2848 return kCountryIDUnknown;
2847 2849
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
3438 GURL origin(as_gurl.GetOrigin()); 3440 GURL origin(as_gurl.GetOrigin());
3439 for (size_t i = 0; i < arraysize(kAllEngines); ++i) { 3441 for (size_t i = 0; i < arraysize(kAllEngines); ++i) {
3440 GURL engine_url(kAllEngines[i]->search_url); 3442 GURL engine_url(kAllEngines[i]->search_url);
3441 if (engine_url.is_valid() && (origin == engine_url.GetOrigin())) 3443 if (engine_url.is_valid() && (origin == engine_url.GetOrigin()))
3442 return kAllEngines[i]->type; 3444 return kAllEngines[i]->type;
3443 } 3445 }
3444 3446
3445 return SEARCH_ENGINE_OTHER; 3447 return SEARCH_ENGINE_OTHER;
3446 } 3448 }
3447 3449
3450 #if defined(OS_ANDROID)
3451
3452 void InitCountryCode(const std::string& country_code) {
3453 if (country_code.size() != 2) {
3454 LOG(ERROR) << "Invalid country code: " << country_code;
SteveT 2012/07/05 13:38:28 nit: Can we DVLOG instead? Or is this useful in re
Philippe 2012/07/05 14:27:40 We don't need that in release builds indeed. I mad
3455 g_country_code_at_install = kCountryIDUnknown;
3456 } else {
3457 g_country_code_at_install =
3458 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]);
3459 }
3460 }
3461
3462 #endif
3463
3448 } // namespace TemplateURLPrepopulateData 3464 } // namespace TemplateURLPrepopulateData
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url_prepopulate_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698