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_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), | 255 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), |
256 net::FormatUrlWithOffsets(info.url(), languages_, format_types, | 256 net::FormatUrlWithOffsets(info.url(), languages_, format_types, |
257 net::UnescapeRule::SPACES, NULL, NULL, &offsets)); | 257 net::UnescapeRule::SPACES, NULL, NULL, &offsets)); |
258 history::TermMatches new_matches = | 258 history::TermMatches new_matches = |
259 ReplaceOffsetsInTermMatches(history_match.url_matches(), offsets); | 259 ReplaceOffsetsInTermMatches(history_match.url_matches(), offsets); |
260 match.contents = net::FormatUrl(info.url(), languages_, format_types, | 260 match.contents = net::FormatUrl(info.url(), languages_, format_types, |
261 net::UnescapeRule::SPACES, NULL, NULL, NULL); | 261 net::UnescapeRule::SPACES, NULL, NULL, NULL); |
262 match.contents_class = | 262 match.contents_class = |
263 SpansFromTermMatch(new_matches, match.contents.length(), true); | 263 SpansFromTermMatch(new_matches, match.contents.length(), true); |
264 | 264 |
265 if (history_match.can_inline()) { | 265 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. |
266 DCHECK(!new_matches.empty()); | 266 // The second part of this test can happen if the only match(es) of the user's |
| 267 // term occur in places FormatUrl() decides to omit in the formatted url. |
| 268 // In these cases, it's impossible to set |inline_autocompletion| correctly |
| 269 // and hence the match cannot be the default match. I (mpearson@) believe |
| 270 // this is likely caused by the mismatch that offsets are originally |
| 271 // computed with respect to the cleaned-up URL yet then applied and |
| 272 // updated by FormatUrl() as if they applied to the original string. |
| 273 // See crbug.com/252630. |
| 274 // TODO(mpearson): replacing the second clause with a DCHECK after fixing |
| 275 // 252630. |
| 276 if (history_match.can_inline() && !new_matches.empty()) { |
267 size_t inline_autocomplete_offset = new_matches[0].offset + | 277 size_t inline_autocomplete_offset = new_matches[0].offset + |
268 new_matches[0].length; | 278 new_matches[0].length; |
269 // |inline_autocomplete_offset| may be beyond the end of the | 279 // |inline_autocomplete_offset| may be beyond the end of the |
270 // |fill_into_edit| if the user has typed an URL with a scheme and the | 280 // |fill_into_edit| if the user has typed an URL with a scheme and the |
271 // last character typed is a slash. That slash is removed by the | 281 // last character typed is a slash. That slash is removed by the |
272 // FormatURLWithOffsets call above. | 282 // FormatURLWithOffsets call above. |
273 if (inline_autocomplete_offset < match.fill_into_edit.length()) { | 283 if (inline_autocomplete_offset < match.fill_into_edit.length()) { |
274 match.inline_autocompletion = | 284 match.inline_autocompletion = |
275 match.fill_into_edit.substr(inline_autocomplete_offset); | 285 match.fill_into_edit.substr(inline_autocomplete_offset); |
276 } | 286 } |
(...skipping 17 matching lines...) Expand all Loading... |
294 if (index_for_testing_.get()) | 304 if (index_for_testing_.get()) |
295 return index_for_testing_.get(); | 305 return index_for_testing_.get(); |
296 | 306 |
297 HistoryService* const history_service = | 307 HistoryService* const history_service = |
298 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 308 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
299 if (!history_service) | 309 if (!history_service) |
300 return NULL; | 310 return NULL; |
301 | 311 |
302 return history_service->InMemoryIndex(); | 312 return history_service->InMemoryIndex(); |
303 } | 313 } |
OLD | NEW |