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_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" |
| 11 #include "chrome/browser/autocomplete/autocomplete.h" | 11 #include "chrome/browser/autocomplete/autocomplete.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 13 #include "chrome/browser/history/history.h" | 13 #include "chrome/browser/history/history.h" |
| 14 #include "chrome/browser/net/url_fixer_upper.h" | 14 #include "chrome/browser/net/url_fixer_upper.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "googleurl/src/url_util.h" | 17 #include "googleurl/src/url_util.h" |
| 18 | 18 |
| 19 HistoryProvider::HistoryProvider(ACProviderListener* listener, | 19 HistoryProvider::HistoryProvider(ACProviderListener* listener, |
| 20 Profile* profile, | 20 Profile* profile, |
| 21 const char* name) | 21 const char* name) |
| 22 : AutocompleteProvider(listener, profile, name) { | 22 : AutocompleteProvider(listener, profile, name) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { | 25 void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { |
|
Peter Kasting
2011/01/04 22:16:01
Nit: Move above constructor
| |
| 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 GURL selected_url(match.destination_url); | 34 GURL selected_url(match.destination_url); |
| 35 if (!history_service || !selected_url.is_valid()) { | 35 if (!history_service || !selected_url.is_valid()) { |
| 36 NOTREACHED() << "Can't delete requested URL"; | 36 NOTREACHED() << "Can't delete requested URL"; |
| 37 return; | 37 return; |
| 38 } | 38 } |
| 39 history_service->DeleteURL(selected_url); | 39 history_service->DeleteURL(selected_url); |
| 40 | 40 |
| 41 // Delete the match from the current set of matches. | 41 // Delete the match from the current set of matches. |
| 42 bool found = false; | 42 bool found = false; |
| 43 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | 43 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { |
| 44 if (i->destination_url == selected_url && i->type == match.type) { | 44 if (i->destination_url == selected_url && i->type == match.type) { |
| 45 found = true; | 45 found = true; |
| 46 if (i->is_history_what_you_typed_match) { | 46 if (i->is_history_what_you_typed_match || i->starred) { |
| 47 // We can't get rid of the What You Typed match, but we can make it | 47 // We can't get rid of What-You-Typed or Bookmarked matches, |
| 48 // look like it has no backing data. | 48 // but we can make them look like they have no backing data. |
| 49 i->deletable = false; | 49 i->deletable = false; |
| 50 i->description.clear(); | 50 i->description.clear(); |
| 51 i->description_class.clear(); | 51 i->description_class.clear(); |
| 52 } else { | 52 } else { |
| 53 matches_.erase(i); | 53 matches_.erase(i); |
| 54 } | 54 } |
| 55 break; | 55 break; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; | 58 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 DCHECK(scheme_pos != std::wstring::npos); | 135 DCHECK(scheme_pos != std::wstring::npos); |
| 136 | 136 |
| 137 // Erase scheme plus up to two slashes. | 137 // Erase scheme plus up to two slashes. |
| 138 size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1; | 138 size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1; |
| 139 const size_t after_slashes = std::min(url->length(), prefix_end + 2); | 139 const size_t after_slashes = std::min(url->length(), prefix_end + 2); |
| 140 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == L'/')) | 140 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == L'/')) |
| 141 ++prefix_end; | 141 ++prefix_end; |
| 142 url->erase(scheme_pos, prefix_end - scheme_pos); | 142 url->erase(scheme_pos, prefix_end - scheme_pos); |
| 143 return (scheme_pos == 0) ? prefix_end : 0; | 143 return (scheme_pos == 0) ? prefix_end : 0; |
| 144 } | 144 } |
| OLD | NEW |