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

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

Issue 320713002: Revert of Omnibox: Combine Two Input Type Enums into One (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 2e18481111b70ebb0d5c2820581f6cef78d53c92..36652d4d5594592627fc720c4641c1dd49065d38 100644
--- a/chrome/browser/autocomplete/autocomplete_input.cc
+++ b/chrome/browser/autocomplete/autocomplete_input.cc
@@ -32,7 +32,7 @@
AutocompleteInput::AutocompleteInput()
: cursor_position_(base::string16::npos),
current_page_classification_(AutocompleteInput::INVALID_SPEC),
- type_(metrics::OmniboxInputType::INVALID),
+ type_(INVALID),
prevent_inline_autocomplete_(false),
prefer_keyword_(false),
allow_exact_keyword_match_(true),
@@ -69,11 +69,10 @@
GURL canonicalized_url;
type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url);
- if (type_ == metrics::OmniboxInputType::INVALID)
+ if (type_ == INVALID)
return;
- if (((type_ == metrics::OmniboxInputType::UNKNOWN) ||
- (type_ == metrics::OmniboxInputType::URL)) &&
+ if (((type_ == UNKNOWN) || (type_ == URL)) &&
canonicalized_url.is_valid() &&
(!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() ||
canonicalized_url.SchemeIsFileSystem() ||
@@ -99,10 +98,9 @@
// static
size_t AutocompleteInput::RemoveForcedQueryStringIfNecessary(
- AutocompleteInput::Type type,
+ Type type,
base::string16* text) {
- if ((type != metrics::OmniboxInputType::FORCED_QUERY) || text->empty() ||
- (*text)[0] != L'?')
+ if (type != FORCED_QUERY || text->empty() || (*text)[0] != L'?')
return 0;
// Drop the leading '?'.
text->erase(0, 1);
@@ -110,17 +108,18 @@
}
// static
-std::string AutocompleteInput::TypeToString(AutocompleteInput::Type type) {
+std::string AutocompleteInput::TypeToString(Type type) {
switch (type) {
- 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();
+ 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();
+ }
}
// static
@@ -132,12 +131,12 @@
GURL* canonicalized_url) {
size_t first_non_white = text.find_first_not_of(base::kWhitespaceUTF16, 0);
if (first_non_white == base::string16::npos)
- return metrics::OmniboxInputType::INVALID; // All whitespace.
+ return 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 metrics::OmniboxInputType::FORCED_QUERY;
+ return FORCED_QUERY;
}
// Ask our parsing back-end to help us understand what the user typed. We
@@ -160,13 +159,13 @@
*canonicalized_url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text),
base::UTF16ToUTF8(desired_tld));
if (!canonicalized_url->is_valid())
- return metrics::OmniboxInputType::QUERY;
+ return 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 metrics::OmniboxInputType::URL;
+ return URL;
}
// If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it
@@ -187,7 +186,7 @@
LowerCaseEqualsASCII(parsed_scheme, content::kViewSourceScheme) ||
LowerCaseEqualsASCII(parsed_scheme, url::kJavaScriptScheme) ||
LowerCaseEqualsASCII(parsed_scheme, url::kDataScheme))
- return metrics::OmniboxInputType::URL;
+ return 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
@@ -203,12 +202,12 @@
base::UTF16ToUTF8(parsed_scheme), true);
switch (block_state) {
case ExternalProtocolHandler::DONT_BLOCK:
- return metrics::OmniboxInputType::URL;
+ return 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 metrics::OmniboxInputType::QUERY;
+ return QUERY;
default: {
// We don't know about this scheme. It might be that the user typed a
@@ -219,14 +218,13 @@
url::Parsed http_parts;
base::string16 http_scheme;
GURL http_canonicalized_url;
- AutocompleteInput::Type http_type =
- Parse(http_scheme_prefix + text, desired_tld, &http_parts,
- &http_scheme, &http_canonicalized_url);
+ 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 == metrics::OmniboxInputType::URL) &&
- http_parts.username.is_nonempty() &&
+ if ((http_type == 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).
@@ -250,7 +248,7 @@
scheme->clear();
*canonicalized_url = http_canonicalized_url;
- return metrics::OmniboxInputType::URL;
+ return URL;
}
// We don't know about this scheme and it doesn't look like the user
@@ -259,7 +257,7 @@
// 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 metrics::OmniboxInputType::UNKNOWN;
+ return UNKNOWN;
}
}
}
@@ -273,7 +271,7 @@
// 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 metrics::OmniboxInputType::QUERY;
+ return QUERY;
// Sanity-check: GURL should have failed to canonicalize this URL if it had an
// invalid port.
@@ -299,14 +297,11 @@
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) {
- // Something like "99999999999" that looks like a bad IP
- // address, but becomes valid on attaching a TLD.
- return metrics::OmniboxInputType::URL;
- }
+ 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.
}
- // Could be a broken IP address, etc.
- return metrics::OmniboxInputType::QUERY;
+ return QUERY; // Could be a broken IP address, etc.
}
@@ -340,19 +335,18 @@
// These are rare, though probably possible in intranets.
return (parts->scheme.is_nonempty() ||
((registry_length != 0) &&
- (host.find(' ') == base::string16::npos))) ?
- metrics::OmniboxInputType::UNKNOWN : metrics::OmniboxInputType::QUERY;
+ (host.find(' ') == base::string16::npos))) ? UNKNOWN : 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 metrics::OmniboxInputType::URL;
+ return URL;
// See if the host is an IP address.
if (host_info.family == url::CanonHostInfo::IPV6)
- return metrics::OmniboxInputType::URL;
+ return 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
@@ -365,27 +359,27 @@
// below.
if ((host_info.family == url::CanonHostInfo::IPV4) &&
(host_info.num_ipv4_components == 4))
- return metrics::OmniboxInputType::URL;
+ return 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 metrics::OmniboxInputType::URL;
+ return 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 metrics::OmniboxInputType::URL;
+ return 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 metrics::OmniboxInputType::URL;
+ return URL;
// If the host has a known TLD or a port, it's probably a URL, with the
// following exceptions:
@@ -398,16 +392,14 @@
// 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() ? metrics::OmniboxInputType::UNKNOWN :
- metrics::OmniboxInputType::URL;
- }
+ parts->port.is_nonempty())))
+ return parts->username.is_nonempty() ? UNKNOWN : 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 metrics::OmniboxInputType::URL;
+ return URL;
// No scheme, password, port, path, and no known TLD on the host.
// This could be:
@@ -426,7 +418,7 @@
// 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 metrics::OmniboxInputType::UNKNOWN;
+ return UNKNOWN;
}
// static
@@ -531,7 +523,7 @@
cursor_position_ = base::string16::npos;
current_url_ = GURL();
current_page_classification_ = AutocompleteInput::INVALID_SPEC;
- type_ = metrics::OmniboxInputType::INVALID;
+ type_ = 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