| OLD | NEW |
| (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/array_writer.h" | |
| 10 #include "ppapi/shared_impl/ppb_network_list_private_shared.h" | |
| 11 #include "ppapi/shared_impl/var.h" | |
| 12 #include "ppapi/thunk/enter.h" | |
| 13 | |
| 14 namespace ppapi { | |
| 15 | |
| 16 NetworkInfo::NetworkInfo() | |
| 17 : type(PP_NETWORKLIST_UNKNOWN), | |
| 18 state(PP_NETWORKLIST_DOWN), | |
| 19 mtu(0) { | |
| 20 } | |
| 21 | |
| 22 NetworkInfo::~NetworkInfo() { | |
| 23 } | |
| 24 | |
| 25 NetworkListStorage::NetworkListStorage(const NetworkList& list) | |
| 26 : list_(list) { | |
| 27 } | |
| 28 | |
| 29 NetworkListStorage::~NetworkListStorage() { | |
| 30 } | |
| 31 | |
| 32 PPB_NetworkList_Private_Shared::PPB_NetworkList_Private_Shared( | |
| 33 ResourceObjectType type, | |
| 34 PP_Instance instance, | |
| 35 const scoped_refptr<NetworkListStorage>& list) | |
| 36 : Resource(type, instance), | |
| 37 list_(list) { | |
| 38 } | |
| 39 | |
| 40 PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() { | |
| 41 } | |
| 42 | |
| 43 // static | |
| 44 PP_Resource PPB_NetworkList_Private_Shared::Create( | |
| 45 ResourceObjectType type, | |
| 46 PP_Instance instance, | |
| 47 const scoped_refptr<NetworkListStorage>& list) { | |
| 48 scoped_refptr<PPB_NetworkList_Private_Shared> object( | |
| 49 new PPB_NetworkList_Private_Shared(type, instance, list)); | |
| 50 return object->GetReference(); | |
| 51 } | |
| 52 | |
| 53 ::ppapi::thunk::PPB_NetworkList_API* | |
| 54 PPB_NetworkList_Private_Shared::AsPPB_NetworkList_API() { | |
| 55 return this; | |
| 56 } | |
| 57 | |
| 58 const NetworkList& PPB_NetworkList_Private_Shared::GetNetworkListData() const { | |
| 59 return list_->list(); | |
| 60 } | |
| 61 | |
| 62 uint32_t PPB_NetworkList_Private_Shared::GetCount() { | |
| 63 return static_cast<uint32_t>(list_->list().size()); | |
| 64 } | |
| 65 | |
| 66 PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) { | |
| 67 if (index >= list_->list().size()) | |
| 68 return PP_MakeUndefined(); | |
| 69 return StringVar::StringToPPVar(list_->list().at(index).name); | |
| 70 } | |
| 71 | |
| 72 PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType( | |
| 73 uint32_t index) { | |
| 74 if (index >= list_->list().size()) | |
| 75 return PP_NETWORKLIST_UNKNOWN; | |
| 76 return list_->list().at(index).type; | |
| 77 } | |
| 78 | |
| 79 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState( | |
| 80 uint32_t index) { | |
| 81 if (index >= list_->list().size()) | |
| 82 return PP_NETWORKLIST_DOWN; | |
| 83 return list_->list().at(index).state; | |
| 84 } | |
| 85 | |
| 86 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses( | |
| 87 uint32_t index, | |
| 88 const PP_ArrayOutput& output) { | |
| 89 ArrayWriter writer(output); | |
| 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()) | |
| 95 return PP_ERROR_FAILED; | |
| 96 | |
| 97 const std::vector<PP_NetAddress_Private>& addresses = | |
| 98 list_->list().at(index).addresses; | |
| 99 std::vector<PP_Resource> addr_resources; | |
| 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; | |
| 109 } | |
| 110 | |
| 111 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) { | |
| 112 if (index >= list_->list().size()) | |
| 113 return PP_MakeUndefined(); | |
| 114 return StringVar::StringToPPVar(list_->list().at(index).display_name); | |
| 115 } | |
| 116 | |
| 117 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) { | |
| 118 if (index >= list_->list().size()) | |
| 119 return 0; | |
| 120 return list_->list().at(index).mtu; | |
| 121 } | |
| 122 | |
| 123 } // namespace thunk | |
| OLD | NEW |