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/ppb_network_list_private_shared.h" | |
10 #include "ppapi/shared_impl/var.h" | |
11 | |
12 namespace ppapi { | |
13 | |
14 PPB_NetworkList_Private_Shared::NetworkInfo::NetworkInfo() { | |
dmichael (off chromium)
2012/03/02 16:43:12
You should probably initialize type, state, and mt
Sergey Ulanov
2012/03/02 18:43:03
Done.
| |
15 } | |
16 | |
17 PPB_NetworkList_Private_Shared::NetworkInfo::~NetworkInfo() { | |
18 } | |
19 | |
20 PPB_NetworkList_Private_Shared::PPB_NetworkList_Private_Shared( | |
21 ResourceObjectType type, | |
22 PP_Instance instance, | |
23 scoped_ptr<NetworkList> list) | |
24 : Resource(type, instance), | |
25 list_(list.Pass()) { | |
26 } | |
27 | |
28 PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() { | |
29 } | |
30 | |
31 // static | |
32 PP_Resource PPB_NetworkList_Private_Shared::Create( | |
33 ResourceObjectType type, | |
34 PP_Instance instance, | |
35 scoped_ptr<NetworkList> list) { | |
36 scoped_refptr<PPB_NetworkList_Private_Shared> object( | |
37 new PPB_NetworkList_Private_Shared(type, instance, list.Pass())); | |
38 return object->GetReference(); | |
39 } | |
40 | |
41 ::ppapi::thunk::PPB_NetworkList_Private_API* | |
42 PPB_NetworkList_Private_Shared::AsPPB_NetworkList_Private_API() { | |
43 return this; | |
44 } | |
45 | |
46 uint32_t PPB_NetworkList_Private_Shared::GetCount() { | |
47 return list_->size(); | |
48 } | |
49 | |
50 PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) { | |
51 if (index >= list_->size()) | |
52 return PP_MakeUndefined(); | |
53 return StringVar::StringToPPVar(list_->at(index).name); | |
54 } | |
55 | |
56 PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType( | |
57 uint32_t index) { | |
58 if (index >= list_->size()) | |
59 return PP_NETWORKLIST_UNKNOWN; | |
60 return list_->at(index).type; | |
61 } | |
62 | |
63 PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState( | |
64 uint32_t index) { | |
65 if (index >= list_->size()) | |
66 return PP_NETWORKLIST_DOWN; | |
67 return list_->at(index).state; | |
68 } | |
69 | |
70 int32_t PPB_NetworkList_Private_Shared::GetIpAddresses( | |
71 uint32_t index, | |
72 struct PP_NetAddress_Private addresses[], | |
73 uint32_t count) { | |
74 if (index >= list_->size()) | |
75 return PP_ERROR_FAILED; | |
76 count = std::min( | |
77 count, static_cast<uint32_t>(list_->at(index).addresses.size())); | |
78 memcpy(addresses, &(list_->at(index).addresses[0]), | |
79 sizeof(PP_NetAddress_Private) * count); | |
80 return count; | |
dmichael (off chromium)
2012/03/02 16:43:12
If the caller passes a count less than the total a
Sergey Ulanov
2012/03/02 18:43:03
Done. Thanks for catching this!
| |
81 } | |
82 | |
83 PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) { | |
84 if (index >= list_->size()) | |
85 return PP_MakeUndefined(); | |
86 return StringVar::StringToPPVar(list_->at(index).display_name); | |
87 } | |
88 | |
89 uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) { | |
90 if (index >= list_->size()) | |
91 return PP_NETWORKLIST_UNKNOWN; | |
dmichael (off chromium)
2012/03/02 16:43:12
This enum doesn't seem right here, since we're not
Sergey Ulanov
2012/03/02 18:43:03
Done.
| |
92 return list_->at(index).mtu; | |
93 } | |
94 | |
95 } // namespace thunk | |
OLD | NEW |