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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 HistoryService* const history_service = | 33 HistoryService* const history_service = |
34 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 34 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
35 | 35 |
36 // Delete the match from the history DB. | 36 // Delete the match from the history DB. |
37 DCHECK(history_service); | 37 DCHECK(history_service); |
38 DCHECK(match.destination_url.is_valid()); | 38 DCHECK(match.destination_url.is_valid()); |
39 history_service->DeleteURL(match.destination_url); | 39 history_service->DeleteURL(match.destination_url); |
40 DeleteMatchFromMatches(match); | 40 DeleteMatchFromMatches(match); |
41 } | 41 } |
42 | 42 |
| 43 HistoryProvider::~HistoryProvider() {} |
| 44 |
| 45 void HistoryProvider::DeleteMatchFromMatches(const AutocompleteMatch& match) { |
| 46 bool found = false; |
| 47 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { |
| 48 if (i->destination_url == match.destination_url && i->type == match.type) { |
| 49 found = true; |
| 50 if (i->is_history_what_you_typed_match || i->starred) { |
| 51 // We can't get rid of What-You-Typed or Bookmarked matches, |
| 52 // but we can make them look like they have no backing data. |
| 53 i->deletable = false; |
| 54 i->description.clear(); |
| 55 i->description_class.clear(); |
| 56 } else { |
| 57 matches_.erase(i); |
| 58 } |
| 59 break; |
| 60 } |
| 61 } |
| 62 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; |
| 63 listener_->OnProviderUpdate(true); |
| 64 } |
| 65 |
43 // static | 66 // static |
44 bool HistoryProvider::FixupUserInput(AutocompleteInput* input) { | 67 bool HistoryProvider::FixupUserInput(AutocompleteInput* input) { |
45 const base::string16& input_text = input->text(); | 68 const base::string16& input_text = input->text(); |
46 // Fixup and canonicalize user input. | 69 // Fixup and canonicalize user input. |
47 const GURL canonical_gurl(URLFixerUpper::FixupURL(UTF16ToUTF8(input_text), | 70 const GURL canonical_gurl(URLFixerUpper::FixupURL(UTF16ToUTF8(input_text), |
48 std::string())); | 71 std::string())); |
49 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); | 72 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); |
50 if (canonical_gurl_str.empty()) { | 73 if (canonical_gurl_str.empty()) { |
51 // This probably won't happen, but there are no guarantees. | 74 // This probably won't happen, but there are no guarantees. |
52 return false; | 75 return false; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 output.append(num_input_slashes - num_output_slashes, '/'); | 127 output.append(num_input_slashes - num_output_slashes, '/'); |
105 else if (num_output_slashes > num_input_slashes) | 128 else if (num_output_slashes > num_input_slashes) |
106 output.erase(output.length() - num_output_slashes + num_input_slashes); | 129 output.erase(output.length() - num_output_slashes + num_input_slashes); |
107 | 130 |
108 url_parse::Parsed parts; | 131 url_parse::Parsed parts; |
109 URLFixerUpper::SegmentURL(output, &parts); | 132 URLFixerUpper::SegmentURL(output, &parts); |
110 input->UpdateText(output, base::string16::npos, parts); | 133 input->UpdateText(output, base::string16::npos, parts); |
111 return !output.empty(); | 134 return !output.empty(); |
112 } | 135 } |
113 | 136 |
114 HistoryProvider::~HistoryProvider() {} | |
115 | |
116 void HistoryProvider::DeleteMatchFromMatches(const AutocompleteMatch& match) { | |
117 bool found = false; | |
118 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | |
119 if (i->destination_url == match.destination_url && i->type == match.type) { | |
120 found = true; | |
121 if (i->is_history_what_you_typed_match || i->starred) { | |
122 // We can't get rid of What-You-Typed or Bookmarked matches, | |
123 // but we can make them look like they have no backing data. | |
124 i->deletable = false; | |
125 i->description.clear(); | |
126 i->description_class.clear(); | |
127 } else { | |
128 matches_.erase(i); | |
129 } | |
130 break; | |
131 } | |
132 } | |
133 DCHECK(found) << "Asked to delete a URL that isn't in our set of matches"; | |
134 listener_->OnProviderUpdate(true); | |
135 } | |
136 | |
137 // static | 137 // static |
138 size_t HistoryProvider::TrimHttpPrefix(base::string16* url) { | 138 size_t HistoryProvider::TrimHttpPrefix(base::string16* url) { |
139 // Find any "http:". | 139 // Find any "http:". |
140 if (!AutocompleteInput::HasHTTPScheme(*url)) | 140 if (!AutocompleteInput::HasHTTPScheme(*url)) |
141 return 0; | 141 return 0; |
142 size_t scheme_pos = | 142 size_t scheme_pos = |
143 url->find(ASCIIToUTF16(content::kHttpScheme) + char16(':')); | 143 url->find(ASCIIToUTF16(content::kHttpScheme) + char16(':')); |
144 DCHECK_NE(base::string16::npos, scheme_pos); | 144 DCHECK_NE(base::string16::npos, scheme_pos); |
145 | 145 |
146 // Erase scheme plus up to two slashes. | 146 // Erase scheme plus up to two slashes. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 do { | 184 do { |
185 offset += matches[i].length; | 185 offset += matches[i].length; |
186 ++i; | 186 ++i; |
187 } while ((i < match_count) && (offset == matches[i].offset)); | 187 } while ((i < match_count) && (offset == matches[i].offset)); |
188 if (offset < text_length) | 188 if (offset < text_length) |
189 spans.push_back(ACMatchClassification(offset, url_style)); | 189 spans.push_back(ACMatchClassification(offset, url_style)); |
190 } | 190 } |
191 | 191 |
192 return spans; | 192 return spans; |
193 } | 193 } |
| 194 |
OLD | NEW |