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" | |
| 12 #include "chrome/browser/autocomplete/autocomplete_match.h" | |
| 13 #include "chrome/browser/history/history.h" | |
| 11 #include "chrome/browser/net/url_fixer_upper.h" | 14 #include "chrome/browser/net/url_fixer_upper.h" |
| 15 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 13 #include "googleurl/src/url_util.h" | 17 #include "googleurl/src/url_util.h" |
| 14 | 18 |
| 15 HistoryProvider::HistoryProvider(ACProviderListener* listener, | 19 HistoryProvider::HistoryProvider(ACProviderListener* listener, |
| 16 Profile* profile, | 20 Profile* profile, |
| 17 const char* name) | 21 const char* name) |
| 18 : AutocompleteProvider(listener, profile, name) { | 22 : AutocompleteProvider(listener, profile, name) { |
| 19 } | 23 } |
| 20 | 24 |
| 25 void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { | |
| 26 DCHECK(done_); | |
| 27 DCHECK(profile_); | |
| 28 DCHECK(match.deletable); | |
| 29 | |
| 30 HistoryService* const history_service = | |
| 31 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | |
|
brettw
2010/12/16 17:55:14
This should be indented 2 more spaces, like it was
| |
| 32 | |
| 33 // Delete the match from the history DB. | |
| 34 GURL selected_url(match.destination_url); | |
| 35 if (!history_service || !selected_url.is_valid()) { | |
| 36 NOTREACHED() << "Can't delete requested URL"; | |
| 37 return; | |
| 38 } | |
| 39 history_service->DeleteURL(selected_url); | |
| 40 | |
| 41 // Delete the match from the current set of matches. | |
| 42 bool found = false; | |
| 43 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | |
| 44 if (i->destination_url == selected_url && i->type == match.type) { | |
| 45 found = true; | |
| 46 if (i->is_history_what_you_typed_match) { | |
| 47 // We can't get rid of the What You Typed match, but we can make it | |
| 48 // look like it has no backing data. | |
| 49 i->deletable = false; | |
| 50 i->description.clear(); | |
| 51 i->description_class.clear(); | |
| 52 } else { | |
| 53 matches_.erase(i); | |
| 54 } | |
| 55 break; | |
| 56 } | |
| 57 } | |
| 58 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; | |
| 59 listener_->OnProviderUpdate(true); | |
| 60 } | |
| 61 | |
| 21 // static | 62 // static |
| 22 std::wstring HistoryProvider::FixupUserInput(const AutocompleteInput& input) { | 63 std::wstring HistoryProvider::FixupUserInput(const AutocompleteInput& input) { |
| 23 const std::wstring& input_text = input.text(); | 64 const std::wstring& input_text = input.text(); |
| 24 // Fixup and canonicalize user input. | 65 // Fixup and canonicalize user input. |
| 25 const GURL canonical_gurl(URLFixerUpper::FixupURL(WideToUTF8(input_text), | 66 const GURL canonical_gurl(URLFixerUpper::FixupURL(WideToUTF8(input_text), |
| 26 std::string())); | 67 std::string())); |
| 27 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); | 68 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); |
| 28 if (canonical_gurl_str.empty()) { | 69 if (canonical_gurl_str.empty()) { |
| 29 // This probably won't happen, but there are no guarantees. | 70 // This probably won't happen, but there are no guarantees. |
| 30 return input_text; | 71 return input_text; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 DCHECK(scheme_pos != std::wstring::npos); | 135 DCHECK(scheme_pos != std::wstring::npos); |
| 95 | 136 |
| 96 // Erase scheme plus up to two slashes. | 137 // Erase scheme plus up to two slashes. |
| 97 size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1; | 138 size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1; |
| 98 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); |
| 99 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == L'/')) | 140 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == L'/')) |
| 100 ++prefix_end; | 141 ++prefix_end; |
| 101 url->erase(scheme_pos, prefix_end - scheme_pos); | 142 url->erase(scheme_pos, prefix_end - scheme_pos); |
| 102 return (scheme_pos == 0) ? prefix_end : 0; | 143 return (scheme_pos == 0) ? prefix_end : 0; |
| 103 } | 144 } |
| OLD | NEW |