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_contents_provider.h" | 5 #include "chrome/browser/autocomplete/history_contents_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 void HistoryContentsProvider::Start(const AutocompleteInput& input, | 66 void HistoryContentsProvider::Start(const AutocompleteInput& input, |
67 bool minimal_changes) { | 67 bool minimal_changes) { |
68 matches_.clear(); | 68 matches_.clear(); |
69 | 69 |
70 if (input.text().empty() || (input.type() == AutocompleteInput::INVALID) || | 70 if (input.text().empty() || (input.type() == AutocompleteInput::INVALID) || |
71 (input.type() == AutocompleteInput::FORCED_QUERY) || | 71 (input.type() == AutocompleteInput::FORCED_QUERY) || |
72 !profile_ || | 72 !profile_ || |
73 // The history service or bookmark bar model must exist. | 73 // The history service or bookmark bar model must exist. |
74 !(HistoryServiceFactory::GetForProfile(profile_, | 74 !(HistoryServiceFactory::GetForProfile(profile_, |
75 Profile::EXPLICIT_ACCESS) || | 75 Profile::EXPLICIT_ACCESS).get() || |
76 BookmarkModelFactory::GetForProfile(profile_))) { | 76 BookmarkModelFactory::GetForProfile(profile_))) { |
77 Stop(false); | 77 Stop(false); |
78 return; | 78 return; |
79 } | 79 } |
80 | 80 |
81 // TODO(pkasting): http://b/888148 We disallow URL input and "URL-like" input | 81 // TODO(pkasting): http://b/888148 We disallow URL input and "URL-like" input |
82 // (REQUESTED_URL or UNKNOWN with dots) because we get poor results for it, | 82 // (REQUESTED_URL or UNKNOWN with dots) because we get poor results for it, |
83 // but we could get better results if we did better tokenizing instead. | 83 // but we could get better results if we did better tokenizing instead. |
84 if ((input.type() == AutocompleteInput::URL) || | 84 if ((input.type() == AutocompleteInput::URL) || |
85 (((input.type() == AutocompleteInput::REQUESTED_URL) || | 85 (((input.type() == AutocompleteInput::REQUESTED_URL) || |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 // Querying bookmarks is synchronous, so we always do it. | 130 // Querying bookmarks is synchronous, so we always do it. |
131 QueryBookmarks(input); | 131 QueryBookmarks(input); |
132 | 132 |
133 // Convert the bookmark results. | 133 // Convert the bookmark results. |
134 ConvertResults(); | 134 ConvertResults(); |
135 | 135 |
136 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { | 136 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { |
137 HistoryService* history = | 137 HistoryService* history = |
138 HistoryServiceFactory::GetForProfile(profile_, | 138 HistoryServiceFactory::GetForProfile(profile_, |
139 Profile::EXPLICIT_ACCESS); | 139 Profile::EXPLICIT_ACCESS).get(); |
140 if (history) { | 140 if (history) { |
141 done_ = false; | 141 done_ = false; |
142 | 142 |
143 history::QueryOptions options; | 143 history::QueryOptions options; |
144 options.body_only = body_only_; | 144 options.body_only = body_only_; |
145 options.SetRecentDayRange(kDaysToSearch); | 145 options.SetRecentDayRange(kDaysToSearch); |
146 options.max_count = kMaxMatches; | 146 options.max_count = kMaxMatches; |
147 history->QueryHistory(input.text(), options, | 147 history->QueryHistory(input.text(), options, |
148 &request_consumer_, | 148 &request_consumer_, |
149 base::Bind(&HistoryContentsProvider::QueryComplete, | 149 base::Bind(&HistoryContentsProvider::QueryComplete, |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", | 283 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", |
284 TimeTicks::Now() - start_time); | 284 TimeTicks::Now() - start_time); |
285 } | 285 } |
286 | 286 |
287 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( | 287 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( |
288 const bookmark_utils::TitleMatch& match) { | 288 const bookmark_utils::TitleMatch& match) { |
289 history::URLResult url_result(match.node->url(), match.match_positions); | 289 history::URLResult url_result(match.node->url(), match.match_positions); |
290 url_result.set_title(match.node->GetTitle()); | 290 url_result.set_title(match.node->GetTitle()); |
291 results_.AppendURLBySwapping(&url_result); | 291 results_.AppendURLBySwapping(&url_result); |
292 } | 292 } |
OLD | NEW |