| OLD | NEW |
| 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 Loading... |
| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 prevent_search_history_inlining_( | 258 prevent_search_history_inlining_( |
| 256 OmniboxFieldTrial::SearchHistoryPreventInlining()), | 259 OmniboxFieldTrial::SearchHistoryPreventInlining()), |
| 257 disable_search_history_( | 260 disable_search_history_( |
| 258 OmniboxFieldTrial::SearchHistoryDisable()) { | 261 OmniboxFieldTrial::SearchHistoryDisable()) { |
| 259 } | 262 } |
| 260 | 263 |
| 261 // static | 264 // static |
| 262 AutocompleteMatch SearchProvider::CreateSearchSuggestion( | 265 AutocompleteMatch SearchProvider::CreateSearchSuggestion( |
| 263 AutocompleteProvider* autocomplete_provider, | 266 AutocompleteProvider* autocomplete_provider, |
| 264 int relevance, | 267 int relevance, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 new_entry.mutable_field_trial_triggered_in_session()->Add( | 369 new_entry.mutable_field_trial_triggered_in_session()->Add( |
| 367 field_trial_hashes[i]); | 370 field_trial_hashes[i]); |
| 368 } | 371 } |
| 369 } | 372 } |
| 370 } | 373 } |
| 371 | 374 |
| 372 void SearchProvider::ResetSession() { | 375 void SearchProvider::ResetSession() { |
| 373 field_trial_triggered_in_session_ = false; | 376 field_trial_triggered_in_session_ = false; |
| 374 } | 377 } |
| 375 | 378 |
| 376 void SearchProvider::SetOmniboxStartMargin(int omnibox_start_margin) { | |
| 377 omnibox_start_margin_ = omnibox_start_margin; | |
| 378 } | |
| 379 | |
| 380 SearchProvider::~SearchProvider() { | 379 SearchProvider::~SearchProvider() { |
| 381 } | 380 } |
| 382 | 381 |
| 383 // static | 382 // static |
| 384 void SearchProvider::RemoveStaleResults(const string16& input, | 383 void SearchProvider::RemoveStaleResults(const string16& input, |
| 385 int verbatim_relevance, | 384 int verbatim_relevance, |
| 386 SuggestResults* suggest_results, | 385 SuggestResults* suggest_results, |
| 387 NavigationResults* navigation_results) { | 386 NavigationResults* navigation_results) { |
| 388 DCHECK_GE(verbatim_relevance, 0); | 387 DCHECK_GE(verbatim_relevance, 0); |
| 389 // Keep pointers to the head of (the highest scoring elements of) | 388 // Keep pointers to the head of (the highest scoring elements of) |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 } | 1372 } |
| 1374 | 1373 |
| 1375 void SearchProvider::AddMatchToMap(const string16& query_string, | 1374 void SearchProvider::AddMatchToMap(const string16& query_string, |
| 1376 const string16& input_text, | 1375 const string16& input_text, |
| 1377 int relevance, | 1376 int relevance, |
| 1378 bool relevance_from_server, | 1377 bool relevance_from_server, |
| 1379 AutocompleteMatch::Type type, | 1378 AutocompleteMatch::Type type, |
| 1380 int accepted_suggestion, | 1379 int accepted_suggestion, |
| 1381 bool is_keyword, | 1380 bool is_keyword, |
| 1382 MatchMap* map) { | 1381 MatchMap* map) { |
| 1382 int omnibox_start_margin = chrome::kDisableStartMargin; |
| 1383 if (chrome::IsInstantExtendedAPIEnabled()) { |
| 1384 Browser* browser = |
| 1385 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); |
| 1386 if (browser && browser->instant_controller() && |
| 1387 browser->instant_controller()->instant()) { |
| 1388 omnibox_start_margin = |
| 1389 browser->instant_controller()->instant()->GetOmniboxBounds().x(); |
| 1390 } |
| 1391 } |
| 1392 |
| 1383 const TemplateURL* template_url = is_keyword ? | 1393 const TemplateURL* template_url = is_keyword ? |
| 1384 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); | 1394 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); |
| 1385 AutocompleteMatch match = CreateSearchSuggestion(this, relevance, type, | 1395 AutocompleteMatch match = CreateSearchSuggestion(this, relevance, type, |
| 1386 template_url, query_string, input_text, input_, is_keyword, | 1396 template_url, query_string, input_text, input_, is_keyword, |
| 1387 accepted_suggestion, omnibox_start_margin_, | 1397 accepted_suggestion, omnibox_start_margin, |
| 1388 !is_keyword || providers_.default_provider().empty()); | 1398 !is_keyword || providers_.default_provider().empty()); |
| 1389 if (!match.destination_url.is_valid()) | 1399 if (!match.destination_url.is_valid()) |
| 1390 return; | 1400 return; |
| 1391 match.RecordAdditionalInfo(kRelevanceFromServerKey, | 1401 match.RecordAdditionalInfo(kRelevanceFromServerKey, |
| 1392 relevance_from_server ? kTrue : kFalse); | 1402 relevance_from_server ? kTrue : kFalse); |
| 1393 | 1403 |
| 1394 // Try to add |match| to |map|. If a match for |query_string| is already in | 1404 // Try to add |match| to |map|. If a match for |query_string| is already in |
| 1395 // |map|, replace it if |match| is more relevant. | 1405 // |map|, replace it if |match| is more relevant. |
| 1396 // NOTE: Keep this ToLower() call in sync with url_database.cc. | 1406 // NOTE: Keep this ToLower() call in sync with url_database.cc. |
| 1397 const std::pair<MatchMap::iterator, bool> i( | 1407 const std::pair<MatchMap::iterator, bool> i( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 it->set_relevance(max_query_relevance); | 1524 it->set_relevance(max_query_relevance); |
| 1515 it->set_relevance_from_server(relevance_from_server); | 1525 it->set_relevance_from_server(relevance_from_server); |
| 1516 } | 1526 } |
| 1517 } | 1527 } |
| 1518 | 1528 |
| 1519 void SearchProvider::UpdateDone() { | 1529 void SearchProvider::UpdateDone() { |
| 1520 // We're done when the timer isn't running, there are no suggest queries | 1530 // We're done when the timer isn't running, there are no suggest queries |
| 1521 // pending, and we're not waiting on Instant. | 1531 // pending, and we're not waiting on Instant. |
| 1522 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1532 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
| 1523 } | 1533 } |
| OLD | NEW |