| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_provider.h" | 5 #include "chrome/browser/autocomplete/history_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_input.h" | 11 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 13 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
| 14 #include "chrome/browser/history/history_service.h" | 14 #include "chrome/browser/history/history_service.h" |
| 15 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 16 #include "chrome/browser/history/in_memory_url_index_types.h" | 16 #include "chrome/browser/history/in_memory_url_index_types.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "url/url_util.h" | 19 #include "url/url_util.h" |
| 20 | 20 |
| 21 HistoryProvider::HistoryProvider(AutocompleteProviderListener* listener, | |
| 22 Profile* profile, | |
| 23 AutocompleteProvider::Type type) | |
| 24 : AutocompleteProvider(listener, profile, type) { | |
| 25 } | |
| 26 | |
| 27 void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { | 21 void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { |
| 28 DCHECK(done_); | 22 DCHECK(done_); |
| 29 DCHECK(profile_); | 23 DCHECK(profile_); |
| 30 DCHECK(match.deletable); | 24 DCHECK(match.deletable); |
| 31 | 25 |
| 32 HistoryService* const history_service = | 26 HistoryService* const history_service = |
| 33 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 27 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 34 | 28 |
| 35 // Delete the match from the history DB. | 29 // Delete the match from the history DB. |
| 36 DCHECK(history_service); | 30 DCHECK(history_service); |
| 37 DCHECK(match.destination_url.is_valid()); | 31 DCHECK(match.destination_url.is_valid()); |
| 38 history_service->DeleteURL(match.destination_url); | 32 history_service->DeleteURL(match.destination_url); |
| 39 DeleteMatchFromMatches(match); | 33 DeleteMatchFromMatches(match); |
| 40 } | 34 } |
| 41 | 35 |
| 36 // static |
| 37 bool HistoryProvider::PreventInlineAutocomplete( |
| 38 const AutocompleteInput& input) { |
| 39 return input.prevent_inline_autocomplete() || |
| 40 (!input.text().empty() && |
| 41 IsWhitespace(input.text()[input.text().length() - 1])); |
| 42 } |
| 43 |
| 44 HistoryProvider::HistoryProvider(AutocompleteProviderListener* listener, |
| 45 Profile* profile, |
| 46 AutocompleteProvider::Type type) |
| 47 : AutocompleteProvider(listener, profile, type) { |
| 48 } |
| 49 |
| 42 HistoryProvider::~HistoryProvider() {} | 50 HistoryProvider::~HistoryProvider() {} |
| 43 | 51 |
| 44 void HistoryProvider::DeleteMatchFromMatches(const AutocompleteMatch& match) { | 52 void HistoryProvider::DeleteMatchFromMatches(const AutocompleteMatch& match) { |
| 45 bool found = false; | 53 bool found = false; |
| 46 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | 54 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { |
| 47 if (i->destination_url == match.destination_url && i->type == match.type) { | 55 if (i->destination_url == match.destination_url && i->type == match.type) { |
| 48 found = true; | 56 found = true; |
| 49 if (i->is_history_what_you_typed_match || i->starred) { | 57 if (i->is_history_what_you_typed_match || i->starred) { |
| 50 // We can't get rid of What-You-Typed or Bookmarked matches, | 58 // We can't get rid of What-You-Typed or Bookmarked matches, |
| 51 // but we can make them look like they have no backing data. | 59 // but we can make them look like they have no backing data. |
| 52 i->deletable = false; | 60 i->deletable = false; |
| 53 i->description.clear(); | 61 i->description.clear(); |
| 54 i->description_class.clear(); | 62 i->description_class.clear(); |
| 55 } else { | 63 } else { |
| 56 matches_.erase(i); | 64 matches_.erase(i); |
| 57 } | 65 } |
| 58 break; | 66 break; |
| 59 } | 67 } |
| 60 } | 68 } |
| 61 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; | 69 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; |
| 62 } | 70 } |
| 63 | 71 |
| 64 // static | 72 // static |
| 65 bool HistoryProvider::PreventInlineAutocomplete( | |
| 66 const AutocompleteInput& input) { | |
| 67 return input.prevent_inline_autocomplete() || | |
| 68 (!input.text().empty() && | |
| 69 IsWhitespace(input.text()[input.text().length() - 1])); | |
| 70 } | |
| 71 | |
| 72 // static | |
| 73 ACMatchClassifications HistoryProvider::SpansFromTermMatch( | 73 ACMatchClassifications HistoryProvider::SpansFromTermMatch( |
| 74 const history::TermMatches& matches, | 74 const history::TermMatches& matches, |
| 75 size_t text_length, | 75 size_t text_length, |
| 76 bool is_url) { | 76 bool is_url) { |
| 77 ACMatchClassification::Style url_style = | 77 ACMatchClassification::Style url_style = |
| 78 is_url ? ACMatchClassification::URL : ACMatchClassification::NONE; | 78 is_url ? ACMatchClassification::URL : ACMatchClassification::NONE; |
| 79 ACMatchClassifications spans; | 79 ACMatchClassifications spans; |
| 80 if (matches.empty()) { | 80 if (matches.empty()) { |
| 81 if (text_length) | 81 if (text_length) |
| 82 spans.push_back(ACMatchClassification(0, url_style)); | 82 spans.push_back(ACMatchClassification(0, url_style)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 93 do { | 93 do { |
| 94 offset += matches[i].length; | 94 offset += matches[i].length; |
| 95 ++i; | 95 ++i; |
| 96 } while ((i < match_count) && (offset == matches[i].offset)); | 96 } while ((i < match_count) && (offset == matches[i].offset)); |
| 97 if (offset < text_length) | 97 if (offset < text_length) |
| 98 spans.push_back(ACMatchClassification(offset, url_style)); | 98 spans.push_back(ACMatchClassification(offset, url_style)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 return spans; | 101 return spans; |
| 102 } | 102 } |
| OLD | NEW |