Chromium Code Reviews| Index: ppapi/shared_impl/ppb_network_list_private_shared.cc |
| diff --git a/ppapi/shared_impl/ppb_network_list_private_shared.cc b/ppapi/shared_impl/ppb_network_list_private_shared.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dcc778942b7c61b102a68d92b79b3743cb0f0f04 |
| --- /dev/null |
| +++ b/ppapi/shared_impl/ppb_network_list_private_shared.cc |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <algorithm> |
| + |
| +#include "base/logging.h" |
| +#include "ppapi/c/pp_errors.h" |
| +#include "ppapi/shared_impl/ppb_network_list_private_shared.h" |
| +#include "ppapi/shared_impl/var.h" |
| + |
| +namespace ppapi { |
| + |
| +PPB_NetworkList_Private_Shared::PPB_NetworkList_Private_Shared( |
| + ResourceObjectType type, |
| + PP_Instance instance, |
| + scoped_ptr<net::NetworkInterfaceList> list) |
| + : Resource(type, instance), |
| + list_(list.Pass()) { |
| +} |
| + |
| +PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() { |
| +} |
| + |
| +// static |
| +PP_Resource PPB_NetworkList_Private_Shared::Create( |
| + ResourceObjectType type, |
| + PP_Instance instance, |
| + scoped_ptr<net::NetworkInterfaceList> list) { |
| + scoped_refptr<PPB_NetworkList_Private_Shared> object( |
| + new PPB_NetworkList_Private_Shared(type, instance, list.Pass())); |
| + return object->GetReference(); |
| +} |
| + |
| +::ppapi::thunk::PPB_NetworkList_Private_API* |
| +PPB_NetworkList_Private_Shared::AsPPB_NetworkList_Private_API() { |
| + return this; |
| +} |
| + |
| +uint32_t PPB_NetworkList_Private_Shared::GetCount() { |
| + return list_->size(); |
| +} |
| + |
| +PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) { |
| + if (index >= list_->size()) |
| + return StringVar::StringToPPVar(""); |
|
dmichael (off chromium)
2012/03/01 18:29:54
you might consider returning an Undefined Var to s
Sergey Ulanov
2012/03/02 03:01:37
Done.
|
| + return StringVar::StringToPPVar(list_->at(index).name); |
| +} |
| + |
| +PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType( |
| + uint32_t index) { |
| + // NetworkInterface struct doesn't privide this information yet. |
| + NOTIMPLEMENTED(); |
| + return PP_NETWORKLIST_UNKNOWN; |
| +} |
| + |
| +PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState( |
| + uint32_t index) { |
| + // Currently we get only interfaces that are active. |
|
dmichael (off chromium)
2012/03/01 18:29:54
Then it doesn't really need to be an error conditi
Sergey Ulanov
2012/03/02 03:01:37
Done.
|
| + NOTIMPLEMENTED(); |
| + return PP_NETWORKLIST_UP; |
| +} |
| + |
| +int32_t PPB_NetworkList_Private_Shared::GetIpAddresses( |
| + uint32_t index, |
| + struct PP_NetAddress_Private addresses[], |
| + uint32_t count) { |
| + if (index >= list_->size()) |
| + return PP_ERROR_FAILED; |
| + |
| + // Currently we get only one address for each interface. |
| + if (count >= 1) { |
| + DCHECK_LE(list_->at(index).address.size(), sizeof(addresses[0].data)); |
| + addresses[0].size = list_->at(index).address.size(); |
| + memcpy(addresses[0].data, &(list_->at(index).address.front()), |
|
dmichael (off chromium)
2012/03/01 18:29:54
You should probably return early if the address do
Sergey Ulanov
2012/03/02 03:01:37
Removed this code from this CL - will add it back
|
| + addresses[0].size); |
| + } |
| + return 1; |
| +} |
| + |
| +PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) { |
| + if (index >= list_->size()) |
| + return StringVar::StringToPPVar(""); |
|
dmichael (off chromium)
2012/03/01 18:29:54
It's probably better to return PP_MakeUndefined()
Sergey Ulanov
2012/03/02 03:01:37
Done.
|
| + // NetworkInterface struct doesn't contain display name yet. |
| + NOTIMPLEMENTED(); |
| + return StringVar::StringToPPVar(list_->at(index).name); |
| +} |
| + |
| +uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) { |
| + if (index >= list_->size()) |
| + return 0; |
| + // NetworkInterface struct doesn't contain MTU yet. |
| + NOTIMPLEMENTED(); |
| + return 0; |
| +} |
| + |
| +} // namespace thunk |