| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 "chrome/browser/extensions/api/system_network/system_network_api.h" | |
| 6 | |
| 7 namespace { | |
| 8 const char kNetworkListError[] = "Network lookup failed or unsupported"; | |
| 9 } // namespace | |
| 10 | |
| 11 namespace extensions { | |
| 12 namespace api { | |
| 13 | |
| 14 SystemNetworkGetNetworkInterfacesFunction:: | |
| 15 SystemNetworkGetNetworkInterfacesFunction() {} | |
| 16 | |
| 17 SystemNetworkGetNetworkInterfacesFunction:: | |
| 18 ~SystemNetworkGetNetworkInterfacesFunction() {} | |
| 19 | |
| 20 bool SystemNetworkGetNetworkInterfacesFunction::RunAsync() { | |
| 21 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | |
| 22 base::Bind(&SystemNetworkGetNetworkInterfacesFunction:: | |
| 23 GetListOnFileThread, | |
| 24 this)); | |
| 25 return true; | |
| 26 } | |
| 27 | |
| 28 void SystemNetworkGetNetworkInterfacesFunction::GetListOnFileThread() { | |
| 29 net::NetworkInterfaceList interface_list; | |
| 30 if (net::GetNetworkList( | |
| 31 &interface_list, net::INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES)) { | |
| 32 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 33 base::Bind(&SystemNetworkGetNetworkInterfacesFunction:: | |
| 34 SendResponseOnUIThread, | |
| 35 this, interface_list)); | |
| 36 return; | |
| 37 } | |
| 38 | |
| 39 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 40 base::Bind(&SystemNetworkGetNetworkInterfacesFunction:: | |
| 41 HandleGetListError, | |
| 42 this)); | |
| 43 } | |
| 44 | |
| 45 void SystemNetworkGetNetworkInterfacesFunction::HandleGetListError() { | |
| 46 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 47 error_ = kNetworkListError; | |
| 48 SendResponse(false); | |
| 49 } | |
| 50 | |
| 51 void SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread( | |
| 52 const net::NetworkInterfaceList& interface_list) { | |
| 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 54 | |
| 55 std::vector<linked_ptr<api::system_network::NetworkInterface> > | |
| 56 create_arg; | |
| 57 create_arg.reserve(interface_list.size()); | |
| 58 for (net::NetworkInterfaceList::const_iterator i = interface_list.begin(); | |
| 59 i != interface_list.end(); ++i) { | |
| 60 linked_ptr<api::system_network::NetworkInterface> info = | |
| 61 make_linked_ptr(new api::system_network::NetworkInterface); | |
| 62 info->name = i->name; | |
| 63 info->address = net::IPAddressToString(i->address); | |
| 64 info->prefix_length = i->network_prefix; | |
| 65 create_arg.push_back(info); | |
| 66 } | |
| 67 | |
| 68 results_ = api::system_network::GetNetworkInterfaces::Results::Create( | |
| 69 create_arg); | |
| 70 SendResponse(true); | |
| 71 } | |
| 72 | |
| 73 } // namespace api | |
| 74 } // namespace extensions | |
| OLD | NEW |