Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "ppapi/thunk/enter.h" | |
| 11 | 12 |
| 12 namespace ppapi { | 13 namespace ppapi { |
| 13 | 14 |
| 14 NetworkInfo::NetworkInfo() | 15 NetworkInfo::NetworkInfo() |
| 15 : type(PP_NETWORKLIST_UNKNOWN), | 16 : type(PP_NETWORKLIST_UNKNOWN), |
| 16 state(PP_NETWORKLIST_DOWN), | 17 state(PP_NETWORKLIST_DOWN), |
| 17 mtu(0) { | 18 mtu(0) { |
| 18 } | 19 } |
| 19 | 20 |
| 20 NetworkInfo::~NetworkInfo() { | 21 NetworkInfo::~NetworkInfo() { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 | 77 |
| 77 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState( | 78 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState( |
| 78 uint32_t index) { | 79 uint32_t index) { |
| 79 if (index >= list_->list().size()) | 80 if (index >= list_->list().size()) |
| 80 return PP_NETWORKLIST_DOWN; | 81 return PP_NETWORKLIST_DOWN; |
| 81 return list_->list().at(index).state; | 82 return list_->list().at(index).state; |
| 82 } | 83 } |
| 83 | 84 |
| 84 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses( | 85 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses( |
| 85 uint32_t index, | 86 uint32_t index, |
| 86 struct PP_NetAddress_Private addresses[], | 87 const PP_ArrayOutput& output) { |
| 87 uint32_t count) { | |
| 88 if (index >= list_->list().size()) | 88 if (index >= list_->list().size()) |
| 89 return PP_ERROR_FAILED; | 89 return PP_ERROR_FAILED; |
| 90 count = std::min( | 90 |
| 91 count, static_cast<uint32_t>(list_->list().at(index).addresses.size())); | 91 thunk::EnterResourceCreationNoLock enter(pp_instance()); |
| 92 memcpy(addresses, &(list_->list().at(index).addresses[0]), | 92 if (enter.failed()) |
| 93 sizeof(PP_NetAddress_Private) * count); | 93 return PP_ERROR_FAILED; |
| 94 return static_cast<int32_t>(list_->list().at(index).addresses.size()); | 94 |
| 95 const std::vector<PP_NetAddress_Private>& addresses = | |
| 96 list_->list().at(index).addresses; | |
| 97 PP_Resource* address_resources = | |
|
yzshen1
2013/09/03 17:47:32
It is preferred to use ArrayWriter, IMO.
Here is o
Sergey Ulanov
2013/09/03 23:42:54
Done.
| |
| 98 reinterpret_cast<PP_Resource*>(output.GetDataBuffer( | |
| 99 output.user_data, static_cast<uint32_t>(addresses.size()), | |
| 100 sizeof(PP_Resource))); | |
| 101 if (!address_resources) | |
| 102 return PP_ERROR_NOMEMORY; | |
| 103 | |
| 104 for (size_t i = 0; i < addresses.size(); ++i) { | |
| 105 address_resources[i] = | |
| 106 enter.functions()->CreateNetAddressFromNetAddressPrivate( | |
| 107 pp_instance(), addresses[i]); | |
| 108 } | |
| 109 | |
| 110 return PP_OK; | |
| 95 } | 111 } |
| 96 | 112 |
| 97 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) { | 113 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) { |
| 98 if (index >= list_->list().size()) | 114 if (index >= list_->list().size()) |
| 99 return PP_MakeUndefined(); | 115 return PP_MakeUndefined(); |
| 100 return StringVar::StringToPPVar(list_->list().at(index).display_name); | 116 return StringVar::StringToPPVar(list_->list().at(index).display_name); |
| 101 } | 117 } |
| 102 | 118 |
| 103 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) { | 119 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) { |
| 104 if (index >= list_->list().size()) | 120 if (index >= list_->list().size()) |
| 105 return 0; | 121 return 0; |
| 106 return list_->list().at(index).mtu; | 122 return list_->list().at(index).mtu; |
| 107 } | 123 } |
| 108 | 124 |
| 109 } // namespace thunk | 125 } // namespace thunk |
| OLD | NEW |