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