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

Unified Diff: chrome/browser/autocomplete/autocomplete_input.cc

Issue 319523005: Omnibox: Combine Two Input Type Enums into One (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/autocomplete_input.cc
diff --git a/chrome/browser/autocomplete/autocomplete_input.cc b/chrome/browser/autocomplete/autocomplete_input.cc
index 36652d4d5594592627fc720c4641c1dd49065d38..2e18481111b70ebb0d5c2820581f6cef78d53c92 100644
--- a/chrome/browser/autocomplete/autocomplete_input.cc
+++ b/chrome/browser/autocomplete/autocomplete_input.cc
@@ -32,7 +32,7 @@ void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed,
AutocompleteInput::AutocompleteInput()
: cursor_position_(base::string16::npos),
current_page_classification_(AutocompleteInput::INVALID_SPEC),
- type_(INVALID),
+ type_(metrics::OmniboxInputType::INVALID),
prevent_inline_autocomplete_(false),
prefer_keyword_(false),
allow_exact_keyword_match_(true),
@@ -69,10 +69,11 @@ AutocompleteInput::AutocompleteInput(
GURL canonicalized_url;
type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url);
- if (type_ == INVALID)
+ if (type_ == metrics::OmniboxInputType::INVALID)
return;
- if (((type_ == UNKNOWN) || (type_ == URL)) &&
+ if (((type_ == metrics::OmniboxInputType::UNKNOWN) ||
+ (type_ == metrics::OmniboxInputType::URL)) &&
canonicalized_url.is_valid() &&
(!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() ||
canonicalized_url.SchemeIsFileSystem() ||
@@ -98,9 +99,10 @@ AutocompleteInput::~AutocompleteInput() {
// static
size_t AutocompleteInput::RemoveForcedQueryStringIfNecessary(
- Type type,
+ AutocompleteInput::Type type,
base::string16* text) {
- if (type != FORCED_QUERY || text->empty() || (*text)[0] != L'?')
+ if ((type != metrics::OmniboxInputType::FORCED_QUERY) || text->empty() ||
+ (*text)[0] != L'?')
return 0;
// Drop the leading '?'.
text->erase(0, 1);
@@ -108,18 +110,17 @@ size_t AutocompleteInput::RemoveForcedQueryStringIfNecessary(
}
// static
-std::string AutocompleteInput::TypeToString(Type type) {
+std::string AutocompleteInput::TypeToString(AutocompleteInput::Type type) {
switch (type) {
- case INVALID: return "invalid";
- case UNKNOWN: return "unknown";
- case URL: return "url";
- case QUERY: return "query";
- case FORCED_QUERY: return "forced-query";
-
- default:
- NOTREACHED();
- return std::string();
+ case metrics::OmniboxInputType::INVALID: return "invalid";
+ case metrics::OmniboxInputType::UNKNOWN: return "unknown";
+ case metrics::OmniboxInputType::DEPRECATED_REQUESTED_URL:
+ return "deprecated-requested-url";
+ case metrics::OmniboxInputType::URL: return "url";
+ case metrics::OmniboxInputType::QUERY: return "query";
+ case metrics::OmniboxInputType::FORCED_QUERY: return "forced-query";
}
+ return std::string();
}
// static
@@ -131,12 +132,12 @@ AutocompleteInput::Type AutocompleteInput::Parse(
GURL* canonicalized_url) {
size_t first_non_white = text.find_first_not_of(base::kWhitespaceUTF16, 0);
if (first_non_white == base::string16::npos)
- return INVALID; // All whitespace.
+ return metrics::OmniboxInputType::INVALID; // All whitespace.
if (text[first_non_white] == L'?') {
// If the first non-whitespace character is a '?', we magically treat this
// as a query.
- return FORCED_QUERY;
+ return metrics::OmniboxInputType::FORCED_QUERY;
}
// Ask our parsing back-end to help us understand what the user typed. We
@@ -159,13 +160,13 @@ AutocompleteInput::Type AutocompleteInput::Parse(
*canonicalized_url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text),
base::UTF16ToUTF8(desired_tld));
if (!canonicalized_url->is_valid())
- return QUERY;
+ return metrics::OmniboxInputType::QUERY;
if (LowerCaseEqualsASCII(parsed_scheme, url::kFileScheme)) {
// A user might or might not type a scheme when entering a file URL. In
// either case, |parsed_scheme| will tell us that this is a file URL, but
// |parts->scheme| might be empty, e.g. if the user typed "C:\foo".
- return URL;
+ return metrics::OmniboxInputType::URL;
}
// If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it
@@ -186,7 +187,7 @@ AutocompleteInput::Type AutocompleteInput::Parse(
LowerCaseEqualsASCII(parsed_scheme, content::kViewSourceScheme) ||
LowerCaseEqualsASCII(parsed_scheme, url::kJavaScriptScheme) ||
LowerCaseEqualsASCII(parsed_scheme, url::kDataScheme))
- return URL;
+ return metrics::OmniboxInputType::URL;
// Not an internal protocol. Check and see if the user has explicitly
// opened this scheme as a URL before, or if the "scheme" is actually a
@@ -202,12 +203,12 @@ AutocompleteInput::Type AutocompleteInput::Parse(
base::UTF16ToUTF8(parsed_scheme), true);
switch (block_state) {
case ExternalProtocolHandler::DONT_BLOCK:
- return URL;
+ return metrics::OmniboxInputType::URL;
case ExternalProtocolHandler::BLOCK:
// If we don't want the user to open the URL, don't let it be navigated
// to at all.
- return QUERY;
+ return metrics::OmniboxInputType::QUERY;
default: {
// We don't know about this scheme. It might be that the user typed a
@@ -218,13 +219,14 @@ AutocompleteInput::Type AutocompleteInput::Parse(
url::Parsed http_parts;
base::string16 http_scheme;
GURL http_canonicalized_url;
- Type http_type = Parse(http_scheme_prefix + text, desired_tld,
- &http_parts, &http_scheme,
- &http_canonicalized_url);
+ AutocompleteInput::Type http_type =
+ Parse(http_scheme_prefix + text, desired_tld, &http_parts,
+ &http_scheme, &http_canonicalized_url);
DCHECK_EQ(std::string(url::kHttpScheme),
base::UTF16ToUTF8(http_scheme));
- if ((http_type == URL) && http_parts.username.is_nonempty() &&
+ if ((http_type == metrics::OmniboxInputType::URL) &&
+ http_parts.username.is_nonempty() &&
http_parts.password.is_nonempty()) {
// Manually re-jigger the parsed parts to match |text| (without the
// http scheme added).
@@ -248,7 +250,7 @@ AutocompleteInput::Type AutocompleteInput::Parse(
scheme->clear();
*canonicalized_url = http_canonicalized_url;
- return URL;
+ return metrics::OmniboxInputType::URL;
}
// We don't know about this scheme and it doesn't look like the user
@@ -257,7 +259,7 @@ AutocompleteInput::Type AutocompleteInput::Parse(
// the option of treating it as a URL if we're wrong.
// Note that SegmentURL() is smart so we aren't tricked by "c:\foo" or
// "www.example.com:81" in this case.
- return UNKNOWN;
+ return metrics::OmniboxInputType::UNKNOWN;
}
}
}
@@ -271,7 +273,7 @@ AutocompleteInput::Type AutocompleteInput::Parse(
// valid, non-standard URL; for standard URLs, an empty host would have
// resulted in an invalid |canonicalized_url| above.)
if (!parts->host.is_nonempty())
- return QUERY;
+ return metrics::OmniboxInputType::QUERY;
// Sanity-check: GURL should have failed to canonicalize this URL if it had an
// invalid port.
@@ -297,11 +299,14 @@ AutocompleteInput::Type AutocompleteInput::Parse(
base::UTF16ToUTF8(host_with_tld),
net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
- if (tld_length != std::string::npos)
- return URL; // Something like "99999999999" that looks like a bad IP
- // address, but becomes valid on attaching a TLD.
+ if (tld_length != std::string::npos) {
+ // Something like "99999999999" that looks like a bad IP
+ // address, but becomes valid on attaching a TLD.
+ return metrics::OmniboxInputType::URL;
+ }
}
- return QUERY; // Could be a broken IP address, etc.
+ // Could be a broken IP address, etc.
+ return metrics::OmniboxInputType::QUERY;
}
@@ -335,18 +340,19 @@ AutocompleteInput::Type AutocompleteInput::Parse(
// These are rare, though probably possible in intranets.
return (parts->scheme.is_nonempty() ||
((registry_length != 0) &&
- (host.find(' ') == base::string16::npos))) ? UNKNOWN : QUERY;
+ (host.find(' ') == base::string16::npos))) ?
+ metrics::OmniboxInputType::UNKNOWN : metrics::OmniboxInputType::QUERY;
}
// Now that we've ruled out all schemes other than http or https and done a
// little more sanity checking, the presence of a scheme means this is likely
// a URL.
if (parts->scheme.is_nonempty())
- return URL;
+ return metrics::OmniboxInputType::URL;
// See if the host is an IP address.
if (host_info.family == url::CanonHostInfo::IPV6)
- return URL;
+ return metrics::OmniboxInputType::URL;
// If the user originally typed a host that looks like an IP address (a
// dotted quad), they probably want to open it. If the original input was
// something else (like a single number), they probably wanted to search for
@@ -359,27 +365,27 @@ AutocompleteInput::Type AutocompleteInput::Parse(
// below.
if ((host_info.family == url::CanonHostInfo::IPV4) &&
(host_info.num_ipv4_components == 4))
- return URL;
+ return metrics::OmniboxInputType::URL;
// Presence of a password means this is likely a URL. Note that unless the
// user has typed an explicit "http://" or similar, we'll probably think that
// the username is some unknown scheme, and bail out in the scheme-handling
// code above.
if (parts->password.is_nonempty())
- return URL;
+ return metrics::OmniboxInputType::URL;
// Trailing slashes force the input to be treated as a URL.
if (parts->path.is_nonempty()) {
char c = text[parts->path.end() - 1];
if ((c == '\\') || (c == '/'))
- return URL;
+ return metrics::OmniboxInputType::URL;
}
// If there is more than one recognized non-host component, this is likely to
// be a URL, even if the TLD is unknown (in which case this is likely an
// intranet URL).
if (NumNonHostComponents(*parts) > 1)
- return URL;
+ return metrics::OmniboxInputType::URL;
// If the host has a known TLD or a port, it's probably a URL, with the
// following exceptions:
@@ -392,14 +398,16 @@ AutocompleteInput::Type AutocompleteInput::Parse(
// Note that we special-case "localhost" as a known hostname.
if ((host_info.family != url::CanonHostInfo::IPV4) &&
((registry_length != 0) || (host == base::ASCIIToUTF16("localhost") ||
- parts->port.is_nonempty())))
- return parts->username.is_nonempty() ? UNKNOWN : URL;
+ parts->port.is_nonempty()))) {
+ return parts->username.is_nonempty() ? metrics::OmniboxInputType::UNKNOWN :
+ metrics::OmniboxInputType::URL;
+ }
// If we reach this point, we know there's no known TLD on the input, so if
// the user wishes to add a desired_tld, the fixup code will oblige; thus this
// is a URL.
if (!desired_tld.empty())
- return URL;
+ return metrics::OmniboxInputType::URL;
// No scheme, password, port, path, and no known TLD on the host.
// This could be:
@@ -418,7 +426,7 @@ AutocompleteInput::Type AutocompleteInput::Parse(
// QUERY. Since this is indistinguishable from the case above, and this
// case is much more likely, claim these are UNKNOWN, which should default
// to the right thing and let users correct us on a case-by-case basis.
- return UNKNOWN;
+ return metrics::OmniboxInputType::UNKNOWN;
}
// static
@@ -523,7 +531,7 @@ void AutocompleteInput::Clear() {
cursor_position_ = base::string16::npos;
current_url_ = GURL();
current_page_classification_ = AutocompleteInput::INVALID_SPEC;
- type_ = INVALID;
+ type_ = metrics::OmniboxInputType::INVALID;
parts_ = url::Parsed();
scheme_.clear();
canonicalized_url_ = GURL();
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_input.h ('k') | chrome/browser/autocomplete/autocomplete_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698