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.
5 #include "extensions/browser/api/system_network/system_network_api.h"
8 const char kNetworkListError
[] = "Network lookup failed or unsupported";
11 namespace extensions
{
14 SystemNetworkGetNetworkInterfacesFunction::
15 SystemNetworkGetNetworkInterfacesFunction() {
18 SystemNetworkGetNetworkInterfacesFunction::
19 ~SystemNetworkGetNetworkInterfacesFunction() {
22 bool SystemNetworkGetNetworkInterfacesFunction::RunAsync() {
23 content::BrowserThread::PostTask(
24 content::BrowserThread::FILE,
27 &SystemNetworkGetNetworkInterfacesFunction::GetListOnFileThread
,
32 void SystemNetworkGetNetworkInterfacesFunction::GetListOnFileThread() {
33 net::NetworkInterfaceList interface_list
;
34 if (net::GetNetworkList(&interface_list
,
35 net::INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES
)) {
36 content::BrowserThread::PostTask(
37 content::BrowserThread::UI
,
40 &SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread
,
46 content::BrowserThread::PostTask(
47 content::BrowserThread::UI
,
49 base::Bind(&SystemNetworkGetNetworkInterfacesFunction::HandleGetListError
,
53 void SystemNetworkGetNetworkInterfacesFunction::HandleGetListError() {
54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
55 error_
= kNetworkListError
;
59 void SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread(
60 const net::NetworkInterfaceList
& interface_list
) {
61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
63 std::vector
<linked_ptr
<core_api::system_network::NetworkInterface
> >
65 create_arg
.reserve(interface_list
.size());
66 for (net::NetworkInterfaceList::const_iterator i
= interface_list
.begin();
67 i
!= interface_list
.end();
69 linked_ptr
<core_api::system_network::NetworkInterface
> info
=
70 make_linked_ptr(new core_api::system_network::NetworkInterface
);
72 info
->address
= net::IPAddressToString(i
->address
);
73 info
->prefix_length
= i
->prefix_length
;
74 create_arg
.push_back(info
);
77 results_
= core_api::system_network::GetNetworkInterfaces::Results::Create(
82 } // namespace core_api
83 } // namespace extensions