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

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

Issue 23806003: Use PP_ArrayOutput and PPB_NetAddress in PPB_NetworkList_Private.. (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 <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/array_writer.h"
9 #include "ppapi/shared_impl/ppb_network_list_private_shared.h" 10 #include "ppapi/shared_impl/ppb_network_list_private_shared.h"
10 #include "ppapi/shared_impl/var.h" 11 #include "ppapi/shared_impl/var.h"
12 #include "ppapi/thunk/enter.h"
11 13
12 namespace ppapi { 14 namespace ppapi {
13 15
14 NetworkInfo::NetworkInfo() 16 NetworkInfo::NetworkInfo()
15 : type(PP_NETWORKLIST_UNKNOWN), 17 : type(PP_NETWORKLIST_UNKNOWN),
16 state(PP_NETWORKLIST_DOWN), 18 state(PP_NETWORKLIST_DOWN),
17 mtu(0) { 19 mtu(0) {
18 } 20 }
19 21
20 NetworkInfo::~NetworkInfo() { 22 NetworkInfo::~NetworkInfo() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 78
77 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState( 79 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState(
78 uint32_t index) { 80 uint32_t index) {
79 if (index >= list_->list().size()) 81 if (index >= list_->list().size())
80 return PP_NETWORKLIST_DOWN; 82 return PP_NETWORKLIST_DOWN;
81 return list_->list().at(index).state; 83 return list_->list().at(index).state;
82 } 84 }
83 85
84 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses( 86 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses(
85 uint32_t index, 87 uint32_t index,
86 struct PP_NetAddress_Private addresses[], 88 const PP_ArrayOutput& output) {
87 uint32_t count) { 89 ArrayWriter writer(output);
88 if (index >= list_->list().size()) 90 if (index >= list_->list().size() || !writer.is_valid())
91 return PP_ERROR_BADARGUMENT;
92
93 thunk::EnterResourceCreationNoLock enter(pp_instance());
94 if (enter.failed())
89 return PP_ERROR_FAILED; 95 return PP_ERROR_FAILED;
90 count = std::min( 96
91 count, static_cast<uint32_t>(list_->list().at(index).addresses.size())); 97 const std::vector<PP_NetAddress_Private>& addresses =
92 memcpy(addresses, &(list_->list().at(index).addresses[0]), 98 list_->list().at(index).addresses;
93 sizeof(PP_NetAddress_Private) * count); 99 std::vector<PP_Resource> addr_resources;
94 return static_cast<int32_t>(list_->list().at(index).addresses.size()); 100 for (size_t i = 0; i < addresses.size(); ++i) {
101 addr_resources.push_back(
102 enter.functions()->CreateNetAddressFromNetAddressPrivate(
103 pp_instance(), addresses[i]));
104 }
105 if (!writer.StoreResourceVector(addr_resources))
106 return PP_ERROR_FAILED;
107
108 return PP_OK;
95 } 109 }
96 110
97 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) { 111 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) {
98 if (index >= list_->list().size()) 112 if (index >= list_->list().size())
99 return PP_MakeUndefined(); 113 return PP_MakeUndefined();
100 return StringVar::StringToPPVar(list_->list().at(index).display_name); 114 return StringVar::StringToPPVar(list_->list().at(index).display_name);
101 } 115 }
102 116
103 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) { 117 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) {
104 if (index >= list_->list().size()) 118 if (index >= list_->list().size())
105 return 0; 119 return 0;
106 return list_->list().at(index).mtu; 120 return list_->list().at(index).mtu;
107 } 121 }
108 122
109 } // namespace thunk 123 } // namespace thunk
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_network_list_private_shared.h ('k') | ppapi/tests/test_network_monitor_private.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698