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

Unified Diff: net/proxy/mojo_proxy_struct_traits.cc

Issue 2083463002: Replace //net TypeConverters with StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@type-converter-cleanup--gurl
Patch Set: rebase Created 4 years, 2 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/proxy/mojo_proxy_struct_traits.cc
diff --git a/net/proxy/mojo_proxy_struct_traits.cc b/net/proxy/mojo_proxy_struct_traits.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f4af60d2972f2c48f17b4d7e8120160db492344b
--- /dev/null
+++ b/net/proxy/mojo_proxy_struct_traits.cc
@@ -0,0 +1,124 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/proxy/mojo_proxy_struct_traits.h"
+
+#include "base/logging.h"
+#include "net/base/host_port_pair.h"
+#include "net/proxy/proxy_info.h"
+#include "net/proxy/proxy_server.h"
+
+namespace mojo {
+
+net::interfaces::ProxyScheme
+EnumTraits<net::interfaces::ProxyScheme, net::ProxyServer::Scheme>::ToMojom(
+ net::ProxyServer::Scheme scheme) {
+ using net::ProxyServer;
+ switch (scheme) {
+ case ProxyServer::SCHEME_INVALID:
+ return net::interfaces::ProxyScheme::INVALID;
+ case ProxyServer::SCHEME_DIRECT:
+ return net::interfaces::ProxyScheme::DIRECT;
+ case ProxyServer::SCHEME_HTTP:
+ return net::interfaces::ProxyScheme::HTTP;
+ case ProxyServer::SCHEME_SOCKS4:
+ return net::interfaces::ProxyScheme::SOCKS4;
+ case ProxyServer::SCHEME_SOCKS5:
+ return net::interfaces::ProxyScheme::SOCKS5;
+ case ProxyServer::SCHEME_HTTPS:
+ return net::interfaces::ProxyScheme::HTTPS;
+ case ProxyServer::SCHEME_QUIC:
+ return net::interfaces::ProxyScheme::QUIC;
+ }
+ NOTREACHED();
+ return net::interfaces::ProxyScheme::INVALID;
+}
+
+bool EnumTraits<net::interfaces::ProxyScheme, net::ProxyServer::Scheme>::
+ FromMojom(net::interfaces::ProxyScheme scheme,
+ net::ProxyServer::Scheme* out) {
+ using net::ProxyServer;
+ switch (scheme) {
+ case net::interfaces::ProxyScheme::INVALID:
+ *out = ProxyServer::SCHEME_INVALID;
+ return true;
+ case net::interfaces::ProxyScheme::DIRECT:
+ *out = ProxyServer::SCHEME_DIRECT;
+ return true;
+ case net::interfaces::ProxyScheme::HTTP:
+ *out = ProxyServer::SCHEME_HTTP;
+ return true;
+ case net::interfaces::ProxyScheme::SOCKS4:
+ *out = ProxyServer::SCHEME_SOCKS4;
+ return true;
+ case net::interfaces::ProxyScheme::SOCKS5:
+ *out = ProxyServer::SCHEME_SOCKS5;
+ return true;
+ case net::interfaces::ProxyScheme::HTTPS:
+ *out = ProxyServer::SCHEME_HTTPS;
+ return true;
+ case net::interfaces::ProxyScheme::QUIC:
+ *out = ProxyServer::SCHEME_QUIC;
+ return true;
+ }
+ return false;
+}
+
+base::StringPiece
+StructTraits<net::interfaces::ProxyServerDataView, net::ProxyServer>::host(
+ const net::ProxyServer& s) {
+ if (s.scheme() == net::ProxyServer::SCHEME_DIRECT ||
+ s.scheme() == net::ProxyServer::SCHEME_INVALID) {
+ return base::StringPiece();
dcheng 2016/10/05 05:59:33 Is it valid for these conditions to be true and ho
Sam McNally 2016/10/05 22:48:37 ProxyServer::host_port_pair() DCHECKs that it's va
+ }
+ return s.host_port_pair().host();
+}
+
+uint16_t StructTraits<net::interfaces::ProxyServerDataView,
+ net::ProxyServer>::port(const net::ProxyServer& s) {
+ if (s.scheme() == net::ProxyServer::SCHEME_DIRECT ||
+ s.scheme() == net::ProxyServer::SCHEME_INVALID) {
+ return 0;
+ }
+ return s.host_port_pair().port();
+}
+
+bool StructTraits<net::interfaces::ProxyServerDataView, net::ProxyServer>::Read(
+ net::interfaces::ProxyServerDataView data,
+ net::ProxyServer* out) {
+ net::ProxyServer::Scheme scheme;
+ if (!data.ReadScheme(&scheme))
+ return false;
+
+ base::StringPiece host;
+ if (!data.ReadHost(&host))
+ return false;
+
+ if ((scheme == net::ProxyServer::SCHEME_DIRECT ||
+ scheme == net::ProxyServer::SCHEME_INVALID) &&
+ (!host.empty() || data.port())) {
+ return false;
+ }
+
+ *out = net::ProxyServer(scheme,
+ net::HostPortPair(host.as_string(), data.port()));
+ return true;
+}
+
+bool StructTraits<net::interfaces::ProxyInfoDataView, net::ProxyInfo>::Read(
+ net::interfaces::ProxyInfoDataView data,
+ net::ProxyInfo* out) {
+ std::vector<net::ProxyServer> proxy_servers;
+ if (!data.ReadProxyServers(&proxy_servers))
+ return false;
+
+ net::ProxyList proxy_list;
+ for (const auto& server : proxy_servers)
+ proxy_list.AddProxyServer(server);
+
+ out->UseProxyList(proxy_list);
+ return true;
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698