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 "ppapi/proxy/network_list_resource.h" | |
| 6 | |
| 5 #include <algorithm> | 7 #include <algorithm> |
| 6 | 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/shared_impl/array_writer.h" | 11 #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/shared_impl/var.h" |
| 12 #include "ppapi/thunk/enter.h" | 13 #include "ppapi/thunk/enter.h" |
| 13 | 14 |
| 14 namespace ppapi { | 15 namespace ppapi { |
| 16 namespace proxy { | |
| 15 | 17 |
| 16 NetworkInfo::NetworkInfo() | 18 NetworkInfo::NetworkInfo() |
| 17 : type(PP_NETWORKLIST_UNKNOWN), | 19 : type(PP_NETWORKLIST_UNKNOWN), |
| 18 state(PP_NETWORKLIST_DOWN), | 20 state(PP_NETWORKLIST_DOWN), |
| 19 mtu(0) { | 21 mtu(0) { |
| 20 } | 22 } |
| 21 | 23 |
| 22 NetworkInfo::~NetworkInfo() { | 24 NetworkInfo::~NetworkInfo() {} |
| 23 } | |
| 24 | 25 |
| 25 NetworkListStorage::NetworkListStorage(const NetworkList& list) | 26 NetworkListResource::NetworkListResource(ResourceObjectType type, |
| 26 : list_(list) { | 27 PP_Instance instance, |
| 27 } | 28 const NetworkList& list) |
| 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), | 29 : Resource(type, instance), |
| 37 list_(list) { | 30 list_(list) { |
| 38 } | 31 } |
| 39 | 32 |
| 40 PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() { | 33 NetworkListResource::~NetworkListResource() {} |
| 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 | 34 |
| 53 ::ppapi::thunk::PPB_NetworkList_API* | 35 ::ppapi::thunk::PPB_NetworkList_API* |
|
yzshen1
2013/09/13 17:47:10
maybe we don't need ::ppapi?
Sergey Ulanov
2013/09/13 18:35:00
Done.
| |
| 54 PPB_NetworkList_Private_Shared::AsPPB_NetworkList_API() { | 36 NetworkListResource::AsPPB_NetworkList_API() { |
| 55 return this; | 37 return this; |
| 56 } | 38 } |
| 57 | 39 |
| 58 const NetworkList& PPB_NetworkList_Private_Shared::GetNetworkListData() const { | 40 uint32_t NetworkListResource::GetCount() { |
| 59 return list_->list(); | 41 return static_cast<uint32_t>(list_.size()); |
| 60 } | 42 } |
| 61 | 43 |
| 62 uint32_t PPB_NetworkList_Private_Shared::GetCount() { | 44 PP_Var NetworkListResource::GetName(uint32_t index) { |
| 63 return static_cast<uint32_t>(list_->list().size()); | 45 if (index >= list_.size()) |
| 46 return PP_MakeUndefined(); | |
| 47 return StringVar::StringToPPVar(list_.at(index).name); | |
| 64 } | 48 } |
| 65 | 49 |
| 66 PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) { | 50 PP_NetworkListType_Private NetworkListResource::GetType(uint32_t index) { |
| 67 if (index >= list_->list().size()) | 51 if (index >= list_.size()) |
| 68 return PP_MakeUndefined(); | 52 return PP_NETWORKLIST_UNKNOWN; |
| 69 return StringVar::StringToPPVar(list_->list().at(index).name); | 53 return list_.at(index).type; |
| 70 } | 54 } |
| 71 | 55 |
| 72 PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType( | 56 PP_NetworkListState_Private NetworkListResource::GetState(uint32_t index) { |
| 73 uint32_t index) { | 57 if (index >= list_.size()) |
| 74 if (index >= list_->list().size()) | 58 return PP_NETWORKLIST_DOWN; |
| 75 return PP_NETWORKLIST_UNKNOWN; | 59 return list_.at(index).state; |
| 76 return list_->list().at(index).type; | |
| 77 } | 60 } |
| 78 | 61 |
| 79 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState( | 62 int32_t NetworkListResource::GetIpAddresses(uint32_t index, |
| 80 uint32_t index) { | 63 const PP_ArrayOutput& output) { |
| 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); | 64 ArrayWriter writer(output); |
| 90 if (index >= list_->list().size() || !writer.is_valid()) | 65 if (index >= list_.size() || !writer.is_valid()) |
| 91 return PP_ERROR_BADARGUMENT; | 66 return PP_ERROR_BADARGUMENT; |
| 92 | 67 |
| 93 thunk::EnterResourceCreationNoLock enter(pp_instance()); | 68 thunk::EnterResourceCreationNoLock enter(pp_instance()); |
| 94 if (enter.failed()) | 69 if (enter.failed()) |
| 95 return PP_ERROR_FAILED; | 70 return PP_ERROR_FAILED; |
| 96 | 71 |
| 97 const std::vector<PP_NetAddress_Private>& addresses = | 72 const std::vector<PP_NetAddress_Private>& addresses = |
| 98 list_->list().at(index).addresses; | 73 list_.at(index).addresses; |
| 99 std::vector<PP_Resource> addr_resources; | 74 std::vector<PP_Resource> addr_resources; |
| 100 for (size_t i = 0; i < addresses.size(); ++i) { | 75 for (size_t i = 0; i < addresses.size(); ++i) { |
| 101 addr_resources.push_back( | 76 addr_resources.push_back( |
| 102 enter.functions()->CreateNetAddressFromNetAddressPrivate( | 77 enter.functions()->CreateNetAddressFromNetAddressPrivate( |
| 103 pp_instance(), addresses[i])); | 78 pp_instance(), addresses[i])); |
| 104 } | 79 } |
| 105 if (!writer.StoreResourceVector(addr_resources)) | 80 if (!writer.StoreResourceVector(addr_resources)) |
| 106 return PP_ERROR_FAILED; | 81 return PP_ERROR_FAILED; |
| 107 | 82 |
| 108 return PP_OK; | 83 return PP_OK; |
| 109 } | 84 } |
| 110 | 85 |
| 111 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) { | 86 PP_Var NetworkListResource::GetDisplayName(uint32_t index) { |
| 112 if (index >= list_->list().size()) | 87 if (index >= list_.size()) |
| 113 return PP_MakeUndefined(); | 88 return PP_MakeUndefined(); |
| 114 return StringVar::StringToPPVar(list_->list().at(index).display_name); | 89 return StringVar::StringToPPVar(list_.at(index).display_name); |
| 115 } | 90 } |
| 116 | 91 |
| 117 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) { | 92 uint32_t NetworkListResource::GetMTU(uint32_t index) { |
| 118 if (index >= list_->list().size()) | 93 if (index >= list_.size()) |
| 119 return 0; | 94 return 0; |
| 120 return list_->list().at(index).mtu; | 95 return list_.at(index).mtu; |
| 121 } | 96 } |
| 122 | 97 |
| 98 } // namespace proxy | |
| 123 } // namespace thunk | 99 } // namespace thunk |
| OLD | NEW |