Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ppapi / proxy / network_list_resource.cc
blob466e533daf79432e70cfe0b47e2bbdf37c604344
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.
5 #include "ppapi/proxy/network_list_resource.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/shared_impl/array_writer.h"
12 #include "ppapi/shared_impl/var.h"
13 #include "ppapi/thunk/enter.h"
15 namespace ppapi {
16 namespace proxy {
18 NetworkListResource::NetworkListResource(PP_Instance instance,
19 const SerializedNetworkList& list)
20 : Resource(OBJECT_IS_PROXY, instance),
21 list_(list) {
24 NetworkListResource::~NetworkListResource() {}
26 thunk::PPB_NetworkList_API* NetworkListResource::AsPPB_NetworkList_API() {
27 return this;
30 uint32_t NetworkListResource::GetCount() {
31 return static_cast<uint32_t>(list_.size());
34 PP_Var NetworkListResource::GetName(uint32_t index) {
35 if (index >= list_.size())
36 return PP_MakeUndefined();
37 return StringVar::StringToPPVar(list_.at(index).name);
40 PP_NetworkList_Type NetworkListResource::GetType(uint32_t index) {
41 if (index >= list_.size())
42 return PP_NETWORKLIST_TYPE_UNKNOWN;
43 return list_.at(index).type;
46 PP_NetworkList_State NetworkListResource::GetState(uint32_t index) {
47 if (index >= list_.size())
48 return PP_NETWORKLIST_STATE_DOWN;
49 return list_.at(index).state;
52 int32_t NetworkListResource::GetIpAddresses(uint32_t index,
53 const PP_ArrayOutput& output) {
54 ArrayWriter writer(output);
55 if (index >= list_.size() || !writer.is_valid())
56 return PP_ERROR_BADARGUMENT;
58 thunk::EnterResourceCreationNoLock enter(pp_instance());
59 if (enter.failed())
60 return PP_ERROR_FAILED;
62 const std::vector<PP_NetAddress_Private>& addresses =
63 list_.at(index).addresses;
64 std::vector<PP_Resource> addr_resources;
65 for (size_t i = 0; i < addresses.size(); ++i) {
66 addr_resources.push_back(
67 enter.functions()->CreateNetAddressFromNetAddressPrivate(
68 pp_instance(), addresses[i]));
70 if (!writer.StoreResourceVector(addr_resources))
71 return PP_ERROR_FAILED;
73 return PP_OK;
76 PP_Var NetworkListResource::GetDisplayName(uint32_t index) {
77 if (index >= list_.size())
78 return PP_MakeUndefined();
79 return StringVar::StringToPPVar(list_.at(index).display_name);
82 uint32_t NetworkListResource::GetMTU(uint32_t index) {
83 if (index >= list_.size())
84 return 0;
85 return list_.at(index).mtu;
88 } // namespace proxy
89 } // namespace thunk