Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 void HistoryContentsProvider::Stop() { | 144 void HistoryContentsProvider::Stop() { |
| 145 done_ = true; | 145 done_ = true; |
| 146 request_consumer_.CancelAllRequests(); | 146 request_consumer_.CancelAllRequests(); |
| 147 | 147 |
| 148 // Clear the results. We swap in an empty one as the easy way to clear it. | 148 // Clear the results. We swap in an empty one as the easy way to clear it. |
| 149 history::QueryResults empty_results; | 149 history::QueryResults empty_results; |
| 150 results_.Swap(&empty_results); | 150 results_.Swap(&empty_results); |
| 151 have_results_ = false; | 151 have_results_ = false; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void HistoryContentsProvider::DeleteMatch(const AutocompleteMatch& match) { | |
| 155 DCHECK(done_); | |
| 156 DCHECK(match.deletable); | |
| 157 DCHECK(profile_); | |
| 158 | |
| 159 // Delete the match from the history DB. | |
| 160 HistoryService* const history_service = | |
| 161 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | |
| 162 | |
| 163 GURL selected_url(match.destination_url); | |
| 164 if (!history_service || !selected_url.is_valid()) { | |
|
brettw
2010/12/15 22:24:11
This code is copied and pasted from the HistoryURL
msw
2010/12/16 01:38:26
How about using base class HistoryProvider?
| |
| 165 NOTREACHED() << "Can't delete requested URL"; | |
| 166 return; | |
| 167 } | |
| 168 history_service->DeleteURL(selected_url); | |
| 169 | |
| 170 // Delete the match from the current set of matches. | |
| 171 bool found = false; | |
| 172 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | |
| 173 if (i->destination_url == match.destination_url && i->type == match.type) { | |
| 174 found = true; | |
| 175 matches_.erase(i); | |
| 176 break; | |
| 177 } | |
| 178 } | |
| 179 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; | |
| 180 | |
| 181 listener_->OnProviderUpdate(true); | |
| 182 } | |
| 183 | |
| 154 HistoryContentsProvider::~HistoryContentsProvider() { | 184 HistoryContentsProvider::~HistoryContentsProvider() { |
| 155 } | 185 } |
| 156 | 186 |
| 157 void HistoryContentsProvider::QueryComplete(HistoryService::Handle handle, | 187 void HistoryContentsProvider::QueryComplete(HistoryService::Handle handle, |
| 158 history::QueryResults* results) { | 188 history::QueryResults* results) { |
| 159 results_.AppendResultsBySwapping(results, true); | 189 results_.AppendResultsBySwapping(results, true); |
| 160 have_results_ = true; | 190 have_results_ = true; |
| 161 ConvertResults(); | 191 ConvertResults(); |
| 162 | 192 |
| 163 done_ = true; | 193 done_ = true; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 245 |
| 216 static bool MatchInTitle(const history::URLResult& result) { | 246 static bool MatchInTitle(const history::URLResult& result) { |
| 217 return !result.title_match_positions().empty(); | 247 return !result.title_match_positions().empty(); |
| 218 } | 248 } |
| 219 | 249 |
| 220 AutocompleteMatch HistoryContentsProvider::ResultToMatch( | 250 AutocompleteMatch HistoryContentsProvider::ResultToMatch( |
| 221 const history::URLResult& result, | 251 const history::URLResult& result, |
| 222 int score) { | 252 int score) { |
| 223 // TODO(sky): if matched title highlight matching words in title. | 253 // TODO(sky): if matched title highlight matching words in title. |
| 224 // Also show star in popup. | 254 // Also show star in popup. |
| 225 AutocompleteMatch match(this, score, false, MatchInTitle(result) ? | 255 AutocompleteMatch match(this, score, true, MatchInTitle(result) ? |
| 226 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); | 256 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); |
| 227 match.contents = StringForURLDisplay(result.url(), true, trim_http_); | 257 match.contents = StringForURLDisplay(result.url(), true, trim_http_); |
| 228 match.fill_into_edit = | 258 match.fill_into_edit = |
| 229 AutocompleteInput::FormattedStringWithEquivalentMeaning(result.url(), | 259 AutocompleteInput::FormattedStringWithEquivalentMeaning(result.url(), |
| 230 match.contents); | 260 match.contents); |
| 231 match.destination_url = result.url(); | 261 match.destination_url = result.url(); |
| 232 match.contents_class.push_back( | 262 match.contents_class.push_back( |
| 233 ACMatchClassification(0, ACMatchClassification::URL)); | 263 ACMatchClassification(0, ACMatchClassification::URL)); |
| 234 match.description = UTF16ToWide(result.title()); | 264 match.description = UTF16ToWide(result.title()); |
| 235 match.starred = | 265 match.starred = |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", | 321 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", |
| 292 TimeTicks::Now() - start_time); | 322 TimeTicks::Now() - start_time); |
| 293 } | 323 } |
| 294 | 324 |
| 295 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( | 325 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( |
| 296 const bookmark_utils::TitleMatch& match) { | 326 const bookmark_utils::TitleMatch& match) { |
| 297 history::URLResult url_result(match.node->GetURL(), match.match_positions); | 327 history::URLResult url_result(match.node->GetURL(), match.match_positions); |
| 298 url_result.set_title(match.node->GetTitle()); | 328 url_result.set_title(match.node->GetTitle()); |
| 299 results_.AppendURLBySwapping(&url_result); | 329 results_.AppendURLBySwapping(&url_result); |
| 300 } | 330 } |
| OLD | NEW |