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

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

Issue 18119005: Misc. cleanup: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 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/util.cc ('k') | chrome/browser/ui/omnibox/omnibox_edit_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/omnibox_controller.h" 5 #include "chrome/browser/ui/omnibox/omnibox_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 8 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
9 #include "chrome/browser/autocomplete/autocomplete_match.h" 9 #include "chrome/browser/autocomplete/autocomplete_match.h"
10 #include "chrome/browser/autocomplete/search_provider.h" 10 #include "chrome/browser/autocomplete/search_provider.h"
11 #include "chrome/browser/net/predictor.h" 11 #include "chrome/browser/net/predictor.h"
12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" 12 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
13 #include "chrome/browser/prerender/prerender_field_trial.h" 13 #include "chrome/browser/prerender/prerender_field_trial.h"
14 #include "chrome/browser/prerender/prerender_manager.h" 14 #include "chrome/browser/prerender/prerender_manager.h"
15 #include "chrome/browser/prerender/prerender_manager_factory.h" 15 #include "chrome/browser/prerender/prerender_manager_factory.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/search/search.h" 17 #include "chrome/browser/search/search.h"
18 #include "chrome/browser/search_engines/template_url_service.h" 18 #include "chrome/browser/search_engines/template_url_service.h"
19 #include "chrome/browser/search_engines/template_url_service_factory.h" 19 #include "chrome/browser/search_engines/template_url_service_factory.h"
20 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" 20 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h"
21 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" 21 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
22 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 22 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
23 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" 23 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
24 #include "chrome/browser/ui/search/instant_controller.h" 24 #include "chrome/browser/ui/search/instant_controller.h"
25 #include "extensions/common/constants.h" 25 #include "extensions/common/constants.h"
26 #include "ui/gfx/rect.h" 26 #include "ui/gfx/rect.h"
27 27
28 using predictors::AutocompleteActionPredictor;
29
30 namespace {
31
32 string16 GetDefaultSearchProviderKeyword(Profile* profile) {
33 TemplateURLService* template_url_service =
34 TemplateURLServiceFactory::GetForProfile(profile);
35 if (template_url_service) {
36 TemplateURL* template_url =
37 template_url_service->GetDefaultSearchProvider();
38 if (template_url)
39 return template_url->keyword();
40 }
41 return string16();
42 }
43
44 } // namespace
45 28
46 OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model, 29 OmniboxController::OmniboxController(OmniboxEditModel* omnibox_edit_model,
47 Profile* profile) 30 Profile* profile)
48 : omnibox_edit_model_(omnibox_edit_model), 31 : omnibox_edit_model_(omnibox_edit_model),
49 profile_(profile) { 32 profile_(profile) {
50 autocomplete_controller_.reset(new AutocompleteController(profile, this, 33 autocomplete_controller_.reset(new AutocompleteController(profile, this,
51 chrome::IsInstantExtendedAPIEnabled() ? 34 chrome::IsInstantExtendedAPIEnabled() ?
52 AutocompleteClassifier::kInstantExtendedOmniboxProviders : 35 AutocompleteClassifier::kInstantExtendedOmniboxProviders :
53 AutocompleteClassifier::kDefaultOmniboxProviders)); 36 AutocompleteClassifier::kDefaultOmniboxProviders));
54 } 37 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 205 }
223 206
224 void OmniboxController::DoPreconnect(const AutocompleteMatch& match) { 207 void OmniboxController::DoPreconnect(const AutocompleteMatch& match) {
225 if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) { 208 if (!match.destination_url.SchemeIs(extensions::kExtensionScheme)) {
226 // Warm up DNS Prefetch cache, or preconnect to a search service. 209 // Warm up DNS Prefetch cache, or preconnect to a search service.
227 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type, 210 UMA_HISTOGRAM_ENUMERATION("Autocomplete.MatchType", match.type,
228 AutocompleteMatchType::NUM_TYPES); 211 AutocompleteMatchType::NUM_TYPES);
229 if (profile_->GetNetworkPredictor()) { 212 if (profile_->GetNetworkPredictor()) {
230 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( 213 profile_->GetNetworkPredictor()->AnticipateOmniboxUrl(
231 match.destination_url, 214 match.destination_url,
232 AutocompleteActionPredictor::IsPreconnectable(match)); 215 predictors::AutocompleteActionPredictor::IsPreconnectable(match));
233 } 216 }
234 // We could prefetch the alternate nav URL, if any, but because there 217 // We could prefetch the alternate nav URL, if any, but because there
235 // can be many of these as a user types an initial series of characters, 218 // can be many of these as a user types an initial series of characters,
236 // the OS DNS cache could suffer eviction problems for minimal gain. 219 // the OS DNS cache could suffer eviction problems for minimal gain.
237 } 220 }
238 } 221 }
239 222
240 void OmniboxController::OnPopupBoundsChanged(const gfx::Rect& bounds) { 223 void OmniboxController::OnPopupBoundsChanged(const gfx::Rect& bounds) {
241 InstantController* instant_controller = GetInstantController(); 224 InstantController* instant_controller = GetInstantController();
242 if (instant_controller) 225 if (instant_controller)
(...skipping 21 matching lines...) Expand all
264 } 247 }
265 248
266 InstantController* OmniboxController::GetInstantController() const { 249 InstantController* OmniboxController::GetInstantController() const {
267 return omnibox_edit_model_->GetInstantController(); 250 return omnibox_edit_model_->GetInstantController();
268 } 251 }
269 252
270 void OmniboxController::CreateAndSetInstantMatch( 253 void OmniboxController::CreateAndSetInstantMatch(
271 string16 query_string, 254 string16 query_string,
272 string16 input_text, 255 string16 input_text,
273 AutocompleteMatchType::Type match_type) { 256 AutocompleteMatchType::Type match_type) {
274 string16 keyword = GetDefaultSearchProviderKeyword(profile_); 257 TemplateURLService* template_url_service =
275 if (keyword.empty()) 258 TemplateURLServiceFactory::GetForProfile(profile_);
276 return; // CreateSearchSuggestion needs a keyword. 259 if (!template_url_service)
260 return;
261
262 TemplateURL* template_url =
263 template_url_service->GetDefaultSearchProvider();
264 if (!template_url)
265 return;
277 266
278 current_match_ = SearchProvider::CreateSearchSuggestion( 267 current_match_ = SearchProvider::CreateSearchSuggestion(
279 profile_, NULL, AutocompleteInput(), query_string, input_text, 0, 268 NULL, 0, match_type, template_url, query_string, input_text,
280 match_type, 0, false, keyword, -1); 269 AutocompleteInput(), false, 0, -1);
281 } 270 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/util.cc ('k') | chrome/browser/ui/omnibox/omnibox_edit_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698