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

Side by Side Diff: ppapi/cpp/network_list.cc

Issue 23450012: Make NetworkList and NetworkMonitor APIs public (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ppapi/cpp/private/network_list_private.h" 5 #include "ppapi/cpp/network_list.h"
6 6
7 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/cpp/array_output.h" 8 #include "ppapi/cpp/array_output.h"
9 #include "ppapi/cpp/logging.h" 9 #include "ppapi/cpp/logging.h"
10 #include "ppapi/cpp/module_impl.h" 10 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/net_address.h" 11 #include "ppapi/cpp/net_address.h"
12 #include "ppapi/cpp/var.h" 12 #include "ppapi/cpp/var.h"
13 13
14 namespace pp { 14 namespace pp {
15 15
16 namespace { 16 namespace {
17 17
18 template <> const char* interface_name<PPB_NetworkList_Private_0_3>() { 18 template <> const char* interface_name<PPB_NetworkList>() {
yzshen1 2013/09/19 07:56:12 Please append version number explicitly. (here and
Sergey Ulanov 2013/09/20 01:17:56 Done. Sorry, poorly executed merge.
19 return PPB_NETWORKLIST_PRIVATE_INTERFACE_0_3; 19 return PPB_NETWORKLIST_INTERFACE_1_0;
20 }
21
22 // Used in GetIpAddresses();
23 struct ResourceArray {
yzshen1 2013/09/19 07:56:12 This is not needed.
Sergey Ulanov 2013/09/20 01:17:56 Done.
24 PP_Resource* resources;
25 int count;
26 };
27
28 void* AllocateResourceArray(void* data, uint32_t count, uint32_t size) {
yzshen1 2013/09/19 07:56:12 This is not needed.
Sergey Ulanov 2013/09/20 01:17:56 Done.
29 ResourceArray* resource_array = reinterpret_cast<ResourceArray*>(data);
30 PP_DCHECK(size == sizeof(PP_Resource));
31 if (size) {
32 resource_array->resources = new PP_Resource[count];
33 if (resource_array->resources)
34 resource_array->count = count;
35 } else {
36 resource_array->resources = NULL;
37 }
38 return resource_array->resources;
20 } 39 }
21 40
22 } // namespace 41 } // namespace
23 42
24 NetworkListPrivate::NetworkListPrivate() { 43 NetworkList::NetworkList() {
25 } 44 }
26 45
27 NetworkListPrivate::NetworkListPrivate(PassRef, PP_Resource resource) 46 NetworkList::NetworkList(PassRef, PP_Resource resource)
28 : Resource(PASS_REF, resource) { 47 : Resource(PASS_REF, resource) {
29 } 48 }
30 49
31 // static 50 // static
32 bool NetworkListPrivate::IsAvailable() { 51 bool NetworkList::IsAvailable() {
33 return has_interface<PPB_NetworkList_Private_0_3>(); 52 return has_interface<PPB_NetworkList>();
34 } 53 }
35 54
36 uint32_t NetworkListPrivate::GetCount() const { 55 uint32_t NetworkList::GetCount() const {
37 if (!has_interface<PPB_NetworkList_Private_0_3>()) 56 if (!has_interface<PPB_NetworkList>())
38 return 0; 57 return 0;
39 return get_interface<PPB_NetworkList_Private_0_3>()->GetCount(pp_resource()); 58 return get_interface<PPB_NetworkList>()->GetCount(pp_resource());
40 } 59 }
41 60
42 std::string NetworkListPrivate::GetName(uint32_t index) const { 61 std::string NetworkList::GetName(uint32_t index) const {
43 if (!has_interface<PPB_NetworkList_Private_0_3>()) 62 if (!has_interface<PPB_NetworkList>())
44 return std::string(); 63 return std::string();
45 Var result(PASS_REF, 64 Var result(PASS_REF,
46 get_interface<PPB_NetworkList_Private_0_3>()->GetName( 65 get_interface<PPB_NetworkList>()->GetName(
47 pp_resource(), index)); 66 pp_resource(), index));
48 return result.is_string() ? result.AsString() : std::string(); 67 return result.is_string() ? result.AsString() : std::string();
49 } 68 }
50 69
51 PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) const { 70 PP_NetworkList_Type NetworkList::GetType(uint32_t index) const {
52 if (!has_interface<PPB_NetworkList_Private_0_3>()) 71 if (!has_interface<PPB_NetworkList>())
53 return PP_NETWORKLIST_ETHERNET; 72 return PP_NETWORKLIST_TYPE_ETHERNET;
54 return get_interface<PPB_NetworkList_Private_0_3>()->GetType( 73 return get_interface<PPB_NetworkList>()->GetType(
55 pp_resource(), index); 74 pp_resource(), index);
56 } 75 }
57 76
58 PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) const { 77 PP_NetworkList_State NetworkList::GetState(uint32_t index) const {
59 if (!has_interface<PPB_NetworkList_Private_0_3>()) 78 if (!has_interface<PPB_NetworkList>())
60 return PP_NETWORKLIST_DOWN; 79 return PP_NETWORKLIST_STATE_DOWN;
61 return get_interface<PPB_NetworkList_Private_0_3>()->GetState( 80 return get_interface<PPB_NetworkList>()->GetState(
62 pp_resource(), index); 81 pp_resource(), index);
63 } 82 }
64 83
65 int32_t NetworkListPrivate::GetIpAddresses( 84 int32_t NetworkList::GetIpAddresses(
66 uint32_t index, 85 uint32_t index,
67 std::vector<NetAddress>* addresses) const { 86 std::vector<NetAddress>* addresses) const {
68 if (!has_interface<PPB_NetworkList_Private_0_3>()) 87 if (!has_interface<PPB_NetworkList_1_0>())
69 return PP_ERROR_NOINTERFACE; 88 return PP_ERROR_NOINTERFACE;
70 if (!addresses) 89 if (!addresses)
71 return PP_ERROR_BADARGUMENT; 90 return PP_ERROR_BADARGUMENT;
72 91
73 ResourceArrayOutputAdapter<NetAddress> adapter(addresses); 92 ResourceArrayOutputAdapter<NetAddress> adapter(addresses);
74 return get_interface<PPB_NetworkList_Private_0_3>()->GetIpAddresses( 93 return get_interface<PPB_NetworkList_1_0>()->GetIpAddresses(
75 pp_resource(), index, adapter.pp_array_output()); 94 pp_resource(), index, adapter.pp_array_output());
76 } 95 }
77 96
78 std::string NetworkListPrivate::GetDisplayName(uint32_t index) const { 97 std::string NetworkList::GetDisplayName(uint32_t index) const {
79 if (!has_interface<PPB_NetworkList_Private_0_3>()) 98 if (!has_interface<PPB_NetworkList>())
80 return std::string(); 99 return std::string();
81 Var result(PASS_REF, 100 Var result(PASS_REF,
82 get_interface<PPB_NetworkList_Private_0_3>()->GetDisplayName( 101 get_interface<PPB_NetworkList>()->GetDisplayName(
83 pp_resource(), index)); 102 pp_resource(), index));
84 return result.is_string() ? result.AsString() : std::string(); 103 return result.is_string() ? result.AsString() : std::string();
85 } 104 }
86 105
87 uint32_t NetworkListPrivate::GetMTU(uint32_t index) const { 106 uint32_t NetworkList::GetMTU(uint32_t index) const {
88 if (!has_interface<PPB_NetworkList_Private_0_3>()) 107 if (!has_interface<PPB_NetworkList>())
89 return 0; 108 return 0;
90 return get_interface<PPB_NetworkList_Private_0_3>()->GetMTU( 109 return get_interface<PPB_NetworkList>()->GetMTU(
91 pp_resource(), index); 110 pp_resource(), index);
92 } 111 }
93 112
94 } // namespace pp 113 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698