OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search_terms_data.h" | 5 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/google/google_brand.h" | 12 #include "chrome/browser/google/google_brand.h" |
13 #include "chrome/browser/google/google_profile_helper.h" | 13 #include "chrome/browser/google/google_profile_helper.h" |
14 #include "chrome/browser/google/google_util.h" | 14 #include "chrome/browser/google/google_util.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/search/search.h" | 16 #include "chrome/browser/search/search.h" |
17 #include "chrome/browser/sync/glue/device_info.h" | 17 #include "chrome/browser/sync/glue/device_info.h" |
18 #include "chrome/browser/themes/theme_service.h" | 18 #include "chrome/browser/themes/theme_service.h" |
19 #include "chrome/browser/themes/theme_service_factory.h" | 19 #include "chrome/browser/themes/theme_service_factory.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "components/google/core/browser/google_url_tracker.h" | |
23 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
24 #include "sync/protocol/sync.pb.h" | 23 #include "sync/protocol/sync.pb.h" |
25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
26 | 25 |
27 #if defined(ENABLE_RLZ) | 26 #if defined(ENABLE_RLZ) |
28 #include "chrome/browser/rlz/rlz.h" | 27 #include "chrome/browser/rlz/rlz.h" |
29 #endif | 28 #endif |
30 | 29 |
31 using content::BrowserThread; | 30 using content::BrowserThread; |
32 | 31 |
33 SearchTermsData::SearchTermsData() { | |
34 } | |
35 | |
36 SearchTermsData::~SearchTermsData() { | |
37 } | |
38 | |
39 std::string SearchTermsData::GoogleBaseURLValue() const { | |
40 return GoogleURLTracker::kDefaultGoogleHomepage; | |
41 } | |
42 | |
43 std::string SearchTermsData::GoogleBaseSuggestURLValue() const { | |
44 // Start with the Google base URL. | |
45 const GURL base_url(GoogleBaseURLValue()); | |
46 DCHECK(base_url.is_valid()); | |
47 | |
48 GURL::Replacements repl; | |
49 | |
50 // Replace any existing path with "/complete/". | |
51 // SetPathStr() requires its argument to stay in scope as long as |repl| is, | |
52 // so "/complete/" can't be passed to SetPathStr() directly, it needs to be in | |
53 // a variable. | |
54 const std::string suggest_path("/complete/"); | |
55 repl.SetPathStr(suggest_path); | |
56 | |
57 // Clear the query and ref. | |
58 repl.ClearQuery(); | |
59 repl.ClearRef(); | |
60 return base_url.ReplaceComponents(repl).spec(); | |
61 } | |
62 | |
63 std::string SearchTermsData::GetApplicationLocale() const { | |
64 return "en"; | |
65 } | |
66 | |
67 base::string16 SearchTermsData::GetRlzParameterValue(bool from_app_list) const { | |
68 return base::string16(); | |
69 } | |
70 | |
71 std::string SearchTermsData::GetSearchClient() const { | |
72 return std::string(); | |
73 } | |
74 | |
75 std::string SearchTermsData::GetSuggestClient() const { | |
76 return std::string(); | |
77 } | |
78 | |
79 std::string SearchTermsData::GetSuggestRequestIdentifier() const { | |
80 return std::string(); | |
81 } | |
82 | |
83 std::string SearchTermsData::NTPIsThemedParam() const { | |
84 return std::string(); | |
85 } | |
86 | |
87 // static | 32 // static |
88 std::string* UIThreadSearchTermsData::google_base_url_ = NULL; | 33 std::string* UIThreadSearchTermsData::google_base_url_ = NULL; |
89 | 34 |
90 UIThreadSearchTermsData::UIThreadSearchTermsData(Profile* profile) | 35 UIThreadSearchTermsData::UIThreadSearchTermsData(Profile* profile) |
91 : profile_(profile) { | 36 : profile_(profile) { |
92 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | 37 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || |
93 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 38 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
94 } | 39 } |
95 | 40 |
96 std::string UIThreadSearchTermsData::GoogleBaseURLValue() const { | 41 std::string UIThreadSearchTermsData::GoogleBaseURLValue() const { |
97 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | 42 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || |
98 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
99 if (google_base_url_) | 44 if (google_base_url_) |
100 return *google_base_url_; | 45 return *google_base_url_; |
101 GURL base_url(google_util::CommandLineGoogleBaseURL()); | 46 GURL base_url(google_util::CommandLineGoogleBaseURL()); |
102 if (base_url.is_valid()) | 47 if (base_url.is_valid()) |
103 return base_url.spec(); | 48 return base_url.spec(); |
104 return profile_ ? | 49 return profile_ ? |
105 google_profile_helper::GetGoogleHomePageURL(profile_).spec() : | 50 google_profile_helper::GetGoogleHomePageURL(profile_).spec() : |
106 SearchTermsData::GoogleBaseURLValue(); | 51 SearchTermsData::GoogleBaseURLValue(); |
107 } | 52 } |
108 | 53 |
109 std::string UIThreadSearchTermsData::GetApplicationLocale() const { | 54 std::string UIThreadSearchTermsData::GetApplicationLocale() const { |
110 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | 55 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || |
111 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 56 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
112 return g_browser_process->GetApplicationLocale(); | 57 return g_browser_process->GetApplicationLocale(); |
113 } | 58 } |
114 | 59 |
115 // Android implementations are located in search_terms_data_android.cc. | 60 // Android implementations are in ui_thread_search_terms_data_android.cc. |
116 #if !defined(OS_ANDROID) | 61 #if !defined(OS_ANDROID) |
117 base::string16 UIThreadSearchTermsData::GetRlzParameterValue( | 62 base::string16 UIThreadSearchTermsData::GetRlzParameterValue( |
118 bool from_app_list) const { | 63 bool from_app_list) const { |
119 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | 64 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || |
120 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 65 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
121 base::string16 rlz_string; | 66 base::string16 rlz_string; |
122 #if defined(ENABLE_RLZ) | 67 #if defined(ENABLE_RLZ) |
123 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 68 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
124 // means a chromium install. This is ok. | 69 // means a chromium install. This is ok. |
125 std::string brand; | 70 std::string brand; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 #endif // defined(ENABLE_THEMES) | 144 #endif // defined(ENABLE_THEMES) |
200 | 145 |
201 return std::string(); | 146 return std::string(); |
202 } | 147 } |
203 | 148 |
204 // static | 149 // static |
205 void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) { | 150 void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) { |
206 delete google_base_url_; | 151 delete google_base_url_; |
207 google_base_url_ = base_url.empty() ? NULL : new std::string(base_url); | 152 google_base_url_ = base_url.empty() ? NULL : new std::string(base_url); |
208 } | 153 } |
OLD | NEW |