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

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

Issue 9677060: Out-of-process implementation of the PPB_NetworkMonitor_Private interface. (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
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ppapi/c/pp_errors.h" 8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/shared_impl/ppb_network_list_private_shared.h" 9 #include "ppapi/shared_impl/ppb_network_list_private_shared.h"
10 #include "ppapi/shared_impl/var.h" 10 #include "ppapi/shared_impl/var.h"
11 11
12 namespace ppapi { 12 namespace ppapi {
13 13
14 PPB_NetworkList_Private_Shared::NetworkInfo::NetworkInfo() 14 NetworkInfo::NetworkInfo()
15 : type(PP_NETWORKLIST_UNKNOWN), 15 : type(PP_NETWORKLIST_UNKNOWN),
16 state(PP_NETWORKLIST_DOWN), 16 state(PP_NETWORKLIST_DOWN),
17 mtu(0) { 17 mtu(0) {
18 } 18 }
19 19
20 PPB_NetworkList_Private_Shared::NetworkInfo::~NetworkInfo() { 20 NetworkInfo::~NetworkInfo() {
21 }
22
23 NetworkListStorage::NetworkListStorage(const NetworkList& list)
24 : list_(list) {
25 }
26
27 NetworkListStorage::~NetworkListStorage() {
21 } 28 }
22 29
23 PPB_NetworkList_Private_Shared::PPB_NetworkList_Private_Shared( 30 PPB_NetworkList_Private_Shared::PPB_NetworkList_Private_Shared(
24 ResourceObjectType type, 31 ResourceObjectType type,
25 PP_Instance instance, 32 PP_Instance instance,
26 scoped_ptr<NetworkList> list) 33 const scoped_refptr<NetworkListStorage>& list)
27 : Resource(type, instance), 34 : Resource(type, instance),
28 list_(list.Pass()) { 35 list_(list) {
29 } 36 }
30 37
31 PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() { 38 PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() {
32 } 39 }
33 40
34 // static 41 // static
35 PP_Resource PPB_NetworkList_Private_Shared::Create( 42 PP_Resource PPB_NetworkList_Private_Shared::Create(
36 ResourceObjectType type, 43 ResourceObjectType type,
37 PP_Instance instance, 44 PP_Instance instance,
38 scoped_ptr<NetworkList> list) { 45 const scoped_refptr<NetworkListStorage>& list) {
39 scoped_refptr<PPB_NetworkList_Private_Shared> object( 46 scoped_refptr<PPB_NetworkList_Private_Shared> object(
40 new PPB_NetworkList_Private_Shared(type, instance, list.Pass())); 47 new PPB_NetworkList_Private_Shared(type, instance, list));
41 return object->GetReference(); 48 return object->GetReference();
42 } 49 }
43 50
44 ::ppapi::thunk::PPB_NetworkList_Private_API* 51 ::ppapi::thunk::PPB_NetworkList_Private_API*
45 PPB_NetworkList_Private_Shared::AsPPB_NetworkList_Private_API() { 52 PPB_NetworkList_Private_Shared::AsPPB_NetworkList_Private_API() {
46 return this; 53 return this;
47 } 54 }
48 55
56 const NetworkList& PPB_NetworkList_Private_Shared::GetNetworkListData() const {
57 return list_->list();
58 }
59
49 uint32_t PPB_NetworkList_Private_Shared::GetCount() { 60 uint32_t PPB_NetworkList_Private_Shared::GetCount() {
50 return list_->size(); 61 return list_->list().size();
51 } 62 }
52 63
53 PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) { 64 PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) {
54 if (index >= list_->size()) 65 if (index >= list_->list().size())
55 return PP_MakeUndefined(); 66 return PP_MakeUndefined();
56 return StringVar::StringToPPVar(list_->at(index).name); 67 return StringVar::StringToPPVar(list_->list().at(index).name);
57 } 68 }
58 69
59 PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType( 70 PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType(
60 uint32_t index) { 71 uint32_t index) {
61 if (index >= list_->size()) 72 if (index >= list_->list().size())
62 return PP_NETWORKLIST_UNKNOWN; 73 return PP_NETWORKLIST_UNKNOWN;
63 return list_->at(index).type; 74 return list_->list().at(index).type;
64 } 75 }
65 76
66 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState( 77 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState(
67 uint32_t index) { 78 uint32_t index) {
68 if (index >= list_->size()) 79 if (index >= list_->list().size())
69 return PP_NETWORKLIST_DOWN; 80 return PP_NETWORKLIST_DOWN;
70 return list_->at(index).state; 81 return list_->list().at(index).state;
71 } 82 }
72 83
73 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses( 84 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses(
74 uint32_t index, 85 uint32_t index,
75 struct PP_NetAddress_Private addresses[], 86 struct PP_NetAddress_Private addresses[],
76 uint32_t count) { 87 uint32_t count) {
77 if (index >= list_->size()) 88 if (index >= list_->list().size())
78 return PP_ERROR_FAILED; 89 return PP_ERROR_FAILED;
79 count = std::min( 90 count = std::min(
80 count, static_cast<uint32_t>(list_->at(index).addresses.size())); 91 count, static_cast<uint32_t>(list_->list().at(index).addresses.size()));
81 memcpy(addresses, &(list_->at(index).addresses[0]), 92 memcpy(addresses, &(list_->list().at(index).addresses[0]),
82 sizeof(PP_NetAddress_Private) * count); 93 sizeof(PP_NetAddress_Private) * count);
83 return list_->at(index).addresses.size(); 94 return list_->list().at(index).addresses.size();
84 } 95 }
85 96
86 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) { 97 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) {
87 if (index >= list_->size()) 98 if (index >= list_->list().size())
88 return PP_MakeUndefined(); 99 return PP_MakeUndefined();
89 return StringVar::StringToPPVar(list_->at(index).display_name); 100 return StringVar::StringToPPVar(list_->list().at(index).display_name);
90 } 101 }
91 102
92 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) { 103 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) {
93 if (index >= list_->size()) 104 if (index >= list_->list().size())
94 return 0; 105 return 0;
95 return list_->at(index).mtu; 106 return list_->list().at(index).mtu;
96 } 107 }
97 108
98 } // namespace thunk 109 } // namespace thunk
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_network_list_private_shared.h ('k') | ppapi/tests/test_network_monitor_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698