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

Side by Side Diff: chrome/browser/search/search.cc

Issue 2232863002: Remove search::GetSearchTerms since it always returns empty string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_query_extract
Patch Set: Android Created 4 years, 4 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
OLDNEW
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/search.h" 5 #include "chrome/browser/search/search.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // URL should not be used because Suggest is disabled. 73 // URL should not be used because Suggest is disabled.
74 // Not used anymore, see crbug.com/340424. 74 // Not used anymore, see crbug.com/340424.
75 // NEW_TAB_URL_SUGGEST_OFF = 5, 75 // NEW_TAB_URL_SUGGEST_OFF = 5,
76 76
77 // URL should not be used because it is blocked for a supervised user. 77 // URL should not be used because it is blocked for a supervised user.
78 NEW_TAB_URL_BLOCKED = 6, 78 NEW_TAB_URL_BLOCKED = 6,
79 79
80 NEW_TAB_URL_MAX 80 NEW_TAB_URL_MAX
81 }; 81 };
82 82
83 // Used to set the Instant support state of the Navigation entry.
84 const char kInstantSupportStateKey[] = "instant_support_state";
85
86 const char kInstantSupportEnabled[] = "Instant support enabled";
87 const char kInstantSupportDisabled[] = "Instant support disabled";
88 const char kInstantSupportUnknown[] = "Instant support unknown";
89
90 base::Feature kUseGoogleLocalNtp { 83 base::Feature kUseGoogleLocalNtp {
91 "UseGoogleLocalNtp", base::FEATURE_DISABLED_BY_DEFAULT 84 "UseGoogleLocalNtp", base::FEATURE_DISABLED_BY_DEFAULT
92 }; 85 };
93 86
94 InstantSupportState StringToInstantSupportState(const base::string16& value) {
95 if (value == base::ASCIIToUTF16(kInstantSupportEnabled))
96 return INSTANT_SUPPORT_YES;
97 else if (value == base::ASCIIToUTF16(kInstantSupportDisabled))
98 return INSTANT_SUPPORT_NO;
99 else
100 return INSTANT_SUPPORT_UNKNOWN;
101 }
102
103 base::string16 InstantSupportStateToString(InstantSupportState state) {
104 switch (state) {
105 case INSTANT_SUPPORT_NO:
106 return base::ASCIIToUTF16(kInstantSupportDisabled);
107 case INSTANT_SUPPORT_YES:
108 return base::ASCIIToUTF16(kInstantSupportEnabled);
109 case INSTANT_SUPPORT_UNKNOWN:
110 return base::ASCIIToUTF16(kInstantSupportUnknown);
111 }
112 return base::ASCIIToUTF16(kInstantSupportUnknown);
113 }
114
115 TemplateURL* GetDefaultSearchProviderTemplateURL(Profile* profile) { 87 TemplateURL* GetDefaultSearchProviderTemplateURL(Profile* profile) {
116 if (profile) { 88 if (profile) {
117 TemplateURLService* template_url_service = 89 TemplateURLService* template_url_service =
118 TemplateURLServiceFactory::GetForProfile(profile); 90 TemplateURLServiceFactory::GetForProfile(profile);
119 if (template_url_service) 91 if (template_url_service)
120 return template_url_service->GetDefaultSearchProvider(); 92 return template_url_service->GetDefaultSearchProvider();
121 } 93 }
122 return NULL; 94 return NULL;
123 } 95 }
124 96
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); 141 const TemplateURLRef& instant_url_ref = template_url->instant_url_ref();
170 UIThreadSearchTermsData search_terms_data(profile); 142 UIThreadSearchTermsData search_terms_data(profile);
171 const GURL instant_url = TemplateURLRefToGURL( 143 const GURL instant_url = TemplateURLRefToGURL(
172 instant_url_ref, search_terms_data, false, false); 144 instant_url_ref, search_terms_data, false, false);
173 if (!instant_url.is_valid()) 145 if (!instant_url.is_valid())
174 return false; 146 return false;
175 147
176 return MatchesOriginAndPath(url, instant_url); 148 return MatchesOriginAndPath(url, instant_url);
177 } 149 }
178 150
179 base::string16 GetSearchTermsImpl(const content::WebContents* contents,
180 const content::NavigationEntry* entry) {
181 // TODO(treib): Remove this and update callers accordingly. crbug.com/627747
182 return base::string16();
183 }
184
185 bool IsURLAllowedForSupervisedUser(const GURL& url, Profile* profile) { 151 bool IsURLAllowedForSupervisedUser(const GURL& url, Profile* profile) {
186 #if defined(ENABLE_SUPERVISED_USERS) 152 #if defined(ENABLE_SUPERVISED_USERS)
187 SupervisedUserService* supervised_user_service = 153 SupervisedUserService* supervised_user_service =
188 SupervisedUserServiceFactory::GetForProfile(profile); 154 SupervisedUserServiceFactory::GetForProfile(profile);
189 SupervisedUserURLFilter* url_filter = 155 SupervisedUserURLFilter* url_filter =
190 supervised_user_service->GetURLFilterForUIThread(); 156 supervised_user_service->GetURLFilterForUIThread();
191 if (url_filter->GetFilteringBehaviorForURL(url) == 157 if (url_filter->GetFilteringBehaviorForURL(url) ==
192 SupervisedUserURLFilter::BLOCK) { 158 SupervisedUserURLFilter::BLOCK) {
193 return false; 159 return false;
194 } 160 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 template_url->ExtractSearchTermsFromURL( 258 template_url->ExtractSearchTermsFromURL(
293 url, UIThreadSearchTermsData(profile), &search_terms); 259 url, UIThreadSearchTermsData(profile), &search_terms);
294 return search_terms; 260 return search_terms;
295 } 261 }
296 262
297 bool IsQueryExtractionAllowedForURL(Profile* profile, const GURL& url) { 263 bool IsQueryExtractionAllowedForURL(Profile* profile, const GURL& url) {
298 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); 264 TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile);
299 return template_url && IsSuitableURLForInstant(url, template_url); 265 return template_url && IsSuitableURLForInstant(url, template_url);
300 } 266 }
301 267
302 base::string16 GetSearchTermsFromNavigationEntry(
303 const content::NavigationEntry* entry) {
304 base::string16 search_terms;
305 if (entry)
306 entry->GetExtraData(sessions::kSearchTermsKey, &search_terms);
307 return search_terms;
308 }
309
310 base::string16 GetSearchTerms(const content::WebContents* contents) {
311 if (!contents)
312 return base::string16();
313
314 const content::NavigationEntry* entry =
315 contents->GetController().GetVisibleEntry();
316 if (!entry)
317 return base::string16();
318
319 if (IsInstantExtendedAPIEnabled()) {
320 InstantSupportState state =
321 GetInstantSupportStateFromNavigationEntry(*entry);
322 if (state == INSTANT_SUPPORT_NO)
323 return base::string16();
324 }
325
326 return GetSearchTermsImpl(contents, entry);
327 }
328
329 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { 268 bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) {
330 return url.is_valid() && 269 return url.is_valid() &&
331 profile && 270 profile &&
332 IsInstantExtendedAPIEnabled() && 271 IsInstantExtendedAPIEnabled() &&
333 (url.SchemeIs(chrome::kChromeSearchScheme) || 272 (url.SchemeIs(chrome::kChromeSearchScheme) ||
334 IsInstantURL(url, profile)); 273 IsInstantURL(url, profile));
335 } 274 }
336 275
337 bool IsRenderedInInstantProcess(const content::WebContents* contents, 276 bool IsRenderedInInstantProcess(const content::WebContents* contents,
338 Profile* profile) { 277 Profile* profile) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 return false; 454 return false;
516 455
517 if (IsInstantNTPURL(*url, profile)) { 456 if (IsInstantNTPURL(*url, profile)) {
518 *url = GURL(chrome::kChromeUINewTabURL); 457 *url = GURL(chrome::kChromeUINewTabURL);
519 return true; 458 return true;
520 } 459 }
521 460
522 return false; 461 return false;
523 } 462 }
524 463
525 void SetInstantSupportStateInNavigationEntry(InstantSupportState state,
526 content::NavigationEntry* entry) {
527 if (!entry)
528 return;
529
530 entry->SetExtraData(kInstantSupportStateKey,
531 InstantSupportStateToString(state));
532 }
533
534 InstantSupportState GetInstantSupportStateFromNavigationEntry(
535 const content::NavigationEntry& entry) {
536 base::string16 value;
537 if (!entry.GetExtraData(kInstantSupportStateKey, &value))
538 return INSTANT_SUPPORT_UNKNOWN;
539
540 return StringToInstantSupportState(value);
541 }
542
543 } // namespace search 464 } // namespace search
OLDNEW
« no previous file with comments | « chrome/browser/search/search.h ('k') | chrome/browser/ui/android/toolbar/toolbar_model_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698