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

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
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::PPB_NetworkList_Private_Shared(
15 ResourceObjectType type,
16 PP_Instance instance,
17 scoped_ptr<net::NetworkInterfaceList> list)
18 : Resource(type, instance),
19 list_(list.Pass()) {
20 }
21
22 PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() {
23 }
24
25 // static
26 PP_Resource PPB_NetworkList_Private_Shared::Create(
27 ResourceObjectType type,
28 PP_Instance instance,
29 scoped_ptr<net::NetworkInterfaceList> list) {
30 scoped_refptr<PPB_NetworkList_Private_Shared> object(
31 new PPB_NetworkList_Private_Shared(type, instance, list.Pass()));
32 return object->GetReference();
33 }
34
35 ::ppapi::thunk::PPB_NetworkList_Private_API*
36 PPB_NetworkList_Private_Shared::AsPPB_NetworkList_Private_API() {
37 return this;
38 }
39
40 uint32_t PPB_NetworkList_Private_Shared::GetCount() {
41 return list_->size();
42 }
43
44 PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) {
45 if (index >= list_->size())
46 return StringVar::StringToPPVar("");
dmichael (off chromium) 2012/03/01 18:29:54 you might consider returning an Undefined Var to s
Sergey Ulanov 2012/03/02 03:01:37 Done.
47 return StringVar::StringToPPVar(list_->at(index).name);
48 }
49
50 PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType(
51 uint32_t index) {
52 // NetworkInterface struct doesn't privide this information yet.
53 NOTIMPLEMENTED();
54 return PP_NETWORKLIST_UNKNOWN;
55 }
56
57 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState(
58 uint32_t index) {
59 // Currently we get only interfaces that are active.
dmichael (off chromium) 2012/03/01 18:29:54 Then it doesn't really need to be an error conditi
Sergey Ulanov 2012/03/02 03:01:37 Done.
60 NOTIMPLEMENTED();
61 return PP_NETWORKLIST_UP;
62 }
63
64 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses(
65 uint32_t index,
66 struct PP_NetAddress_Private addresses[],
67 uint32_t count) {
68 if (index >= list_->size())
69 return PP_ERROR_FAILED;
70
71 // Currently we get only one address for each interface.
72 if (count >= 1) {
73 DCHECK_LE(list_->at(index).address.size(), sizeof(addresses[0].data));
74 addresses[0].size = list_->at(index).address.size();
75 memcpy(addresses[0].data, &(list_->at(index).address.front()),
dmichael (off chromium) 2012/03/01 18:29:54 You should probably return early if the address do
Sergey Ulanov 2012/03/02 03:01:37 Removed this code from this CL - will add it back
76 addresses[0].size);
77 }
78 return 1;
79 }
80
81 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) {
82 if (index >= list_->size())
83 return StringVar::StringToPPVar("");
dmichael (off chromium) 2012/03/01 18:29:54 It's probably better to return PP_MakeUndefined()
Sergey Ulanov 2012/03/02 03:01:37 Done.
84 // NetworkInterface struct doesn't contain display name yet.
85 NOTIMPLEMENTED();
86 return StringVar::StringToPPVar(list_->at(index).name);
87 }
88
89 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) {
90 if (index >= list_->size())
91 return 0;
92 // NetworkInterface struct doesn't contain MTU yet.
93 NOTIMPLEMENTED();
94 return 0;
95 }
96
97 } // namespace thunk
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698