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/bookmarks/bookmark_model_factory.h" | |
12 #include "chrome/browser/history/history_service_factory.h" | |
13 #include "chrome/browser/profiles/profile.h" | |
14 #include "chrome/common/url_constants.h" | |
15 #include "components/bookmarks/browser/bookmark_model.h" | 11 #include "components/bookmarks/browser/bookmark_model.h" |
16 #include "components/history/core/browser/history_service.h" | 12 #include "components/history/core/browser/history_service.h" |
17 #include "components/omnibox/autocomplete_input.h" | 13 #include "components/omnibox/autocomplete_input.h" |
18 #include "components/omnibox/autocomplete_match.h" | 14 #include "components/omnibox/autocomplete_match.h" |
19 #include "components/omnibox/in_memory_url_index_types.h" | 15 #include "components/omnibox/in_memory_url_index_types.h" |
20 #include "url/url_util.h" | 16 #include "url/url_util.h" |
21 | 17 |
22 using bookmarks::BookmarkModel; | 18 using bookmarks::BookmarkModel; |
23 | 19 |
24 void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { | 20 void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { |
25 DCHECK(done_); | 21 DCHECK(done_); |
26 DCHECK(profile_); | 22 DCHECK(client_); |
27 DCHECK(match.deletable); | 23 DCHECK(match.deletable); |
28 | 24 |
29 history::HistoryService* const history_service = | 25 history::HistoryService* const history_service = client_->HistoryService(); |
30 HistoryServiceFactory::GetForProfile(profile_, | |
31 ServiceAccessType::EXPLICIT_ACCESS); | |
32 | 26 |
33 // Delete the underlying URL along with all its visits from the history DB. | 27 // Delete the underlying URL along with all its visits from the history DB. |
34 // The resulting HISTORY_URLS_DELETED notification will also cause all caches | 28 // The resulting HISTORY_URLS_DELETED notification will also cause all caches |
35 // and indices to drop any data they might have stored pertaining to the URL. | 29 // and indices to drop any data they might have stored pertaining to the URL. |
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 | 33 |
40 DeleteMatchFromMatches(match); | 34 DeleteMatchFromMatches(match); |
41 } | 35 } |
42 | 36 |
43 // static | 37 // static |
44 bool HistoryProvider::PreventInlineAutocomplete( | 38 bool HistoryProvider::PreventInlineAutocomplete( |
45 const AutocompleteInput& input) { | 39 const AutocompleteInput& input) { |
46 return input.prevent_inline_autocomplete() || | 40 return input.prevent_inline_autocomplete() || |
47 (!input.text().empty() && | 41 (!input.text().empty() && |
48 IsWhitespace(input.text()[input.text().length() - 1])); | 42 IsWhitespace(input.text()[input.text().length() - 1])); |
49 } | 43 } |
50 | 44 |
51 HistoryProvider::HistoryProvider(Profile* profile, | 45 HistoryProvider::HistoryProvider(scoped_ptr<AutocompleteProviderClient> client, |
52 AutocompleteProvider::Type type) | 46 AutocompleteProvider::Type type) |
53 : AutocompleteProvider(type), | 47 : AutocompleteProvider(type), client_(client.Pass()) { |
Peter Kasting
2015/06/12 16:20:23
Tiny nit: I kinda feel like we should reverse the
blundell
2015/06/15 08:51:33
Done.
| |
54 profile_(profile) { | |
55 } | 48 } |
56 | 49 |
57 HistoryProvider::~HistoryProvider() {} | 50 HistoryProvider::~HistoryProvider() {} |
58 | 51 |
59 void HistoryProvider::DeleteMatchFromMatches(const AutocompleteMatch& match) { | 52 void HistoryProvider::DeleteMatchFromMatches(const AutocompleteMatch& match) { |
60 bool found = false; | 53 bool found = false; |
61 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); | 54 BookmarkModel* bookmark_model = client_->BookmarkModel(); |
62 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | 55 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { |
63 if (i->destination_url == match.destination_url && i->type == match.type) { | 56 if (i->destination_url == match.destination_url && i->type == match.type) { |
64 found = true; | 57 found = true; |
65 if ((i->type == AutocompleteMatchType::URL_WHAT_YOU_TYPED) || | 58 if ((i->type == AutocompleteMatchType::URL_WHAT_YOU_TYPED) || |
66 (bookmark_model && | 59 (bookmark_model && |
67 bookmark_model->IsBookmarked(i->destination_url))) { | 60 bookmark_model->IsBookmarked(i->destination_url))) { |
68 // We can't get rid of What-You-Typed or Bookmarked matches, | 61 // We can't get rid of What-You-Typed or Bookmarked matches, |
69 // but we can make them look like they have no backing data. | 62 // but we can make them look like they have no backing data. |
70 i->deletable = false; | 63 i->deletable = false; |
71 i->description.clear(); | 64 i->description.clear(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 do { | 96 do { |
104 offset += matches[i].length; | 97 offset += matches[i].length; |
105 ++i; | 98 ++i; |
106 } while ((i < match_count) && (offset == matches[i].offset)); | 99 } while ((i < match_count) && (offset == matches[i].offset)); |
107 if (offset < text_length) | 100 if (offset < text_length) |
108 spans.push_back(ACMatchClassification(offset, url_style)); | 101 spans.push_back(ACMatchClassification(offset, url_style)); |
109 } | 102 } |
110 | 103 |
111 return spans; | 104 return spans; |
112 } | 105 } |
OLD | NEW |