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

Unified Diff: ppapi/cpp/private/network_list_private.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/cpp/private/network_list_private.cc
diff --git a/ppapi/cpp/private/network_list_private.cc b/ppapi/cpp/private/network_list_private.cc
new file mode 100644
index 0000000000000000000000000000000000000000..14c0422f52a24d7823180bf7bcf33f26952256e0
--- /dev/null
+++ b/ppapi/cpp/private/network_list_private.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2011 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 "ppapi/cpp/private/network_list_private.h"
+
+#include "ppapi/cpp/module_impl.h"
+#include "ppapi/cpp/var.h"
+
+namespace pp {
+
+namespace {
+
+template <> const char* interface_name<PPB_NetworkList_Private>() {
+ return PPB_NETWORKLIST_PRIVATE_INTERFACE;
+}
+
+} // namespace
+
+NetworkListPrivate::NetworkListPrivate(PP_Resource resource)
+ : Resource(resource) {
+}
+
+// static
+bool NetworkListPrivate::IsAvailable() {
+ return has_interface<PPB_NetworkList_Private>();
+}
+
+uint32_t NetworkListPrivate::GetCount() {
+ if (!has_interface<PPB_NetworkList_Private>())
+ return 0;
+ return get_interface<PPB_NetworkList_Private>()->GetCount(pp_resource());
+}
+
+std::string NetworkListPrivate::GetName(uint32_t index) {
+ if (!has_interface<PPB_NetworkList_Private>())
+ return std::string();
+ Var result(PASS_REF,
+ get_interface<PPB_NetworkList_Private>()->GetName(
+ pp_resource(), index));
+ return result.is_string() ? result.AsString() : std::string();
+}
+
+PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) {
+ if (!has_interface<PPB_NetworkList_Private>())
+ return PP_NETWORKLIST_ETHERNET;
+ return get_interface<PPB_NetworkList_Private>()->GetType(
+ pp_resource(), index);
+}
+
+PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) {
+ if (!has_interface<PPB_NetworkList_Private>())
+ return PP_NETWORKLIST_DOWN;
+ return get_interface<PPB_NetworkList_Private>()->GetState(
+ pp_resource(), index);
+}
+
+void NetworkListPrivate::GetIpAddresses(
+ uint32_t index,
+ std::vector<PP_NetAddress_Private>* addresses) {
+ if (!has_interface<PPB_NetworkList_Private>())
+ return;
+
+ // Most netword interfaces don't have more than 3 network
+ // interfaces.
+ addresses->resize(3);
+
+ int32_t result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses(
+ pp_resource(), index, &addresses->front(), addresses->size());
+
+ if (result < 0) {
dmichael (off chromium) 2012/03/01 18:29:54 Why not <= 0?
Sergey Ulanov 2012/03/02 03:01:37 "result = 0" is a not an error condition - it just
+ addresses->resize(0);
+ return;
+ }
+
+ if (result < static_cast<int32_t>(addresses->size())) {
dmichael (off chromium) 2012/03/01 18:29:54 Why not <=? Right now, if you get 3 back, you fall
Sergey Ulanov 2012/03/02 03:01:37 Done.
+ addresses->resize(result);
+ return;
+ }
+
+ addresses->resize(result);
+ result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses(
+ pp_resource(), index, &addresses->front(), addresses->size());
+ if (result < 0) {
+ addresses->resize(0);
+ } else if (result < static_cast<int32_t>(addresses->size())) {
+ addresses->resize(result);
+ }
+}
+
+std::string NetworkListPrivate::GetDisplayName(uint32_t index) {
+ if (!has_interface<PPB_NetworkList_Private>())
+ return std::string();
+ Var result(PASS_REF,
+ get_interface<PPB_NetworkList_Private>()->GetDisplayName(
+ pp_resource(), index));
+ return result.is_string() ? result.AsString() : std::string();
+}
+
+uint32_t NetworkListPrivate::GetMTU(uint32_t index) {
+ if (!has_interface<PPB_NetworkList_Private>())
+ return 0;
+ return get_interface<PPB_NetworkList_Private>()->GetMTU(
+ pp_resource(), index);
+}
+
+} // namespace pp

Powered by Google App Engine
This is Rietveld 408576698