| 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_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/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 RunAutocompletePasses(input, true); | 140 RunAutocompletePasses(input, true); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void HistoryURLProvider::Stop() { | 143 void HistoryURLProvider::Stop() { |
| 144 done_ = true; | 144 done_ = true; |
| 145 | 145 |
| 146 if (params_) | 146 if (params_) |
| 147 params_->cancel = true; | 147 params_->cancel = true; |
| 148 } | 148 } |
| 149 | 149 |
| 150 void HistoryURLProvider::DeleteMatch(const AutocompleteMatch& match) { | |
| 151 DCHECK(done_); | |
| 152 | |
| 153 // Delete the match from the history DB. | |
| 154 HistoryService* const history_service = | |
| 155 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | |
| 156 GURL selected_url(match.destination_url); | |
| 157 if (!history_service || !selected_url.is_valid()) { | |
| 158 NOTREACHED() << "Can't delete requested URL"; | |
| 159 return; | |
| 160 } | |
| 161 history_service->DeleteURL(selected_url); | |
| 162 | |
| 163 // Delete the match from the current set of matches. | |
| 164 bool found = false; | |
| 165 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | |
| 166 if (i->destination_url == match.destination_url) { | |
| 167 found = true; | |
| 168 if (i->is_history_what_you_typed_match) { | |
| 169 // We can't get rid of the What You Typed match, but we can make it | |
| 170 // look like it has no backing data. | |
| 171 i->deletable = false; | |
| 172 i->description.clear(); | |
| 173 i->description_class.clear(); | |
| 174 } else { | |
| 175 matches_.erase(i); | |
| 176 } | |
| 177 break; | |
| 178 } | |
| 179 } | |
| 180 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; | |
| 181 listener_->OnProviderUpdate(true); | |
| 182 } | |
| 183 | |
| 184 // Called on the history thread. | 150 // Called on the history thread. |
| 185 void HistoryURLProvider::ExecuteWithDB(history::HistoryBackend* backend, | 151 void HistoryURLProvider::ExecuteWithDB(history::HistoryBackend* backend, |
| 186 history::URLDatabase* db, | 152 history::URLDatabase* db, |
| 187 HistoryURLProviderParams* params) { | 153 HistoryURLProviderParams* params) { |
| 188 // We may get called with a NULL database if it couldn't be properly | 154 // We may get called with a NULL database if it couldn't be properly |
| 189 // initialized. | 155 // initialized. |
| 190 if (!db) { | 156 if (!db) { |
| 191 params->failed = true; | 157 params->failed = true; |
| 192 } else if (!params->cancel) { | 158 } else if (!params->cancel) { |
| 193 TimeTicks beginning_time = TimeTicks::Now(); | 159 TimeTicks beginning_time = TimeTicks::Now(); |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 &match.contents_class); | 802 &match.contents_class); |
| 837 } | 803 } |
| 838 match.description = UTF16ToWide(info.title()); | 804 match.description = UTF16ToWide(info.title()); |
| 839 AutocompleteMatch::ClassifyMatchInString(params->input.text(), | 805 AutocompleteMatch::ClassifyMatchInString(params->input.text(), |
| 840 UTF16ToWide(info.title()), | 806 UTF16ToWide(info.title()), |
| 841 ACMatchClassification::NONE, | 807 ACMatchClassification::NONE, |
| 842 &match.description_class); | 808 &match.description_class); |
| 843 | 809 |
| 844 return match; | 810 return match; |
| 845 } | 811 } |
| OLD | NEW |