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/search_terms_data.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/field_trial.h" | |
9 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/google/google_url_tracker.h" | 9 #include "chrome/browser/google/google_url_tracker.h" |
11 #include "chrome/browser/google/google_util.h" | 10 #include "chrome/browser/google/google_util.h" |
12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser_instant_controller.h" | 12 #include "chrome/browser/ui/browser_instant_controller.h" |
14 #include "chrome/browser/ui/search/search.h" | 13 #include "chrome/browser/ui/search/search.h" |
15 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
17 | 16 |
18 #if defined(ENABLE_RLZ) | 17 #if defined(ENABLE_RLZ) |
19 #include "chrome/browser/google/google_util.h" | |
20 #include "chrome/browser/rlz/rlz.h" | 18 #include "chrome/browser/rlz/rlz.h" |
21 #endif | 19 #endif |
22 | 20 |
23 using content::BrowserThread; | 21 using content::BrowserThread; |
24 | 22 |
25 SearchTermsData::SearchTermsData() { | 23 SearchTermsData::SearchTermsData() { |
26 } | 24 } |
27 | 25 |
28 SearchTermsData::~SearchTermsData() { | 26 SearchTermsData::~SearchTermsData() { |
29 } | 27 } |
(...skipping 19 matching lines...) Expand all Loading... | |
49 // Clear the query and ref. | 47 // Clear the query and ref. |
50 repl.ClearQuery(); | 48 repl.ClearQuery(); |
51 repl.ClearRef(); | 49 repl.ClearRef(); |
52 return base_url.ReplaceComponents(repl).spec(); | 50 return base_url.ReplaceComponents(repl).spec(); |
53 } | 51 } |
54 | 52 |
55 std::string SearchTermsData::GetApplicationLocale() const { | 53 std::string SearchTermsData::GetApplicationLocale() const { |
56 return "en"; | 54 return "en"; |
57 } | 55 } |
58 | 56 |
59 #if defined(ENABLE_RLZ) | |
60 string16 SearchTermsData::GetRlzParameterValue() const { | 57 string16 SearchTermsData::GetRlzParameterValue() const { |
61 return string16(); | 58 return string16(); |
62 } | 59 } |
63 #endif | 60 |
61 std::string SearchTermsData::GetSearchClient() const { | |
62 return std::string(); | |
63 } | |
64 | 64 |
65 std::string SearchTermsData::InstantEnabledParam() const { | 65 std::string SearchTermsData::InstantEnabledParam() const { |
66 return std::string(); | 66 return std::string(); |
67 } | 67 } |
68 | 68 |
69 // static | 69 // static |
70 std::string* UIThreadSearchTermsData::google_base_url_ = NULL; | 70 std::string* UIThreadSearchTermsData::google_base_url_ = NULL; |
71 | 71 |
72 UIThreadSearchTermsData::UIThreadSearchTermsData(Profile* profile) | 72 UIThreadSearchTermsData::UIThreadSearchTermsData(Profile* profile) |
73 : profile_(profile) { | 73 : profile_(profile) { |
74 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || | 74 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || |
75 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 75 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
76 } | 76 } |
77 | 77 |
78 std::string UIThreadSearchTermsData::GoogleBaseURLValue() const { | 78 std::string UIThreadSearchTermsData::GoogleBaseURLValue() const { |
79 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || | 79 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || |
80 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 80 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
81 if (google_base_url_) | 81 if (google_base_url_) |
82 return *google_base_url_; | 82 return *google_base_url_; |
83 return profile_ ? GoogleURLTracker::GoogleURL(profile_).spec() : | 83 return profile_ ? GoogleURLTracker::GoogleURL(profile_).spec() : |
84 SearchTermsData::GoogleBaseURLValue(); | 84 SearchTermsData::GoogleBaseURLValue(); |
85 } | 85 } |
86 | 86 |
87 std::string UIThreadSearchTermsData::GetApplicationLocale() const { | 87 std::string UIThreadSearchTermsData::GetApplicationLocale() const { |
88 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || | 88 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || |
89 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 89 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
90 return g_browser_process->GetApplicationLocale(); | 90 return g_browser_process->GetApplicationLocale(); |
91 } | 91 } |
92 | 92 |
93 #if defined(ENABLE_RLZ) | 93 #if !defined(OS_ANDROID) |
94 // Android implementations are located in search_terms_data_android.cc. | |
Peter Kasting
2012/12/07 23:32:57
Tiny nit: I'd put this comment above the #if
gone
2012/12/08 00:32:52
Done.
| |
94 string16 UIThreadSearchTermsData::GetRlzParameterValue() const { | 95 string16 UIThreadSearchTermsData::GetRlzParameterValue() const { |
95 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || | 96 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || |
96 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 97 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
97 string16 rlz_string; | 98 string16 rlz_string; |
99 #if defined(ENABLE_RLZ) | |
98 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 100 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
99 // means a chromium install. This is ok. | 101 // means a chromium install. This is ok. |
100 std::string brand; | 102 std::string brand; |
101 if (google_util::GetBrand(&brand) && !brand.empty() && | 103 if (google_util::GetBrand(&brand) && !brand.empty() && |
102 !google_util::IsOrganic(brand)) { | 104 !google_util::IsOrganic(brand)) { |
103 // This call will return false the first time(s) it is called until the | 105 // This call will return false the first time(s) it is called until the |
104 // value has been cached. This normally would mean that at most one omnibox | 106 // value has been cached. This normally would mean that at most one omnibox |
105 // search might not send the RLZ data but this is not really a problem. | 107 // search might not send the RLZ data but this is not really a problem. |
106 RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz_string); | 108 RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz_string); |
107 } | 109 } |
110 #endif | |
108 return rlz_string; | 111 return rlz_string; |
109 } | 112 } |
113 | |
114 std::string UIThreadSearchTermsData::GetSearchClient() const { | |
115 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || | |
116 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
Peter Kasting
2012/12/07 23:32:57
Nit: Since you changed it everywhere else, indent
gone
2012/12/08 00:32:52
Ah, missed this.
| |
117 return std::string(); | |
118 } | |
110 #endif | 119 #endif |
111 | 120 |
112 std::string UIThreadSearchTermsData::InstantEnabledParam() const { | 121 std::string UIThreadSearchTermsData::InstantEnabledParam() const { |
113 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || | 122 DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || |
114 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
115 if (chrome::search::IsInstantExtendedAPIEnabled(profile_)) | 124 if (chrome::search::IsInstantExtendedAPIEnabled(profile_)) |
116 return std::string(google_util::kInstantExtendedAPIParam) + "=1&"; | 125 return std::string(google_util::kInstantExtendedAPIParam) + "=1&"; |
117 if (chrome::BrowserInstantController::IsInstantEnabled(profile_)) | 126 if (chrome::BrowserInstantController::IsInstantEnabled(profile_)) |
118 return "ion=1&"; | 127 return "ion=1&"; |
119 return std::string(); | 128 return std::string(); |
120 } | 129 } |
121 | 130 |
122 // static | 131 // static |
123 void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) { | 132 void UIThreadSearchTermsData::SetGoogleBaseURL(const std::string& base_url) { |
124 delete google_base_url_; | 133 delete google_base_url_; |
125 google_base_url_ = base_url.empty() ? NULL : new std::string(base_url); | 134 google_base_url_ = base_url.empty() ? NULL : new std::string(base_url); |
126 } | 135 } |
OLD | NEW |