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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 21042013: Have SearchProvider look up the omnibox start margin directly. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Respond to comments. Created 7 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/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/browser/history/history_service_factory.h" 29 #include "chrome/browser/history/history_service_factory.h"
30 #include "chrome/browser/history/in_memory_database.h" 30 #include "chrome/browser/history/in_memory_database.h"
31 #include "chrome/browser/metrics/variations/variations_http_header_provider.h" 31 #include "chrome/browser/metrics/variations/variations_http_header_provider.h"
32 #include "chrome/browser/omnibox/omnibox_field_trial.h" 32 #include "chrome/browser/omnibox/omnibox_field_trial.h"
33 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/search/search.h" 34 #include "chrome/browser/search/search.h"
35 #include "chrome/browser/search_engines/search_engine_type.h" 35 #include "chrome/browser/search_engines/search_engine_type.h"
36 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 36 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
37 #include "chrome/browser/search_engines/template_url_service.h" 37 #include "chrome/browser/search_engines/template_url_service.h"
38 #include "chrome/browser/search_engines/template_url_service_factory.h" 38 #include "chrome/browser/search_engines/template_url_service_factory.h"
39 #include "chrome/browser/ui/browser.h"
40 #include "chrome/browser/ui/browser_finder.h"
41 #include "chrome/browser/ui/browser_instant_controller.h"
42 #include "chrome/browser/ui/search/instant_controller.h"
39 #include "chrome/common/net/url_fixer_upper.h" 43 #include "chrome/common/net/url_fixer_upper.h"
40 #include "chrome/common/pref_names.h" 44 #include "chrome/common/pref_names.h"
41 #include "chrome/common/url_constants.h" 45 #include "chrome/common/url_constants.h"
42 #include "grit/generated_resources.h" 46 #include "grit/generated_resources.h"
43 #include "net/base/escape.h" 47 #include "net/base/escape.h"
44 #include "net/base/load_flags.h" 48 #include "net/base/load_flags.h"
45 #include "net/base/net_util.h" 49 #include "net/base/net_util.h"
46 #include "net/http/http_request_headers.h" 50 #include "net/http/http_request_headers.h"
47 #include "net/http/http_response_headers.h" 51 #include "net/http/http_response_headers.h"
48 #include "net/url_request/url_fetcher.h" 52 #include "net/url_request/url_fetcher.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 const char SearchProvider::kTrue[] = "true"; 247 const char SearchProvider::kTrue[] = "true";
244 const char SearchProvider::kFalse[] = "false"; 248 const char SearchProvider::kFalse[] = "false";
245 249
246 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, 250 SearchProvider::SearchProvider(AutocompleteProviderListener* listener,
247 Profile* profile) 251 Profile* profile)
248 : AutocompleteProvider(listener, profile, 252 : AutocompleteProvider(listener, profile,
249 AutocompleteProvider::TYPE_SEARCH), 253 AutocompleteProvider::TYPE_SEARCH),
250 providers_(TemplateURLServiceFactory::GetForProfile(profile)), 254 providers_(TemplateURLServiceFactory::GetForProfile(profile)),
251 suggest_results_pending_(0), 255 suggest_results_pending_(0),
252 field_trial_triggered_(false), 256 field_trial_triggered_(false),
253 field_trial_triggered_in_session_(false), 257 field_trial_triggered_in_session_(false) {
254 omnibox_start_margin_(-1) {
255 } 258 }
256 259
257 // static 260 // static
258 AutocompleteMatch SearchProvider::CreateSearchSuggestion( 261 AutocompleteMatch SearchProvider::CreateSearchSuggestion(
259 AutocompleteProvider* autocomplete_provider, 262 AutocompleteProvider* autocomplete_provider,
260 int relevance, 263 int relevance,
261 AutocompleteMatch::Type type, 264 AutocompleteMatch::Type type,
262 const TemplateURL* template_url, 265 const TemplateURL* template_url,
263 const string16& query_string, 266 const string16& query_string,
264 const string16& input_text, 267 const string16& input_text,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 new_entry.mutable_field_trial_triggered_in_session()->Add( 365 new_entry.mutable_field_trial_triggered_in_session()->Add(
363 field_trial_hashes[i]); 366 field_trial_hashes[i]);
364 } 367 }
365 } 368 }
366 } 369 }
367 370
368 void SearchProvider::ResetSession() { 371 void SearchProvider::ResetSession() {
369 field_trial_triggered_in_session_ = false; 372 field_trial_triggered_in_session_ = false;
370 } 373 }
371 374
372 void SearchProvider::SetOmniboxStartMargin(int omnibox_start_margin) {
373 omnibox_start_margin_ = omnibox_start_margin;
374 }
375
376 SearchProvider::~SearchProvider() { 375 SearchProvider::~SearchProvider() {
377 } 376 }
378 377
379 // static 378 // static
380 void SearchProvider::RemoveStaleResults(const string16& input, 379 void SearchProvider::RemoveStaleResults(const string16& input,
381 int verbatim_relevance, 380 int verbatim_relevance,
382 SuggestResults* suggest_results, 381 SuggestResults* suggest_results,
383 NavigationResults* navigation_results) { 382 NavigationResults* navigation_results) {
384 DCHECK_GE(verbatim_relevance, 0); 383 DCHECK_GE(verbatim_relevance, 0);
385 // Keep pointers to the head of (the highest scoring elements of) 384 // Keep pointers to the head of (the highest scoring elements of)
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 } 1374 }
1376 1375
1377 void SearchProvider::AddMatchToMap(const string16& query_string, 1376 void SearchProvider::AddMatchToMap(const string16& query_string,
1378 const string16& input_text, 1377 const string16& input_text,
1379 int relevance, 1378 int relevance,
1380 bool relevance_from_server, 1379 bool relevance_from_server,
1381 AutocompleteMatch::Type type, 1380 AutocompleteMatch::Type type,
1382 int accepted_suggestion, 1381 int accepted_suggestion,
1383 bool is_keyword, 1382 bool is_keyword,
1384 MatchMap* map) { 1383 MatchMap* map) {
1384 int omnibox_start_margin = chrome::kDisableStartMargin;
1385 #if !defined(OS_ANDROID)
samarth 2013/08/07 16:19:07 nit: don't indent this line or the #endif.
samarth 2013/08/07 16:19:07 Do you need this because browser finder doesn't ex
jeremycho 2013/08/07 22:16:05 Done.
jeremycho 2013/08/07 22:16:05 Yeah, done.
1386 if (chrome::IsInstantExtendedAPIEnabled()) {
1387 Browser* browser =
1388 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop());
1389 if (browser && browser->instant_controller() &&
1390 browser->instant_controller()->instant()) {
1391 omnibox_start_margin =
1392 browser->instant_controller()->instant()->omnibox_bounds().x();
1393 }
1394 }
1395 #endif // !defined(OS_ANDROID)
1396
1385 const TemplateURL* template_url = is_keyword ? 1397 const TemplateURL* template_url = is_keyword ?
1386 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); 1398 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL();
1387 AutocompleteMatch match = CreateSearchSuggestion(this, relevance, type, 1399 AutocompleteMatch match = CreateSearchSuggestion(this, relevance, type,
1388 template_url, query_string, input_text, input_, is_keyword, 1400 template_url, query_string, input_text, input_, is_keyword,
1389 accepted_suggestion, omnibox_start_margin_, 1401 accepted_suggestion, omnibox_start_margin,
1390 !is_keyword || providers_.default_provider().empty()); 1402 !is_keyword || providers_.default_provider().empty());
1391 if (!match.destination_url.is_valid()) 1403 if (!match.destination_url.is_valid())
1392 return; 1404 return;
1393 match.RecordAdditionalInfo(kRelevanceFromServerKey, 1405 match.RecordAdditionalInfo(kRelevanceFromServerKey,
1394 relevance_from_server ? kTrue : kFalse); 1406 relevance_from_server ? kTrue : kFalse);
1395 1407
1396 // Try to add |match| to |map|. If a match for |query_string| is already in 1408 // Try to add |match| to |map|. If a match for |query_string| is already in
1397 // |map|, replace it if |match| is more relevant. 1409 // |map|, replace it if |match| is more relevant.
1398 // NOTE: Keep this ToLower() call in sync with url_database.cc. 1410 // NOTE: Keep this ToLower() call in sync with url_database.cc.
1399 const std::pair<MatchMap::iterator, bool> i( 1411 const std::pair<MatchMap::iterator, bool> i(
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 it->set_relevance(max_query_relevance); 1528 it->set_relevance(max_query_relevance);
1517 it->set_relevance_from_server(relevance_from_server); 1529 it->set_relevance_from_server(relevance_from_server);
1518 } 1530 }
1519 } 1531 }
1520 1532
1521 void SearchProvider::UpdateDone() { 1533 void SearchProvider::UpdateDone() {
1522 // We're done when the timer isn't running, there are no suggest queries 1534 // We're done when the timer isn't running, there are no suggest queries
1523 // pending, and we're not waiting on Instant. 1535 // pending, and we're not waiting on Instant.
1524 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); 1536 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
1525 } 1537 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.h ('k') | chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698