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

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

Issue 976423002: Remove ScoreHistoryMatch::Builder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cpplint
Patch Set: Address comments Created 5 years, 9 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 (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_quick_provider.h" 5 #include "chrome/browser/autocomplete/history_quick_provider.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/i18n/break_iterator.h" 11 #include "base/i18n/break_iterator.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
21 #include "chrome/browser/autocomplete/history_url_provider.h" 21 #include "chrome/browser/autocomplete/history_url_provider.h"
22 #include "chrome/browser/autocomplete/in_memory_url_index.h" 22 #include "chrome/browser/autocomplete/in_memory_url_index.h"
23 #include "chrome/browser/autocomplete/in_memory_url_index_types.h" 23 #include "chrome/browser/autocomplete/in_memory_url_index_types.h"
24 #include "chrome/browser/autocomplete/scored_history_match_builder_impl.h"
25 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 24 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
26 #include "chrome/browser/history/history_service_factory.h" 25 #include "chrome/browser/history/history_service_factory.h"
27 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/search_engines/template_url_service_factory.h" 27 #include "chrome/browser/search_engines/template_url_service_factory.h"
29 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
32 #include "components/bookmarks/browser/bookmark_model.h" 31 #include "components/bookmarks/browser/bookmark_model.h"
33 #include "components/history/core/browser/history_database.h" 32 #include "components/history/core/browser/history_database.h"
34 #include "components/history/core/browser/history_service.h" 33 #include "components/history/core/browser/history_service.h"
35 #include "components/metrics/proto/omnibox_input_type.pb.h" 34 #include "components/metrics/proto/omnibox_input_type.pb.h"
36 #include "components/omnibox/autocomplete_match_type.h" 35 #include "components/omnibox/autocomplete_match_type.h"
37 #include "components/omnibox/autocomplete_result.h" 36 #include "components/omnibox/autocomplete_result.h"
38 #include "components/omnibox/omnibox_field_trial.h" 37 #include "components/omnibox/omnibox_field_trial.h"
39 #include "components/search_engines/template_url.h" 38 #include "components/search_engines/template_url.h"
40 #include "components/search_engines/template_url_service.h" 39 #include "components/search_engines/template_url_service.h"
41 #include "content/public/browser/notification_source.h" 40 #include "content/public/browser/notification_source.h"
42 #include "content/public/browser/notification_types.h" 41 #include "content/public/browser/notification_types.h"
43 #include "net/base/escape.h" 42 #include "net/base/escape.h"
44 #include "net/base/net_util.h" 43 #include "net/base/net_util.h"
45 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 44 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
46 #include "url/url_parse.h" 45 #include "url/url_parse.h"
47 #include "url/url_util.h" 46 #include "url/url_util.h"
48 47
49 namespace {
50
51 // Returns whether |url| is bookmarked in |bookmark_model| (which can be null
52 // during testing). Used for ScoredHistoryMatchBuilderImpl.
53 bool IsBookmarked(bookmarks::BookmarkModel* bookmark_model, const GURL& url) {
54 return bookmark_model && bookmark_model->IsBookmarked(url);
55 }
56
57 } // namespace
58
59 bool HistoryQuickProvider::disabled_ = false; 48 bool HistoryQuickProvider::disabled_ = false;
60 49
61 HistoryQuickProvider::HistoryQuickProvider( 50 HistoryQuickProvider::HistoryQuickProvider(
62 Profile* profile, 51 Profile* profile,
63 InMemoryURLIndex* in_memory_url_index) 52 InMemoryURLIndex* in_memory_url_index)
64 : HistoryProvider(profile, AutocompleteProvider::TYPE_HISTORY_QUICK), 53 : HistoryProvider(profile, AutocompleteProvider::TYPE_HISTORY_QUICK),
65 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), 54 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)),
66 in_memory_url_index_(in_memory_url_index) { 55 in_memory_url_index_(in_memory_url_index) {
67 } 56 }
68 57
(...skipping 21 matching lines...) Expand all
90 base::TimeTicks end_time = base::TimeTicks::Now(); 79 base::TimeTicks end_time = base::TimeTicks::Now();
91 std::string name = "HistoryQuickProvider.QueryIndexTime." + 80 std::string name = "HistoryQuickProvider.QueryIndexTime." +
92 base::IntToString(input.text().length()); 81 base::IntToString(input.text().length());
93 base::HistogramBase* counter = base::Histogram::FactoryGet( 82 base::HistogramBase* counter = base::Histogram::FactoryGet(
94 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); 83 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag);
95 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); 84 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds()));
96 } 85 }
97 } 86 }
98 } 87 }
99 88
100 HistoryQuickProvider::~HistoryQuickProvider() {} 89 HistoryQuickProvider::~HistoryQuickProvider() {
90 }
101 91
102 void HistoryQuickProvider::DoAutocomplete() { 92 void HistoryQuickProvider::DoAutocomplete() {
103 // Get the matching URLs from the DB. 93 // Get the matching URLs from the DB.
104 ScoredHistoryMatches matches; 94 ScoredHistoryMatches matches = in_memory_url_index_->HistoryItemsForTerms(
105 { 95 autocomplete_input_.text(), autocomplete_input_.cursor_position(),
106 ScoredHistoryMatchBuilderImpl builder(base::Bind( 96 AutocompleteProvider::kMaxMatches);
107 &IsBookmarked,
108 base::Unretained(BookmarkModelFactory::GetForProfile(profile_))));
109 matches = in_memory_url_index_->HistoryItemsForTerms(
110 autocomplete_input_.text(), autocomplete_input_.cursor_position(),
111 AutocompleteProvider::kMaxMatches, builder);
112 }
113 if (matches.empty()) 97 if (matches.empty())
114 return; 98 return;
115 99
116 // Figure out if HistoryURL provider has a URL-what-you-typed match 100 // Figure out if HistoryURL provider has a URL-what-you-typed match
117 // that ought to go first and what its score will be. 101 // that ought to go first and what its score will be.
118 bool will_have_url_what_you_typed_match_first = false; 102 bool will_have_url_what_you_typed_match_first = false;
119 int url_what_you_typed_match_score = -1; // undefined 103 int url_what_you_typed_match_score = -1; // undefined
120 // These are necessary (but not sufficient) conditions for the omnibox 104 // These are necessary (but not sufficient) conditions for the omnibox
121 // input to be a URL-what-you-typed match. The username test checks that 105 // input to be a URL-what-you-typed match. The username test checks that
122 // either the username does not exist (a regular URL such as http://site/) 106 // either the username does not exist (a regular URL such as http://site/)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 match.description = info.title(); 280 match.description = info.title();
297 match.description_class = SpansFromTermMatch( 281 match.description_class = SpansFromTermMatch(
298 history_match.title_matches, match.description.length(), false); 282 history_match.title_matches, match.description.length(), false);
299 283
300 match.RecordAdditionalInfo("typed count", info.typed_count()); 284 match.RecordAdditionalInfo("typed count", info.typed_count());
301 match.RecordAdditionalInfo("visit count", info.visit_count()); 285 match.RecordAdditionalInfo("visit count", info.visit_count());
302 match.RecordAdditionalInfo("last visit", info.last_visit()); 286 match.RecordAdditionalInfo("last visit", info.last_visit());
303 287
304 return match; 288 return match;
305 } 289 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/history_url_provider.cc » ('j') | chrome/browser/autocomplete/scored_history_match.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698