| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/client/plugin/pepper_network_manager.h" | 5 #include "remoting/client/plugin/pepper_network_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
| 12 #include "ppapi/cpp/net_address.h" |
| 12 #include "ppapi/cpp/private/network_list_private.h" | 13 #include "ppapi/cpp/private/network_list_private.h" |
| 13 #include "ppapi/cpp/private/net_address_private.h" | 14 #include "remoting/client/plugin/pepper_util.h" |
| 15 #include "third_party/libjingle/source/talk/base/socketaddress.h" |
| 14 | 16 |
| 15 namespace remoting { | 17 namespace remoting { |
| 16 | 18 |
| 17 PepperNetworkManager::PepperNetworkManager(const pp::InstanceHandle& instance) | 19 PepperNetworkManager::PepperNetworkManager(const pp::InstanceHandle& instance) |
| 18 : monitor_(instance, &PepperNetworkManager::OnNetworkListCallbackHandler, | 20 : monitor_(instance, &PepperNetworkManager::OnNetworkListCallbackHandler, |
| 19 this), | 21 this), |
| 20 start_count_(0), | 22 start_count_(0), |
| 21 network_list_received_(false), | 23 network_list_received_(false), |
| 22 weak_factory_(this) { | 24 weak_factory_(this) { |
| 23 } | 25 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 49 pp::NetworkListPrivate list(pp::PASS_REF, list_resource); | 51 pp::NetworkListPrivate list(pp::PASS_REF, list_resource); |
| 50 object->OnNetworkList(list); | 52 object->OnNetworkList(list); |
| 51 } | 53 } |
| 52 | 54 |
| 53 void PepperNetworkManager::OnNetworkList(const pp::NetworkListPrivate& list) { | 55 void PepperNetworkManager::OnNetworkList(const pp::NetworkListPrivate& list) { |
| 54 network_list_received_ = true; | 56 network_list_received_ = true; |
| 55 | 57 |
| 56 std::vector<talk_base::Network*> networks; | 58 std::vector<talk_base::Network*> networks; |
| 57 size_t count = list.GetCount(); | 59 size_t count = list.GetCount(); |
| 58 for (size_t i = 0; i < count; i++) { | 60 for (size_t i = 0; i < count; i++) { |
| 59 std::vector<PP_NetAddress_Private> addresses; | 61 std::vector<pp::NetAddress> addresses; |
| 60 list.GetIpAddresses(i, &addresses); | 62 list.GetIpAddresses(i, &addresses); |
| 61 | 63 |
| 62 if (addresses.size() == 0) | 64 if (addresses.size() == 0) |
| 63 continue; | 65 continue; |
| 64 | 66 |
| 65 char address_bytes[sizeof(in6_addr)]; | 67 talk_base::Network* network = new talk_base::Network( |
| 66 if (!pp::NetAddressPrivate::GetAddress( | 68 list.GetName(i), list.GetDisplayName(i), talk_base::IPAddress(), 0); |
| 67 addresses[0], &address_bytes, sizeof(address_bytes))) { | 69 |
| 68 LOG(ERROR) << "Failed to get address for network interface."; | 70 for (size_t i = 0; i < addresses.size(); ++i) { |
| 69 continue; | 71 talk_base::SocketAddress address; |
| 72 PpNetAddressToSocketAddress(addresses[i], &address); |
| 73 network->AddIP(address.ipaddr()); |
| 70 } | 74 } |
| 71 | 75 |
| 72 int prefix_length; | |
| 73 | |
| 74 // TODO(sergeyu): Copy all addresses, not only the first one. | |
| 75 talk_base::IPAddress address; | |
| 76 switch (pp::NetAddressPrivate::GetFamily(addresses[0])) { | |
| 77 case PP_NETADDRESSFAMILY_PRIVATE_IPV4: { | |
| 78 in_addr* address_ipv4 = reinterpret_cast<in_addr*>(address_bytes); | |
| 79 address = talk_base::IPAddress(*address_ipv4); | |
| 80 prefix_length = sizeof(in_addr) * 8; | |
| 81 break; | |
| 82 } | |
| 83 | |
| 84 case PP_NETADDRESSFAMILY_PRIVATE_IPV6: { | |
| 85 in6_addr* address_ipv6 = reinterpret_cast<in6_addr*>(address_bytes); | |
| 86 address = talk_base::IPAddress(*address_ipv6); | |
| 87 prefix_length = sizeof(in6_addr) * 8; | |
| 88 break; | |
| 89 } | |
| 90 | |
| 91 default: | |
| 92 LOG(WARNING) << "Skipping address with unknown family: " | |
| 93 << pp::NetAddressPrivate::GetFamily(addresses[0]); | |
| 94 continue; | |
| 95 } | |
| 96 | |
| 97 talk_base::Network* network = new talk_base::Network( | |
| 98 list.GetName(i), list.GetDisplayName(i), address, prefix_length); | |
| 99 network->AddIP(address); | |
| 100 networks.push_back(network); | 76 networks.push_back(network); |
| 101 } | 77 } |
| 102 | 78 |
| 103 bool changed = false; | 79 bool changed = false; |
| 104 MergeNetworkList(networks, &changed); | 80 MergeNetworkList(networks, &changed); |
| 105 if (changed) | 81 if (changed) |
| 106 SignalNetworksChanged(); | 82 SignalNetworksChanged(); |
| 107 } | 83 } |
| 108 | 84 |
| 109 void PepperNetworkManager::SendNetworksChangedSignal() { | 85 void PepperNetworkManager::SendNetworksChangedSignal() { |
| 110 SignalNetworksChanged(); | 86 SignalNetworksChanged(); |
| 111 } | 87 } |
| 112 | 88 |
| 113 } // namespace remoting | 89 } // namespace remoting |
| OLD | NEW |