1 // Copyright 2018 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 #include "services/network/public/cpp/network_interface_mojom_traits.h"
6 
7 #include "services/network/public/cpp/ip_address_mojom_traits.h"
8 
9 namespace mojo {
10 
11 bool StructTraits<
12     network::mojom::NetworkInterfaceDataView,
Read(network::mojom::NetworkInterfaceDataView data,net::NetworkInterface * out)13     net::NetworkInterface>::Read(network::mojom::NetworkInterfaceDataView data,
14                                  net::NetworkInterface* out) {
15   if (!data.ReadName(&out->name))
16     return false;
17   if (!data.ReadFriendlyName(&out->friendly_name))
18     return false;
19   if (!data.ReadAddress(&out->address))
20     return false;
21   if (!data.ReadType(&out->type))
22     return false;
23   out->interface_index = data.interface_index();
24   out->prefix_length = data.prefix_length();
25   out->ip_address_attributes = data.ip_address_attributes();
26   return true;
27 }
28 
29 network::mojom::ConnectionType
30 EnumTraits<network::mojom::ConnectionType,
31            net::NetworkChangeNotifier::ConnectionType>::
ToMojom(net::NetworkChangeNotifier::ConnectionType input)32     ToMojom(net::NetworkChangeNotifier::ConnectionType input) {
33   switch (input) {
34     case net::NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN:
35       return network::mojom::ConnectionType::CONNECTION_UNKNOWN;
36     case net::NetworkChangeNotifier::ConnectionType::CONNECTION_ETHERNET:
37       return network::mojom::ConnectionType::CONNECTION_ETHERNET;
38     case net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI:
39       return network::mojom::ConnectionType::CONNECTION_WIFI;
40     case net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G:
41       return network::mojom::ConnectionType::CONNECTION_2G;
42     case net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G:
43       return network::mojom::ConnectionType::CONNECTION_3G;
44     case net::NetworkChangeNotifier::ConnectionType::CONNECTION_4G:
45       return network::mojom::ConnectionType::CONNECTION_4G;
46     case net::NetworkChangeNotifier::ConnectionType::CONNECTION_5G:
47       return network::mojom::ConnectionType::CONNECTION_5G;
48     case net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE:
49       return network::mojom::ConnectionType::CONNECTION_NONE;
50     case net::NetworkChangeNotifier::ConnectionType::CONNECTION_BLUETOOTH:
51       return network::mojom::ConnectionType::CONNECTION_BLUETOOTH;
52   }
53   NOTREACHED();
54   return network::mojom::ConnectionType::CONNECTION_UNKNOWN;
55 }
56 
57 bool EnumTraits<network::mojom::ConnectionType,
58                 net::NetworkChangeNotifier::ConnectionType>::
FromMojom(network::mojom::ConnectionType input,net::NetworkChangeNotifier::ConnectionType * output)59     FromMojom(network::mojom::ConnectionType input,
60               net::NetworkChangeNotifier::ConnectionType* output) {
61   switch (input) {
62     case network::mojom::ConnectionType::CONNECTION_UNKNOWN:
63       *output = net::NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN;
64       return true;
65     case network::mojom::ConnectionType::CONNECTION_ETHERNET:
66       *output = net::NetworkChangeNotifier::ConnectionType::CONNECTION_ETHERNET;
67       return true;
68     case network::mojom::ConnectionType::CONNECTION_WIFI:
69       *output = net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI;
70       return true;
71     case network::mojom::ConnectionType::CONNECTION_2G:
72       *output = net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G;
73       return true;
74     case network::mojom::ConnectionType::CONNECTION_3G:
75       *output = net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G;
76       return true;
77     case network::mojom::ConnectionType::CONNECTION_4G:
78       *output = net::NetworkChangeNotifier::ConnectionType::CONNECTION_4G;
79       return true;
80     case network::mojom::ConnectionType::CONNECTION_5G:
81       *output = net::NetworkChangeNotifier::ConnectionType::CONNECTION_5G;
82       return true;
83     case network::mojom::ConnectionType::CONNECTION_NONE:
84       *output = net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE;
85       return true;
86     case network::mojom::ConnectionType::CONNECTION_BLUETOOTH:
87       *output =
88           net::NetworkChangeNotifier::ConnectionType::CONNECTION_BLUETOOTH;
89       return true;
90   }
91   return false;
92 }
93 
94 }  // namespace mojo
95