Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / extensions / browser / api / system_network / system_network_api.cc
blob8cba5b7616c299a3f76c4baa53fcaa2cd5c0c8ba
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 core_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<core_api::system_network::NetworkInterface> >
66 create_arg;
67 create_arg.reserve(interface_list.size());
68 for (net::NetworkInterfaceList::const_iterator i = interface_list.begin();
69 i != interface_list.end();
70 ++i) {
71 linked_ptr<core_api::system_network::NetworkInterface> info =
72 make_linked_ptr(new core_api::system_network::NetworkInterface);
73 info->name = i->name;
74 info->address = net::IPAddressToString(i->address);
75 info->prefix_length = i->prefix_length;
76 create_arg.push_back(info);
79 results_ = core_api::system_network::GetNetworkInterfaces::Results::Create(
80 create_arg);
81 SendResponse(true);
84 } // namespace core_api
85 } // namespace extensions