| 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/autocomplete_provider.h" | 5 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_match.h" | 9 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 10 #include "components/autocomplete/autocomplete_input.h" | 10 #include "components/autocomplete/autocomplete_input.h" |
| 11 #include "components/bookmarks/browser/bookmark_model.h" | |
| 12 #include "components/url_fixer/url_fixer.h" | 11 #include "components/url_fixer/url_fixer.h" |
| 13 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
| 14 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 15 | 14 |
| 16 // static | 15 // static |
| 17 const size_t AutocompleteProvider::kMaxMatches = 3; | 16 const size_t AutocompleteProvider::kMaxMatches = 3; |
| 18 | 17 |
| 19 AutocompleteProvider::AutocompleteProvider(Type type) | 18 AutocompleteProvider::AutocompleteProvider(Type type) |
| 20 : done_(true), | 19 : done_(true), |
| 21 type_(type) { | 20 type_(type) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void AutocompleteProvider::AddProviderInfo(ProvidersInfo* provider_info) const { | 86 void AutocompleteProvider::AddProviderInfo(ProvidersInfo* provider_info) const { |
| 88 } | 87 } |
| 89 | 88 |
| 90 void AutocompleteProvider::ResetSession() { | 89 void AutocompleteProvider::ResetSession() { |
| 91 } | 90 } |
| 92 | 91 |
| 93 AutocompleteProvider::~AutocompleteProvider() { | 92 AutocompleteProvider::~AutocompleteProvider() { |
| 94 Stop(false); | 93 Stop(false); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void AutocompleteProvider::UpdateStarredStateOfMatches( | |
| 98 BookmarkModel* bookmark_model) { | |
| 99 if (matches_.empty() || !bookmark_model || !bookmark_model->loaded()) | |
| 100 return; | |
| 101 | |
| 102 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | |
| 103 i->starred = bookmark_model->IsBookmarked(i->destination_url); | |
| 104 } | |
| 105 | |
| 106 // static | 96 // static |
| 107 AutocompleteProvider::FixupReturn AutocompleteProvider::FixupUserInput( | 97 AutocompleteProvider::FixupReturn AutocompleteProvider::FixupUserInput( |
| 108 const AutocompleteInput& input) { | 98 const AutocompleteInput& input) { |
| 109 const base::string16& input_text = input.text(); | 99 const base::string16& input_text = input.text(); |
| 110 const FixupReturn failed(false, input_text); | 100 const FixupReturn failed(false, input_text); |
| 111 | 101 |
| 112 // Fixup and canonicalize user input. | 102 // Fixup and canonicalize user input. |
| 113 const GURL canonical_gurl( | 103 const GURL canonical_gurl( |
| 114 url_fixer::FixupURL(base::UTF16ToUTF8(input_text), std::string())); | 104 url_fixer::FixupURL(base::UTF16ToUTF8(input_text), std::string())); |
| 115 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); | 105 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 DCHECK_NE(base::string16::npos, scheme_pos); | 176 DCHECK_NE(base::string16::npos, scheme_pos); |
| 187 | 177 |
| 188 // Erase scheme plus up to two slashes. | 178 // Erase scheme plus up to two slashes. |
| 189 size_t prefix_end = scheme_pos + strlen(url::kHttpScheme) + 1; | 179 size_t prefix_end = scheme_pos + strlen(url::kHttpScheme) + 1; |
| 190 const size_t after_slashes = std::min(url->length(), prefix_end + 2); | 180 const size_t after_slashes = std::min(url->length(), prefix_end + 2); |
| 191 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) | 181 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) |
| 192 ++prefix_end; | 182 ++prefix_end; |
| 193 url->erase(scheme_pos, prefix_end - scheme_pos); | 183 url->erase(scheme_pos, prefix_end - scheme_pos); |
| 194 return (scheme_pos == 0) ? prefix_end : 0; | 184 return (scheme_pos == 0) ? prefix_end : 0; |
| 195 } | 185 } |
| OLD | NEW |