Reland the ULONG -> SIZE_T change from 317177
[chromium-blink-merge.git] / extensions / browser / api / system_network / system_network_api.cc
blob59445f8ce0d09e749722d5b035b47af160571097
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 namespace {
8 const char kNetworkListError[] = "Network lookup failed or unsupported";
9 } // namespace
11 namespace extensions {
12 namespace core_api {
14 SystemNetworkGetNetworkInterfacesFunction::
15 SystemNetworkGetNetworkInterfacesFunction() {
18 SystemNetworkGetNetworkInterfacesFunction::
19 ~SystemNetworkGetNetworkInterfacesFunction() {
22 bool SystemNetworkGetNetworkInterfacesFunction::RunAsync() {
23 content::BrowserThread::PostTask(
24 content::BrowserThread::FILE,
25 FROM_HERE,
26 base::Bind(
27 &SystemNetworkGetNetworkInterfacesFunction::GetListOnFileThread,
28 this));
29 return true;
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,
38 FROM_HERE,
39 base::Bind(
40 &SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread,
41 this,
42 interface_list));
43 return;
46 content::BrowserThread::PostTask(
47 content::BrowserThread::UI,
48 FROM_HERE,
49 base::Bind(&SystemNetworkGetNetworkInterfacesFunction::HandleGetListError,
50 this));
53 void SystemNetworkGetNetworkInterfacesFunction::HandleGetListError() {
54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
55 error_ = kNetworkListError;
56 SendResponse(false);
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> >
64 create_arg;
65 create_arg.reserve(interface_list.size());
66 for (net::NetworkInterfaceList::const_iterator i = interface_list.begin();
67 i != interface_list.end();
68 ++i) {
69 linked_ptr<core_api::system_network::NetworkInterface> info =
70 make_linked_ptr(new core_api::system_network::NetworkInterface);
71 info->name = i->name;
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(
78 create_arg);
79 SendResponse(true);
82 } // namespace core_api
83 } // namespace extensions