Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_PROXY_MOJO_PROXY_STRUCT_TRAITS_H_ | |
| 6 #define NET_PROXY_MOJO_PROXY_STRUCT_TRAITS_H_ | |
| 7 | |
| 8 #include "base/strings/string_piece.h" | |
| 9 #include "mojo/public/cpp/bindings/enum_traits.h" | |
| 10 #include "mojo/public/cpp/bindings/struct_traits.h" | |
| 11 #include "net/base/host_port_pair.h" | |
| 12 #include "net/interfaces/proxy_resolver_service.mojom.h" | |
| 13 #include "net/proxy/proxy_info.h" | |
| 14 #include "net/proxy/proxy_list.h" | |
| 15 #include "net/proxy/proxy_server.h" | |
| 16 | |
| 17 namespace net { | |
| 18 class ProxyInfo; | |
| 19 class ProxyServer; | |
| 20 } | |
| 21 | |
| 22 namespace mojo { | |
| 23 | |
| 24 template <> | |
| 25 struct EnumTraits<net::interfaces::ProxyScheme, net::ProxyServer::Scheme> { | |
| 26 static net::interfaces::ProxyScheme ToMojom(net::ProxyServer::Scheme scheme); | |
| 27 static bool FromMojom(net::interfaces::ProxyScheme scheme, | |
| 28 net::ProxyServer::Scheme* out); | |
| 29 }; | |
| 30 | |
| 31 template <> | |
| 32 struct StructTraits<net::interfaces::ProxyServer, net::ProxyServer> { | |
| 33 static net::ProxyServer::Scheme scheme(const net::ProxyServer& s) { | |
| 34 return s.scheme(); | |
| 35 } | |
| 36 | |
| 37 static base::StringPiece host(const net::ProxyServer& s) { | |
| 38 if (s.scheme() == net::ProxyServer::SCHEME_DIRECT || | |
|
dcheng
2016/06/27 03:50:45
Let's move this to the .cc, since it's not just a
Sam McNally
2016/06/29 01:42:07
Done.
| |
| 39 s.scheme() == net::ProxyServer::SCHEME_INVALID) { | |
| 40 return base::StringPiece(); | |
| 41 } | |
| 42 return s.host_port_pair().host(); | |
| 43 } | |
| 44 | |
| 45 static uint16_t port(const net::ProxyServer& s) { | |
| 46 if (s.scheme() == net::ProxyServer::SCHEME_DIRECT || | |
| 47 s.scheme() == net::ProxyServer::SCHEME_INVALID) { | |
| 48 return 0; | |
| 49 } | |
| 50 return s.host_port_pair().port(); | |
| 51 } | |
| 52 | |
| 53 static bool Read(net::interfaces::ProxyServerDataView data, | |
| 54 net::ProxyServer* out); | |
| 55 }; | |
| 56 | |
| 57 template <> | |
| 58 struct StructTraits<net::interfaces::ProxyInfo, net::ProxyInfo> { | |
| 59 static const std::vector<net::ProxyServer>& proxy_servers( | |
| 60 const net::ProxyInfo& info) { | |
| 61 return info.proxy_list().GetAll(); | |
| 62 } | |
| 63 | |
| 64 static bool Read(net::interfaces::ProxyInfoDataView data, | |
| 65 net::ProxyInfo* out); | |
| 66 }; | |
| 67 | |
| 68 } // namespace mojo | |
| 69 | |
| 70 #endif // NET_PROXY_MOJO_PROXY_STRUCT_TRAITS_H_ | |
| OLD | NEW |