Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / extensions / browser / api / system_network / system_network_api.cc
blobb6b6685804bb1a2a895bf2fb0552ef446f2ece99
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"
7 #include "net/base/ip_address_number.h"
9 namespace {
10 const char kNetworkListError[] = "Network lookup failed or unsupported";
11 } // namespace
13 namespace extensions {
14 namespace api {
16 SystemNetworkGetNetworkInterfacesFunction::
17 SystemNetworkGetNetworkInterfacesFunction() {
20 SystemNetworkGetNetworkInterfacesFunction::
21 ~SystemNetworkGetNetworkInterfacesFunction() {
24 bool SystemNetworkGetNetworkInterfacesFunction::RunAsync() {
25 content::BrowserThread::PostTask(
26 content::BrowserThread::FILE,
27 FROM_HERE,
28 base::Bind(
29 &SystemNetworkGetNetworkInterfacesFunction::GetListOnFileThread,
30 this));
31 return true;
34 void SystemNetworkGetNetworkInterfacesFunction::GetListOnFileThread() {
35 net::NetworkInterfaceList interface_list;
36 if (net::GetNetworkList(&interface_list,
37 net::INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES)) {
38 content::BrowserThread::PostTask(
39 content::BrowserThread::UI,
40 FROM_HERE,
41 base::Bind(
42 &SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread,
43 this,
44 interface_list));
45 return;
48 content::BrowserThread::PostTask(
49 content::BrowserThread::UI,
50 FROM_HERE,
51 base::Bind(&SystemNetworkGetNetworkInterfacesFunction::HandleGetListError,
52 this));
55 void SystemNetworkGetNetworkInterfacesFunction::HandleGetListError() {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 error_ = kNetworkListError;
58 SendResponse(false);
61 void SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread(
62 const net::NetworkInterfaceList& interface_list) {
63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
65 std::vector<linked_ptr<api::system_network::NetworkInterface>> create_arg;
66 create_arg.reserve(interface_list.size());
67 for (net::NetworkInterfaceList::const_iterator i = interface_list.begin();
68 i != interface_list.end();
69 ++i) {
70 linked_ptr<api::system_network::NetworkInterface> info =
71 make_linked_ptr(new api::system_network::NetworkInterface);
72 info->name = i->name;
73 info->address = net::IPAddressToString(i->address);
74 info->prefix_length = i->prefix_length;
75 create_arg.push_back(info);
78 results_ =
79 api::system_network::GetNetworkInterfaces::Results::Create(create_arg);
80 SendResponse(true);
83 } // namespace api
84 } // namespace extensions