Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Unified Diff: ppapi/shared_impl/ppb_network_list_private_shared.cc

Issue 9545010: Add NetworkList/NetworkMonitor hooks and C++ wrappers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..9fa327c5e4674b332c3de942e3ca89c3319a3b01
--- /dev/null
+++ b/ppapi/shared_impl/ppb_network_list_private_shared.cc
@@ -0,0 +1,95 @@
+// 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::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.
+}
+
+PPB_NetworkList_Private_Shared::NetworkInfo::~NetworkInfo() {
+}
+
+PPB_NetworkList_Private_Shared::PPB_NetworkList_Private_Shared(
+ ResourceObjectType type,
+ PP_Instance instance,
+ scoped_ptr<NetworkList> 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<NetworkList> 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 PP_MakeUndefined();
+ return StringVar::StringToPPVar(list_->at(index).name);
+}
+
+PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType(
+ uint32_t index) {
+ if (index >= list_->size())
+ return PP_NETWORKLIST_UNKNOWN;
+ return list_->at(index).type;
+}
+
+PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState(
+ uint32_t index) {
+ if (index >= list_->size())
+ return PP_NETWORKLIST_DOWN;
+ return list_->at(index).state;
+}
+
+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;
+ count = std::min(
+ count, static_cast<uint32_t>(list_->at(index).addresses.size()));
+ memcpy(addresses, &(list_->at(index).addresses[0]),
+ sizeof(PP_NetAddress_Private) * count);
+ 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!
+}
+
+PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) {
+ if (index >= list_->size())
+ return PP_MakeUndefined();
+ return StringVar::StringToPPVar(list_->at(index).display_name);
+}
+
+uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) {
+ if (index >= list_->size())
+ 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.
+ return list_->at(index).mtu;
+}
+
+} // namespace thunk

Powered by Google App Engine
This is Rietveld 408576698