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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 Loading... | |
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 // browser_finder does not exist for Android. On IOS, start margin is not used. | |
Peter Kasting
2013/08/09 21:03:46
Nit: To avoid unusual comment indenting, how about
jeremycho
2013/08/09 23:55:09
Done.
| |
1386 #if !defined(OS_ANDROID) && !defined(IOS) | |
1387 if (chrome::IsInstantExtendedAPIEnabled()) { | |
1388 Browser* browser = | |
1389 chrome::FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()); | |
1390 if (browser && browser->instant_controller() && | |
1391 browser->instant_controller()->instant()) { | |
1392 omnibox_start_margin = | |
1393 browser->instant_controller()->instant()->omnibox_bounds().x(); | |
1394 } | |
1395 } | |
1396 #endif // !defined(OS_ANDROID) && !defined(IOS) | |
1397 | |
1385 const TemplateURL* template_url = is_keyword ? | 1398 const TemplateURL* template_url = is_keyword ? |
1386 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); | 1399 providers_.GetKeywordProviderURL() : providers_.GetDefaultProviderURL(); |
1387 AutocompleteMatch match = CreateSearchSuggestion(this, relevance, type, | 1400 AutocompleteMatch match = CreateSearchSuggestion(this, relevance, type, |
1388 template_url, query_string, input_text, input_, is_keyword, | 1401 template_url, query_string, input_text, input_, is_keyword, |
1389 accepted_suggestion, omnibox_start_margin_, | 1402 accepted_suggestion, omnibox_start_margin, |
1390 !is_keyword || providers_.default_provider().empty()); | 1403 !is_keyword || providers_.default_provider().empty()); |
1391 if (!match.destination_url.is_valid()) | 1404 if (!match.destination_url.is_valid()) |
1392 return; | 1405 return; |
1393 match.RecordAdditionalInfo(kRelevanceFromServerKey, | 1406 match.RecordAdditionalInfo(kRelevanceFromServerKey, |
1394 relevance_from_server ? kTrue : kFalse); | 1407 relevance_from_server ? kTrue : kFalse); |
1395 | 1408 |
1396 // Try to add |match| to |map|. If a match for |query_string| is already in | 1409 // Try to add |match| to |map|. If a match for |query_string| is already in |
1397 // |map|, replace it if |match| is more relevant. | 1410 // |map|, replace it if |match| is more relevant. |
1398 // NOTE: Keep this ToLower() call in sync with url_database.cc. | 1411 // NOTE: Keep this ToLower() call in sync with url_database.cc. |
1399 const std::pair<MatchMap::iterator, bool> i( | 1412 const std::pair<MatchMap::iterator, bool> i( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1516 it->set_relevance(max_query_relevance); | 1529 it->set_relevance(max_query_relevance); |
1517 it->set_relevance_from_server(relevance_from_server); | 1530 it->set_relevance_from_server(relevance_from_server); |
1518 } | 1531 } |
1519 } | 1532 } |
1520 | 1533 |
1521 void SearchProvider::UpdateDone() { | 1534 void SearchProvider::UpdateDone() { |
1522 // We're done when the timer isn't running, there are no suggest queries | 1535 // We're done when the timer isn't running, there are no suggest queries |
1523 // pending, and we're not waiting on Instant. | 1536 // pending, and we're not waiting on Instant. |
1524 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1537 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
1525 } | 1538 } |
OLD | NEW |