Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: extensions/browser/api/system_network/system_network_api.cc

Issue 389633002: Move system.* family of APIs to extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: No ash/ dependency anymore Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/system_network/system_network_api.h" 5 #include "extensions/browser/api/system_network/system_network_api.h"
6 6
7 namespace { 7 namespace {
8 const char kNetworkListError[] = "Network lookup failed or unsupported"; 8 const char kNetworkListError[] = "Network lookup failed or unsupported";
9 } // namespace 9 } // namespace
10 10
11 namespace extensions { 11 namespace extensions {
12 namespace api { 12 namespace core_api {
13 13
14 SystemNetworkGetNetworkInterfacesFunction:: 14 SystemNetworkGetNetworkInterfacesFunction::
15 SystemNetworkGetNetworkInterfacesFunction() {} 15 SystemNetworkGetNetworkInterfacesFunction() {
16 }
16 17
17 SystemNetworkGetNetworkInterfacesFunction:: 18 SystemNetworkGetNetworkInterfacesFunction::
18 ~SystemNetworkGetNetworkInterfacesFunction() {} 19 ~SystemNetworkGetNetworkInterfacesFunction() {
20 }
19 21
20 bool SystemNetworkGetNetworkInterfacesFunction::RunAsync() { 22 bool SystemNetworkGetNetworkInterfacesFunction::RunAsync() {
21 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, 23 content::BrowserThread::PostTask(
22 base::Bind(&SystemNetworkGetNetworkInterfacesFunction:: 24 content::BrowserThread::FILE,
23 GetListOnFileThread, 25 FROM_HERE,
26 base::Bind(
27 &SystemNetworkGetNetworkInterfacesFunction::GetListOnFileThread,
24 this)); 28 this));
25 return true; 29 return true;
26 } 30 }
27 31
28 void SystemNetworkGetNetworkInterfacesFunction::GetListOnFileThread() { 32 void SystemNetworkGetNetworkInterfacesFunction::GetListOnFileThread() {
29 net::NetworkInterfaceList interface_list; 33 net::NetworkInterfaceList interface_list;
30 if (net::GetNetworkList( 34 if (net::GetNetworkList(&interface_list,
31 &interface_list, net::INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES)) { 35 net::INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES)) {
32 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 36 content::BrowserThread::PostTask(
33 base::Bind(&SystemNetworkGetNetworkInterfacesFunction:: 37 content::BrowserThread::UI,
34 SendResponseOnUIThread, 38 FROM_HERE,
35 this, interface_list)); 39 base::Bind(
40 &SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread,
41 this,
42 interface_list));
36 return; 43 return;
37 } 44 }
38 45
39 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 46 content::BrowserThread::PostTask(
40 base::Bind(&SystemNetworkGetNetworkInterfacesFunction:: 47 content::BrowserThread::UI,
41 HandleGetListError, 48 FROM_HERE,
42 this)); 49 base::Bind(&SystemNetworkGetNetworkInterfacesFunction::HandleGetListError,
50 this));
43 } 51 }
44 52
45 void SystemNetworkGetNetworkInterfacesFunction::HandleGetListError() { 53 void SystemNetworkGetNetworkInterfacesFunction::HandleGetListError() {
46 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
47 error_ = kNetworkListError; 55 error_ = kNetworkListError;
48 SendResponse(false); 56 SendResponse(false);
49 } 57 }
50 58
51 void SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread( 59 void SystemNetworkGetNetworkInterfacesFunction::SendResponseOnUIThread(
52 const net::NetworkInterfaceList& interface_list) { 60 const net::NetworkInterfaceList& interface_list) {
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
54 62
55 std::vector<linked_ptr<api::system_network::NetworkInterface> > 63 std::vector<linked_ptr<core_api::system_network::NetworkInterface> >
56 create_arg; 64 create_arg;
57 create_arg.reserve(interface_list.size()); 65 create_arg.reserve(interface_list.size());
58 for (net::NetworkInterfaceList::const_iterator i = interface_list.begin(); 66 for (net::NetworkInterfaceList::const_iterator i = interface_list.begin();
59 i != interface_list.end(); ++i) { 67 i != interface_list.end();
60 linked_ptr<api::system_network::NetworkInterface> info = 68 ++i) {
61 make_linked_ptr(new api::system_network::NetworkInterface); 69 linked_ptr<core_api::system_network::NetworkInterface> info =
70 make_linked_ptr(new core_api::system_network::NetworkInterface);
62 info->name = i->name; 71 info->name = i->name;
63 info->address = net::IPAddressToString(i->address); 72 info->address = net::IPAddressToString(i->address);
64 info->prefix_length = i->network_prefix; 73 info->prefix_length = i->network_prefix;
65 create_arg.push_back(info); 74 create_arg.push_back(info);
66 } 75 }
67 76
68 results_ = api::system_network::GetNetworkInterfaces::Results::Create( 77 results_ = core_api::system_network::GetNetworkInterfaces::Results::Create(
69 create_arg); 78 create_arg);
70 SendResponse(true); 79 SendResponse(true);
71 } 80 }
72 81
73 } // namespace api 82 } // namespace core_api
74 } // namespace extensions 83 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698