| 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 "webkit/plugins/ppapi/ppb_network_monitor_private_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_network_monitor_private_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "ppapi/shared_impl/ppb_network_list_private_shared.h" | 8 #include "ppapi/shared_impl/ppb_network_list_private_shared.h" |
| 9 #include "net/base/net_util.h" | 9 #include "net/base/net_util.h" |
| 10 #include "webkit/plugins/ppapi/resource_helper.h" | 10 #include "webkit/plugins/ppapi/resource_helper.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 bool PPB_NetworkMonitor_Private_Impl::Start() { | 49 bool PPB_NetworkMonitor_Private_Impl::Start() { |
| 50 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 50 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 51 if (!plugin_delegate) | 51 if (!plugin_delegate) |
| 52 return false; | 52 return false; |
| 53 started_ = plugin_delegate->AddNetworkListObserver(this); | 53 started_ = plugin_delegate->AddNetworkListObserver(this); |
| 54 return started_; | 54 return started_; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void PPB_NetworkMonitor_Private_Impl::OnNetworkListChanged( | 57 void PPB_NetworkMonitor_Private_Impl::OnNetworkListChanged( |
| 58 const net::NetworkInterfaceList& list) { | 58 const net::NetworkInterfaceList& list) { |
| 59 scoped_ptr< ::ppapi::PPB_NetworkList_Private_Shared::NetworkList> list_copy( | 59 ::ppapi::NetworkList list_copy(list.size()); |
| 60 new ::ppapi::PPB_NetworkList_Private_Shared::NetworkList(list.size())); | |
| 61 for (size_t i = 0; i < list.size(); ++i) { | 60 for (size_t i = 0; i < list.size(); ++i) { |
| 62 ::ppapi::PPB_NetworkList_Private_Shared::NetworkInfo& network = | 61 ::ppapi::NetworkInfo& network = list_copy.at(i); |
| 63 list_copy->at(i); | |
| 64 network.name = list[i].name; | 62 network.name = list[i].name; |
| 65 | 63 |
| 66 network.addresses.resize(1); | 64 network.addresses.resize(1); |
| 67 CHECK_LE(list[i].address.size(), sizeof(network.addresses[0].data)); | 65 CHECK_LE(list[i].address.size(), sizeof(network.addresses[0].data)); |
| 68 network.addresses[0].size = list[i].address.size(); | 66 network.addresses[0].size = list[i].address.size(); |
| 69 memcpy(network.addresses[0].data, &(list[i].address.front()), | 67 memcpy(network.addresses[0].data, &(list[i].address.front()), |
| 70 list[i].address.size()); | 68 list[i].address.size()); |
| 71 | 69 |
| 72 // TODO(sergeyu): Currently net::NetworkInterfaceList provides | 70 // TODO(sergeyu): Currently net::NetworkInterfaceList provides |
| 73 // only name and one IP address. Add all other fields and copy | 71 // only name and one IP address. Add all other fields and copy |
| 74 // them here. | 72 // them here. |
| 75 network.type = PP_NETWORKLIST_UNKNOWN; | 73 network.type = PP_NETWORKLIST_UNKNOWN; |
| 76 network.state = PP_NETWORKLIST_UP; | 74 network.state = PP_NETWORKLIST_UP; |
| 77 network.display_name = list[i].name; | 75 network.display_name = list[i].name; |
| 78 network.mtu = 0; | 76 network.mtu = 0; |
| 79 } | 77 } |
| 78 scoped_refptr< ::ppapi::NetworkListStorage> list_storage( |
| 79 new ::ppapi::NetworkListStorage(list_copy)); |
| 80 PP_Resource list_resource = | 80 PP_Resource list_resource = |
| 81 ::ppapi::PPB_NetworkList_Private_Shared::Create( | 81 ::ppapi::PPB_NetworkList_Private_Shared::Create( |
| 82 ::ppapi::OBJECT_IS_IMPL, pp_instance(), list_copy.Pass()); | 82 ::ppapi::OBJECT_IS_IMPL, pp_instance(), list_storage); |
| 83 callback_(user_data_, list_resource); | 83 callback_(user_data_, list_resource); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace ppapi | 86 } // namespace ppapi |
| 87 } // namespace webkit | 87 } // namespace webkit |
| OLD | NEW |