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

Side by Side Diff: chrome/browser/ui/omnibox/chrome_omnibox_client.cc

Issue 1260033003: Partially componentize //chrome/browser/search/search.{h,cc} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation on iOS Created 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/omnibox/chrome_omnibox_client.h" 5 #include "chrome/browser/ui/omnibox/chrome_omnibox_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // highly or if kAllowPrefetchNonDefaultMatch field trial is enabled, we'll 52 // highly or if kAllowPrefetchNonDefaultMatch field trial is enabled, we'll
53 // return it. 53 // return it.
54 // 54 //
55 // If the kAllowPrefetchNonDefaultMatch field trial is enabled we return the 55 // If the kAllowPrefetchNonDefaultMatch field trial is enabled we return the
56 // prefetch suggestion even if it is not the default match. Otherwise we only 56 // prefetch suggestion even if it is not the default match. Otherwise we only
57 // care about matches that are the default or the second entry in the dropdown 57 // care about matches that are the default or the second entry in the dropdown
58 // (which can happen for non-default matches when a top verbatim match is 58 // (which can happen for non-default matches when a top verbatim match is
59 // shown); for other matches, we think the likelihood of the user selecting 59 // shown); for other matches, we think the likelihood of the user selecting
60 // them is low enough that prefetching isn't worth doing. 60 // them is low enough that prefetching isn't worth doing.
61 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) { 61 const AutocompleteMatch* GetMatchToPrefetch(const AutocompleteResult& result) {
62 if (chrome::ShouldAllowPrefetchNonDefaultMatch()) { 62 if (search::ShouldAllowPrefetchNonDefaultMatch()) {
63 const AutocompleteResult::const_iterator prefetch_match = std::find_if( 63 const AutocompleteResult::const_iterator prefetch_match = std::find_if(
64 result.begin(), result.end(), SearchProvider::ShouldPrefetch); 64 result.begin(), result.end(), SearchProvider::ShouldPrefetch);
65 return prefetch_match != result.end() ? &(*prefetch_match) : NULL; 65 return prefetch_match != result.end() ? &(*prefetch_match) : NULL;
66 } 66 }
67 67
68 // If the default match should be prefetched, do that. 68 // If the default match should be prefetched, do that.
69 const auto default_match = result.default_match(); 69 const auto default_match = result.default_match();
70 if ((default_match != result.end()) && 70 if ((default_match != result.end()) &&
71 SearchProvider::ShouldPrefetch(*default_match)) 71 SearchProvider::ShouldPrefetch(*default_match))
72 return &(*default_match); 72 return &(*default_match);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 bool ChromeOmniboxClient::CurrentPageExists() const { 130 bool ChromeOmniboxClient::CurrentPageExists() const {
131 return (controller_->GetWebContents() != NULL); 131 return (controller_->GetWebContents() != NULL);
132 } 132 }
133 133
134 const GURL& ChromeOmniboxClient::GetURL() const { 134 const GURL& ChromeOmniboxClient::GetURL() const {
135 return controller_->GetWebContents()->GetVisibleURL(); 135 return controller_->GetWebContents()->GetVisibleURL();
136 } 136 }
137 137
138 bool ChromeOmniboxClient::IsInstantNTP() const { 138 bool ChromeOmniboxClient::IsInstantNTP() const {
139 return chrome::IsInstantNTP(controller_->GetWebContents()); 139 return search::IsInstantNTP(controller_->GetWebContents());
140 } 140 }
141 141
142 bool ChromeOmniboxClient::IsSearchResultsPage() const { 142 bool ChromeOmniboxClient::IsSearchResultsPage() const {
143 Profile* profile = Profile::FromBrowserContext( 143 Profile* profile = Profile::FromBrowserContext(
144 controller_->GetWebContents()->GetBrowserContext()); 144 controller_->GetWebContents()->GetBrowserContext());
145 return TemplateURLServiceFactory::GetForProfile(profile)-> 145 return TemplateURLServiceFactory::GetForProfile(profile)->
146 IsSearchResultsPageFromDefaultSearchProvider(GetURL()); 146 IsSearchResultsPageFromDefaultSearchProvider(GetURL());
147 } 147 }
148 148
149 bool ChromeOmniboxClient::IsLoading() const { 149 bool ChromeOmniboxClient::IsLoading() const {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if (!controller_->GetWebContents()) 215 if (!controller_->GetWebContents())
216 return; 216 return;
217 SearchTabHelper::FromWebContents( 217 SearchTabHelper::FromWebContents(
218 controller_->GetWebContents())->OmniboxFocusChanged(state, reason); 218 controller_->GetWebContents())->OmniboxFocusChanged(state, reason);
219 } 219 }
220 220
221 void ChromeOmniboxClient::OnResultChanged( 221 void ChromeOmniboxClient::OnResultChanged(
222 const AutocompleteResult& result, 222 const AutocompleteResult& result,
223 bool default_match_changed, 223 bool default_match_changed,
224 const base::Callback<void(const SkBitmap& bitmap)>& on_bitmap_fetched) { 224 const base::Callback<void(const SkBitmap& bitmap)>& on_bitmap_fetched) {
225 if (chrome::IsInstantExtendedAPIEnabled() && 225 if (search::IsInstantExtendedAPIEnabled() &&
226 ((default_match_changed && result.default_match() != result.end()) || 226 ((default_match_changed && result.default_match() != result.end()) ||
227 (chrome::ShouldAllowPrefetchNonDefaultMatch() && !result.empty()))) { 227 (search::ShouldAllowPrefetchNonDefaultMatch() && !result.empty()))) {
228 InstantSuggestion prefetch_suggestion; 228 InstantSuggestion prefetch_suggestion;
229 const AutocompleteMatch* match_to_prefetch = GetMatchToPrefetch(result); 229 const AutocompleteMatch* match_to_prefetch = GetMatchToPrefetch(result);
230 if (match_to_prefetch) { 230 if (match_to_prefetch) {
231 prefetch_suggestion.text = match_to_prefetch->contents; 231 prefetch_suggestion.text = match_to_prefetch->contents;
232 prefetch_suggestion.metadata = 232 prefetch_suggestion.metadata =
233 SearchProvider::GetSuggestMetadata(*match_to_prefetch); 233 SearchProvider::GetSuggestMetadata(*match_to_prefetch);
234 } 234 }
235 // Send the prefetch suggestion unconditionally to the InstantPage. If 235 // Send the prefetch suggestion unconditionally to the InstantPage. If
236 // there is no suggestion to prefetch, we need to send a blank query to 236 // there is no suggestion to prefetch, we need to send a blank query to
237 // clear the prefetched results. 237 // clear the prefetched results.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 match.destination_url, 305 match.destination_url,
306 predictors::AutocompleteActionPredictor::IsPreconnectable(match)); 306 predictors::AutocompleteActionPredictor::IsPreconnectable(match));
307 } 307 }
308 // We could prefetch the alternate nav URL, if any, but because there 308 // We could prefetch the alternate nav URL, if any, but because there
309 // can be many of these as a user types an initial series of characters, 309 // can be many of these as a user types an initial series of characters,
310 // the OS DNS cache could suffer eviction problems for minimal gain. 310 // the OS DNS cache could suffer eviction problems for minimal gain.
311 } 311 }
312 312
313 void ChromeOmniboxClient::SetSuggestionToPrefetch( 313 void ChromeOmniboxClient::SetSuggestionToPrefetch(
314 const InstantSuggestion& suggestion) { 314 const InstantSuggestion& suggestion) {
315 DCHECK(chrome::IsInstantExtendedAPIEnabled()); 315 DCHECK(search::IsInstantExtendedAPIEnabled());
316 content::WebContents* web_contents = controller_->GetWebContents(); 316 content::WebContents* web_contents = controller_->GetWebContents();
317 if (web_contents && 317 if (web_contents &&
318 SearchTabHelper::FromWebContents(web_contents)->IsSearchResultsPage()) { 318 SearchTabHelper::FromWebContents(web_contents)->IsSearchResultsPage()) {
319 if (chrome::ShouldPrefetchSearchResultsOnSRP()) { 319 if (search::ShouldPrefetchSearchResultsOnSRP()) {
320 SearchTabHelper::FromWebContents(web_contents)-> 320 SearchTabHelper::FromWebContents(web_contents)->
321 SetSuggestionToPrefetch(suggestion); 321 SetSuggestionToPrefetch(suggestion);
322 } 322 }
323 } else { 323 } else {
324 InstantSearchPrerenderer* prerenderer = 324 InstantSearchPrerenderer* prerenderer =
325 InstantSearchPrerenderer::GetForProfile(profile_); 325 InstantSearchPrerenderer::GetForProfile(profile_);
326 if (prerenderer) 326 if (prerenderer)
327 prerenderer->Prerender(suggestion); 327 prerenderer->Prerender(suggestion);
328 } 328 }
329 } 329 }
330 330
331 void ChromeOmniboxClient::OnBitmapFetched(const BitmapFetchedCallback& callback, 331 void ChromeOmniboxClient::OnBitmapFetched(const BitmapFetchedCallback& callback,
332 const SkBitmap& bitmap) { 332 const SkBitmap& bitmap) {
333 request_id_ = BitmapFetcherService::REQUEST_ID_INVALID; 333 request_id_ = BitmapFetcherService::REQUEST_ID_INVALID;
334 callback.Run(bitmap); 334 callback.Run(bitmap);
335 } 335 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/extensions/extension_install_ui_default.cc ('k') | chrome/browser/ui/search/instant_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698