Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_provider.cc

Issue 320253004: Componentize URLFixerUpper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win64 fix Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 11 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/net/url_fixer_upper.h"
15 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
16 #include "components/bookmarks/browser/bookmark_model.h" 15 #include "components/bookmarks/browser/bookmark_model.h"
16 #include "components/url_fixer/url_fixer.h"
17 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
21 // static 21 // static
22 const size_t AutocompleteProvider::kMaxMatches = 3; 22 const size_t AutocompleteProvider::kMaxMatches = 3;
23 23
24 AutocompleteProvider::AutocompleteProvider( 24 AutocompleteProvider::AutocompleteProvider(
25 AutocompleteProviderListener* listener, 25 AutocompleteProviderListener* listener,
26 Profile* profile, 26 Profile* profile,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 i->starred = bookmark_model->IsBookmarked(i->destination_url); 133 i->starred = bookmark_model->IsBookmarked(i->destination_url);
134 } 134 }
135 135
136 // static 136 // static
137 AutocompleteProvider::FixupReturn AutocompleteProvider::FixupUserInput( 137 AutocompleteProvider::FixupReturn AutocompleteProvider::FixupUserInput(
138 const AutocompleteInput& input) { 138 const AutocompleteInput& input) {
139 const base::string16& input_text = input.text(); 139 const base::string16& input_text = input.text();
140 const FixupReturn failed(false, input_text); 140 const FixupReturn failed(false, input_text);
141 141
142 // Fixup and canonicalize user input. 142 // Fixup and canonicalize user input.
143 const GURL canonical_gurl(URLFixerUpper::FixupURL( 143 const GURL canonical_gurl(
144 base::UTF16ToUTF8(input_text), std::string())); 144 url_fixer::FixupURL(base::UTF16ToUTF8(input_text), std::string()));
145 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); 145 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec());
146 if (canonical_gurl_str.empty()) { 146 if (canonical_gurl_str.empty()) {
147 // This probably won't happen, but there are no guarantees. 147 // This probably won't happen, but there are no guarantees.
148 return failed; 148 return failed;
149 } 149 }
150 150
151 // If the user types a number, GURL will convert it to a dotted quad. 151 // If the user types a number, GURL will convert it to a dotted quad.
152 // However, if the parser did not mark this as a URL, then the user probably 152 // However, if the parser did not mark this as a URL, then the user probably
153 // didn't intend this interpretation. Since this can break history matching 153 // didn't intend this interpretation. Since this can break history matching
154 // for hostname beginning with numbers (e.g. input of "17173" will be matched 154 // for hostname beginning with numbers (e.g. input of "17173" will be matched
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 // Erase scheme plus up to two slashes. 218 // Erase scheme plus up to two slashes.
219 size_t prefix_end = scheme_pos + strlen(url::kHttpScheme) + 1; 219 size_t prefix_end = scheme_pos + strlen(url::kHttpScheme) + 1;
220 const size_t after_slashes = std::min(url->length(), prefix_end + 2); 220 const size_t after_slashes = std::min(url->length(), prefix_end + 2);
221 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) 221 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/'))
222 ++prefix_end; 222 ++prefix_end;
223 url->erase(scheme_pos, prefix_end - scheme_pos); 223 url->erase(scheme_pos, prefix_end - scheme_pos);
224 return (scheme_pos == 0) ? prefix_end : 0; 224 return (scheme_pos == 0) ? prefix_end : 0;
225 } 225 }
226 226
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_input.cc ('k') | chrome/browser/autocomplete/base_search_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698