OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 18 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
19 #include "chrome/browser/autocomplete/scored_history_match.h" | 19 #include "chrome/browser/autocomplete/scored_history_match.h" |
20 #include "chrome/browser/history/history_service_factory.h" | |
21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 21 #include "chrome/browser/search_engines/template_url_service_factory.h" |
23 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 22 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
24 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
27 #include "components/bookmarks/browser/bookmark_utils.h" | 26 #include "components/bookmarks/browser/bookmark_utils.h" |
28 #include "components/history/core/browser/history_backend.h" | 27 #include "components/history/core/browser/history_backend.h" |
29 #include "components/history/core/browser/history_database.h" | 28 #include "components/history/core/browser/history_database.h" |
30 #include "components/history/core/browser/history_service.h" | 29 #include "components/history/core/browser/history_service.h" |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 promote_type(NEITHER), | 463 promote_type(NEITHER), |
465 languages(languages), | 464 languages(languages), |
466 default_search_provider(default_search_provider ? | 465 default_search_provider(default_search_provider ? |
467 new TemplateURL(default_search_provider->data()) : NULL), | 466 new TemplateURL(default_search_provider->data()) : NULL), |
468 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { | 467 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { |
469 } | 468 } |
470 | 469 |
471 HistoryURLProviderParams::~HistoryURLProviderParams() { | 470 HistoryURLProviderParams::~HistoryURLProviderParams() { |
472 } | 471 } |
473 | 472 |
474 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderListener* listener, | 473 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, |
474 AutocompleteProviderListener* listener, | |
475 Profile* profile) | 475 Profile* profile) |
476 : HistoryProvider(profile, AutocompleteProvider::TYPE_HISTORY_URL), | 476 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_URL, client), |
477 profile_(profile), | |
477 listener_(listener), | 478 listener_(listener), |
478 params_(NULL) { | 479 params_(NULL) { |
479 // Initialize HUP scoring params based on the current experiment. | 480 // Initialize HUP scoring params based on the current experiment. |
480 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); | 481 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); |
481 } | 482 } |
482 | 483 |
483 void HistoryURLProvider::Start(const AutocompleteInput& input, | 484 void HistoryURLProvider::Start(const AutocompleteInput& input, |
484 bool minimal_changes, | 485 bool minimal_changes, |
485 bool called_due_to_focus) { | 486 bool called_due_to_focus) { |
486 // NOTE: We could try hard to do less work in the |minimal_changes| case | 487 // NOTE: We could try hard to do less work in the |minimal_changes| case |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 what_you_typed_match.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); | 520 what_you_typed_match.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); |
520 | 521 |
521 // Add the WYT match as a fallback in case we can't get the history service or | 522 // Add the WYT match as a fallback in case we can't get the history service or |
522 // URL DB; otherwise, we'll replace this match lower down. Don't do this for | 523 // URL DB; otherwise, we'll replace this match lower down. Don't do this for |
523 // queries, though -- while we can sometimes mark up a match for them, it's | 524 // queries, though -- while we can sometimes mark up a match for them, it's |
524 // not what the user wants, and just adds noise. | 525 // not what the user wants, and just adds noise. |
525 if (fixed_up_input.type() != metrics::OmniboxInputType::QUERY) | 526 if (fixed_up_input.type() != metrics::OmniboxInputType::QUERY) |
526 matches_.push_back(what_you_typed_match); | 527 matches_.push_back(what_you_typed_match); |
527 | 528 |
528 // We'll need the history service to run both passes, so try to obtain it. | 529 // We'll need the history service to run both passes, so try to obtain it. |
529 if (!profile_) | 530 if (!client()) |
Peter Kasting
2015/06/16 00:03:42
Can this ever be null?
blundell
2015/06/16 07:21:25
No. Removed.
| |
530 return; | 531 return; |
531 history::HistoryService* const history_service = | 532 history::HistoryService* const history_service = client()->HistoryService(); |
532 HistoryServiceFactory::GetForProfile(profile_, | |
533 ServiceAccessType::EXPLICIT_ACCESS); | |
534 if (!history_service) | 533 if (!history_service) |
535 return; | 534 return; |
536 | 535 |
537 // Get the default search provider and search terms data now since we have to | 536 // Get the default search provider and search terms data now since we have to |
538 // retrieve these on the UI thread, and the second pass runs on the history | 537 // retrieve these on the UI thread, and the second pass runs on the history |
539 // thread. |template_url_service| can be NULL when testing. | 538 // thread. |template_url_service| can be NULL when testing. |
540 TemplateURLService* template_url_service = | 539 TemplateURLService* template_url_service = |
541 TemplateURLServiceFactory::GetForProfile(profile_); | 540 TemplateURLServiceFactory::GetForProfile(profile_); |
542 TemplateURL* default_search_provider = template_url_service ? | 541 TemplateURL* default_search_provider = template_url_service ? |
543 template_url_service->GetDefaultSearchProvider() : NULL; | 542 template_url_service->GetDefaultSearchProvider() : NULL; |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1179 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1178 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
1180 match.contents.length(), ACMatchClassification::URL, | 1179 match.contents.length(), ACMatchClassification::URL, |
1181 &match.contents_class); | 1180 &match.contents_class); |
1182 } | 1181 } |
1183 match.description = info.title(); | 1182 match.description = info.title(); |
1184 match.description_class = | 1183 match.description_class = |
1185 ClassifyDescription(params.input.text(), match.description); | 1184 ClassifyDescription(params.input.text(), match.description); |
1186 RecordAdditionalInfoFromUrlRow(info, &match); | 1185 RecordAdditionalInfoFromUrlRow(info, &match); |
1187 return match; | 1186 return match; |
1188 } | 1187 } |
OLD | NEW |