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

Side by Side Diff: ppapi/shared_impl/ppb_network_list_private_shared.cc

Issue 9545010: Add NetworkList/NetworkMonitor hooks and C++ wrappers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 9 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
« no previous file with comments | « ppapi/shared_impl/ppb_network_list_private_shared.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <algorithm>
6
7 #include "base/logging.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/shared_impl/ppb_network_list_private_shared.h"
10 #include "ppapi/shared_impl/var.h"
11
12 namespace ppapi {
13
14 PPB_NetworkList_Private_Shared::NetworkInfo::NetworkInfo()
15 : type(PP_NETWORKLIST_UNKNOWN),
16 state(PP_NETWORKLIST_DOWN),
17 mtu(0) {
18 }
19
20 PPB_NetworkList_Private_Shared::NetworkInfo::~NetworkInfo() {
21 }
22
23 PPB_NetworkList_Private_Shared::PPB_NetworkList_Private_Shared(
24 ResourceObjectType type,
25 PP_Instance instance,
26 scoped_ptr<NetworkList> list)
27 : Resource(type, instance),
28 list_(list.Pass()) {
29 }
30
31 PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() {
32 }
33
34 // static
35 PP_Resource PPB_NetworkList_Private_Shared::Create(
36 ResourceObjectType type,
37 PP_Instance instance,
38 scoped_ptr<NetworkList> list) {
39 scoped_refptr<PPB_NetworkList_Private_Shared> object(
40 new PPB_NetworkList_Private_Shared(type, instance, list.Pass()));
41 return object->GetReference();
42 }
43
44 ::ppapi::thunk::PPB_NetworkList_Private_API*
45 PPB_NetworkList_Private_Shared::AsPPB_NetworkList_Private_API() {
46 return this;
47 }
48
49 uint32_t PPB_NetworkList_Private_Shared::GetCount() {
50 return list_->size();
51 }
52
53 PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) {
54 if (index >= list_->size())
55 return PP_MakeUndefined();
56 return StringVar::StringToPPVar(list_->at(index).name);
57 }
58
59 PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType(
60 uint32_t index) {
61 if (index >= list_->size())
62 return PP_NETWORKLIST_UNKNOWN;
63 return list_->at(index).type;
64 }
65
66 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState(
67 uint32_t index) {
68 if (index >= list_->size())
69 return PP_NETWORKLIST_DOWN;
70 return list_->at(index).state;
71 }
72
73 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses(
74 uint32_t index,
75 struct PP_NetAddress_Private addresses[],
76 uint32_t count) {
77 if (index >= list_->size())
78 return PP_ERROR_FAILED;
79 count = std::min(
80 count, static_cast<uint32_t>(list_->at(index).addresses.size()));
81 memcpy(addresses, &(list_->at(index).addresses[0]),
82 sizeof(PP_NetAddress_Private) * count);
83 return list_->at(index).addresses.size();
84 }
85
86 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) {
87 if (index >= list_->size())
88 return PP_MakeUndefined();
89 return StringVar::StringToPPVar(list_->at(index).display_name);
90 }
91
92 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) {
93 if (index >= list_->size())
94 return 0;
95 return list_->at(index).mtu;
96 }
97
98 } // namespace thunk
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_network_list_private_shared.h ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698