| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
| 8 | 8 |
| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { | 25 void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { |
| 26 DCHECK(done_); | 26 DCHECK(done_); |
| 27 DCHECK(profile_); | 27 DCHECK(profile_); |
| 28 DCHECK(match.deletable); | 28 DCHECK(match.deletable); |
| 29 | 29 |
| 30 HistoryService* const history_service = | 30 HistoryService* const history_service = |
| 31 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 31 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 32 | 32 |
| 33 // Delete the match from the history DB. | 33 // Delete the match from the history DB. |
| 34 DCHECK(history_service); | 34 GURL selected_url(match.destination_url); |
| 35 DCHECK(match.destination_url.is_valid()); | 35 if (!history_service || !selected_url.is_valid()) { |
| 36 history_service->DeleteURL(match.destination_url); | 36 NOTREACHED() << "Can't delete requested URL"; |
| 37 DeleteMatchFromMatches(match); | 37 return; |
| 38 } | 38 } |
| 39 history_service->DeleteURL(selected_url); |
| 39 | 40 |
| 40 void HistoryProvider::DeleteMatchFromMatches(const AutocompleteMatch& match) { | 41 // Delete the match from the current set of matches. |
| 41 bool found = false; | 42 bool found = false; |
| 42 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | 43 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { |
| 43 if (i->destination_url == match.destination_url && i->type == match.type) { | 44 if (i->destination_url == selected_url && i->type == match.type) { |
| 44 found = true; | 45 found = true; |
| 45 if (i->is_history_what_you_typed_match || i->starred) { | 46 if (i->is_history_what_you_typed_match || i->starred) { |
| 46 // We can't get rid of What-You-Typed or Bookmarked matches, | 47 // We can't get rid of What-You-Typed or Bookmarked matches, |
| 47 // but we can make them look like they have no backing data. | 48 // but we can make them look like they have no backing data. |
| 48 i->deletable = false; | 49 i->deletable = false; |
| 49 i->description.clear(); | 50 i->description.clear(); |
| 50 i->description_class.clear(); | 51 i->description_class.clear(); |
| 51 } else { | 52 } else { |
| 52 matches_.erase(i); | 53 matches_.erase(i); |
| 53 } | 54 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return (scheme_pos == 0) ? prefix_end : 0; | 152 return (scheme_pos == 0) ? prefix_end : 0; |
| 152 } | 153 } |
| 153 | 154 |
| 154 // static | 155 // static |
| 155 bool HistoryProvider::PreventInlineAutocomplete( | 156 bool HistoryProvider::PreventInlineAutocomplete( |
| 156 const AutocompleteInput& input) { | 157 const AutocompleteInput& input) { |
| 157 return input.prevent_inline_autocomplete() || | 158 return input.prevent_inline_autocomplete() || |
| 158 (!input.text().empty() && | 159 (!input.text().empty() && |
| 159 IsWhitespace(input.text()[input.text().length() - 1])); | 160 IsWhitespace(input.text()[input.text().length() - 1])); |
| 160 } | 161 } |
| OLD | NEW |