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

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: Rebase and 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 17 matching lines...) Expand all
28 #include "chrome/browser/history/history_service.h" 28 #include "chrome/browser/history/history_service.h"
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/template_url_prepopulate_data.h" 35 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
36 #include "chrome/browser/search_engines/template_url_service.h" 36 #include "chrome/browser/search_engines/template_url_service.h"
37 #include "chrome/browser/search_engines/template_url_service_factory.h" 37 #include "chrome/browser/search_engines/template_url_service_factory.h"
38 #include "chrome/browser/ui/browser.h"
39 #include "chrome/browser/ui/browser_finder.h"
40 #include "chrome/browser/ui/browser_instant_controller.h"
41 #include "chrome/browser/ui/search/instant_controller.h"
38 #include "chrome/common/net/url_fixer_upper.h" 42 #include "chrome/common/net/url_fixer_upper.h"
39 #include "chrome/common/pref_names.h" 43 #include "chrome/common/pref_names.h"
40 #include "chrome/common/url_constants.h" 44 #include "chrome/common/url_constants.h"
41 #include "grit/generated_resources.h" 45 #include "grit/generated_resources.h"
42 #include "net/base/escape.h" 46 #include "net/base/escape.h"
43 #include "net/base/load_flags.h" 47 #include "net/base/load_flags.h"
44 #include "net/base/net_util.h" 48 #include "net/base/net_util.h"
45 #include "net/http/http_request_headers.h" 49 #include "net/http/http_request_headers.h"
46 #include "net/http/http_response_headers.h" 50 #include "net/http/http_response_headers.h"
47 #include "net/url_request/url_fetcher.h" 51 #include "net/url_request/url_fetcher.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 const char SearchProvider::kTrue[] = "true"; 246 const char SearchProvider::kTrue[] = "true";
243 const char SearchProvider::kFalse[] = "false"; 247 const char SearchProvider::kFalse[] = "false";
244 248
245 SearchProvider::SearchProvider(AutocompleteProviderListener* listener, 249 SearchProvider::SearchProvider(AutocompleteProviderListener* listener,
246 Profile* profile) 250 Profile* profile)
247 : AutocompleteProvider(listener, profile, 251 : AutocompleteProvider(listener, profile,
248 AutocompleteProvider::TYPE_SEARCH), 252 AutocompleteProvider::TYPE_SEARCH),
249 providers_(TemplateURLServiceFactory::GetForProfile(profile)), 253 providers_(TemplateURLServiceFactory::GetForProfile(profile)),
250 suggest_results_pending_(0), 254 suggest_results_pending_(0),
251 field_trial_triggered_(false), 255 field_trial_triggered_(false),
252 field_trial_triggered_in_session_(false), 256 field_trial_triggered_in_session_(false) {
253 omnibox_start_margin_(-1) {
254 } 257 }
255 258
256 // static 259 // static
257 AutocompleteMatch SearchProvider::CreateSearchSuggestion( 260 AutocompleteMatch SearchProvider::CreateSearchSuggestion(
258 AutocompleteProvider* autocomplete_provider, 261 AutocompleteProvider* autocomplete_provider,
259 int relevance, 262 int relevance,
260 AutocompleteMatch::Type type, 263 AutocompleteMatch::Type type,
261 const TemplateURL* template_url, 264 const TemplateURL* template_url,
262 const string16& query_string, 265 const string16& query_string,
263 const string16& input_text, 266 const string16& input_text,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 new_entry.mutable_field_trial_triggered_in_session()->Add( 364 new_entry.mutable_field_trial_triggered_in_session()->Add(
362 field_trial_hashes[i]); 365 field_trial_hashes[i]);
363 } 366 }
364 } 367 }
365 } 368 }
366 369
367 void SearchProvider::ResetSession() { 370 void SearchProvider::ResetSession() {
368 field_trial_triggered_in_session_ = false; 371 field_trial_triggered_in_session_ = false;
369 } 372 }
370 373
371 void SearchProvider::SetOmniboxStartMargin(int omnibox_start_margin) {
372 omnibox_start_margin_ = omnibox_start_margin;
373 }
374
375 SearchProvider::~SearchProvider() { 374 SearchProvider::~SearchProvider() {
376 } 375 }
377 376
378 // static 377 // static
379 void SearchProvider::RemoveStaleResults(const string16& input, 378 void SearchProvider::RemoveStaleResults(const string16& input,
380 int verbatim_relevance, 379 int verbatim_relevance,
381 SuggestResults* suggest_results, 380 SuggestResults* suggest_results,
382 NavigationResults* navigation_results) { 381 NavigationResults* navigation_results) {
383 DCHECK_GE(verbatim_relevance, 0); 382 DCHECK_GE(verbatim_relevance, 0);
384 // Keep pointers to the head of (the highest scoring elements of) 383 // Keep pointers to the head of (the highest scoring elements of)
(...skipping 990 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 // On non-mobile, ask the instant controller for the appropriate start margin.
1385 // On mobile the start margin is unused, so leave the value as default there.
1386 int omnibox_start_margin = chrome::kDisableStartMargin;
1387 #if !defined(OS_ANDROID) && !defined(IOS)
pkl (ping after 24h if needed) 2013/08/14 13:25:16 iOS should be !defined(OS_IOS) Unfortunately, this
1388 if (chrome::IsInstantExtendedAPIEnabled()) {
1389 Browser* browser =
1390 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop());
1391 if (browser && browser->instant_controller() &&
1392 browser->instant_controller()->instant()) {
1393 omnibox_start_margin =
1394 browser->instant_controller()->instant()->omnibox_bounds().x();
1395 }
1396 }
1397 #endif // !defined(OS_ANDROID) && !defined(IOS)
1398
1385 const TemplateURL* template_url = is_keyword ? 1399 const TemplateURL* template_url = is_keyword ?
1386 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); 1400 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL();
1387 AutocompleteMatch match = CreateSearchSuggestion(this, relevance, type, 1401 AutocompleteMatch match = CreateSearchSuggestion(this, relevance, type,
1388 template_url, query_string, input_text, input_, is_keyword, 1402 template_url, query_string, input_text, input_, is_keyword,
1389 accepted_suggestion, omnibox_start_margin_, 1403 accepted_suggestion, omnibox_start_margin,
1390 !is_keyword || providers_.default_provider().empty()); 1404 !is_keyword || providers_.default_provider().empty());
1391 if (!match.destination_url.is_valid()) 1405 if (!match.destination_url.is_valid())
1392 return; 1406 return;
1393 match.RecordAdditionalInfo(kRelevanceFromServerKey, 1407 match.RecordAdditionalInfo(kRelevanceFromServerKey,
1394 relevance_from_server ? kTrue : kFalse); 1408 relevance_from_server ? kTrue : kFalse);
1395 1409
1396 // Try to add |match| to |map|. If a match for |query_string| is already in 1410 // Try to add |match| to |map|. If a match for |query_string| is already in
1397 // |map|, replace it if |match| is more relevant. 1411 // |map|, replace it if |match| is more relevant.
1398 // NOTE: Keep this ToLower() call in sync with url_database.cc. 1412 // NOTE: Keep this ToLower() call in sync with url_database.cc.
1399 const std::pair<MatchMap::iterator, bool> i( 1413 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); 1530 it->set_relevance(max_query_relevance);
1517 it->set_relevance_from_server(relevance_from_server); 1531 it->set_relevance_from_server(relevance_from_server);
1518 } 1532 }
1519 } 1533 }
1520 1534
1521 void SearchProvider::UpdateDone() { 1535 void SearchProvider::UpdateDone() {
1522 // We're done when the timer isn't running, there are no suggest queries 1536 // We're done when the timer isn't running, there are no suggest queries
1523 // pending, and we're not waiting on Instant. 1537 // pending, and we're not waiting on Instant.
1524 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); 1538 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
1525 } 1539 }
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