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

Unified Diff: net/base/port_util.h

Issue 1230313005: split port_util.h off of net_util.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moar Created 5 years, 5 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: net/base/port_util.h
diff --git a/net/url_request/http_user_agent_settings.h b/net/base/port_util.h
similarity index 22%
copy from net/url_request/http_user_agent_settings.h
copy to net/base/port_util.h
index 40eb1a6739cafa8e96ab250d983b3a86dcd8a934..85e9160da37c6e66c14392c974537e2e43efdb3f 100644
--- a/net/url_request/http_user_agent_settings.h
+++ b/net/base/port_util.h
@@ -2,36 +2,45 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef NET_URL_REQUEST_HTTP_USER_AGENT_SETTINGS_H_
-#define NET_URL_REQUEST_HTTP_USER_AGENT_SETTINGS_H_
+#ifndef NET_BASE_NET_PORT_UTIL_
+#define NET_BASE_NET_PORT_UTIL_
#include <string>
#include "base/basictypes.h"
#include "net/base/net_export.h"
-class GURL;
-
namespace net {
-// The interface used by HTTP jobs to retrieve HTTP Accept-Language
-// and User-Agent header values.
-class NET_EXPORT HttpUserAgentSettings {
- public:
- HttpUserAgentSettings() {}
- virtual ~HttpUserAgentSettings() {}
+// Checks if |port| is in the valid range (0 to 65535, though 0 is technically
+// reserved). Should be used before casting a port to a uint16_t.
+NET_EXPORT bool IsPortValid(int port);
+
+// Returns true if the port is in the range [0, 1023]. These ports are
+// registered by IANA and typically need root access to listen on.
+bool IsWellKnownPort(int port);
+
+// Checks if the port is allowed for the specified scheme. Ports set as allowed
+// with SetExplicitlyAllowedPorts() or by using ScopedPortException() will be
+// considered allowed for any scheme.
+NET_EXPORT bool IsPortAllowedForScheme(int port, const std::string& url_scheme);
- // Gets the value of 'Accept-Language' header field.
- virtual std::string GetAcceptLanguage() const = 0;
+// Returns the number of explicitly allowed ports; for testing.
+NET_EXPORT_PRIVATE size_t GetCountOfExplicitlyAllowedPorts();
- // Gets the UA string.
- virtual std::string GetUserAgent() const = 0;
+NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports);
+
+class NET_EXPORT ScopedPortException {
+ public:
+ explicit ScopedPortException(int port);
+ ~ScopedPortException();
private:
- DISALLOW_COPY_AND_ASSIGN(HttpUserAgentSettings);
+ int port_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedPortException);
};
} // namespace net
-#endif // NET_URL_REQUEST_HTTP_USER_AGENT_SETTINGS_H_
-
+#endif // NET_BASE_NET_PORT_UTIL_

Powered by Google App Engine
This is Rietveld 408576698