summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/ppapi_proxy.gypi2
-rw-r--r--ppapi/proxy/interface_list.cc1
-rw-r--r--ppapi/proxy/ppapi_messages.h23
-rw-r--r--ppapi/proxy/ppb_network_monitor_private_proxy.cc146
-rw-r--r--ppapi/proxy/ppb_network_monitor_private_proxy.h61
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc5
-rw-r--r--ppapi/shared_impl/api_id.h1
-rw-r--r--ppapi/shared_impl/ppb_network_list_private_shared.cc53
-rw-r--r--ppapi/shared_impl/ppb_network_list_private_shared.h52
-rw-r--r--ppapi/tests/test_network_monitor_private.cc50
-rw-r--r--ppapi/tests/test_network_monitor_private.h1
-rw-r--r--ppapi/thunk/interfaces_ppb_private.h12
-rw-r--r--ppapi/thunk/ppb_network_list_private_api.h10
13 files changed, 366 insertions, 51 deletions
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi
index caa12f5..84913e0 100644
--- a/ppapi/ppapi_proxy.gypi
+++ b/ppapi/ppapi_proxy.gypi
@@ -105,6 +105,8 @@
'proxy/ppb_instance_proxy.h',
'proxy/ppb_message_loop_proxy.cc',
'proxy/ppb_message_loop_proxy.h',
+ 'proxy/ppb_network_monitor_private_proxy.cc',
+ 'proxy/ppb_network_monitor_private_proxy.h',
'proxy/ppb_pdf_proxy.cc',
'proxy/ppb_pdf_proxy.h',
'proxy/ppb_talk_private_proxy.cc',
diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc
index c169833..5728b54 100644
--- a/ppapi/proxy/interface_list.cc
+++ b/ppapi/proxy/interface_list.cc
@@ -92,6 +92,7 @@
#include "ppapi/proxy/ppb_image_data_proxy.h"
#include "ppapi/proxy/ppb_instance_proxy.h"
#include "ppapi/proxy/ppb_message_loop_proxy.h"
+#include "ppapi/proxy/ppb_network_monitor_private_proxy.h"
#include "ppapi/proxy/ppb_pdf_proxy.h"
#include "ppapi/proxy/ppb_talk_private_proxy.h"
#include "ppapi/proxy/ppb_tcp_server_socket_private_proxy.h"
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 4c74eac..1043f59 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -41,6 +41,7 @@
#include "ppapi/shared_impl/ppapi_preferences.h"
#include "ppapi/shared_impl/ppb_device_ref_shared.h"
#include "ppapi/shared_impl/ppb_input_event_shared.h"
+#include "ppapi/shared_impl/ppb_network_list_private_shared.h"
#include "ppapi/shared_impl/ppb_url_request_info_shared.h"
#include "ppapi/shared_impl/ppb_view_shared.h"
#include "ppapi/shared_impl/private/ppb_host_resolver_shared.h"
@@ -54,6 +55,8 @@ IPC_ENUM_TRAITS(PP_DeviceType_Dev)
IPC_ENUM_TRAITS(PP_InputEvent_MouseButton)
IPC_ENUM_TRAITS(PP_InputEvent_Type)
IPC_ENUM_TRAITS(PP_NetAddressFamily_Private)
+IPC_ENUM_TRAITS(PP_NetworkListType_Private)
+IPC_ENUM_TRAITS(PP_NetworkListState_Private)
IPC_ENUM_TRAITS(PP_TextInput_Type)
IPC_ENUM_TRAITS(PP_VideoDecodeError_Dev)
IPC_ENUM_TRAITS(PP_VideoDecoder_Profile)
@@ -188,6 +191,15 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::PPB_URLRequestInfo_Data::BodyItem)
IPC_STRUCT_TRAITS_MEMBER(expected_last_modified_time)
IPC_STRUCT_TRAITS_END()
+IPC_STRUCT_TRAITS_BEGIN(ppapi::NetworkInfo)
+ IPC_STRUCT_TRAITS_MEMBER(name)
+ IPC_STRUCT_TRAITS_MEMBER(type)
+ IPC_STRUCT_TRAITS_MEMBER(state)
+ IPC_STRUCT_TRAITS_MEMBER(addresses)
+ IPC_STRUCT_TRAITS_MEMBER(display_name)
+ IPC_STRUCT_TRAITS_MEMBER(mtu)
+IPC_STRUCT_TRAITS_END()
+
// These are from the browser to the plugin.
// Loads the given plugin.
IPC_MESSAGE_CONTROL1(PpapiMsg_LoadPlugin, FilePath /* path */)
@@ -309,6 +321,11 @@ IPC_MESSAGE_ROUTED2(
ppapi::HostResource /* filesystem */,
int32_t /* result */)
+// PPB_NetworkMonitor_Private.
+IPC_MESSAGE_ROUTED2(PpapiMsg_PPBNetworkMonitor_NetworkList,
+ uint32 /* plugin_dispatcher_id */,
+ ppapi::NetworkList /* network_list */)
+
// PPB_Talk
IPC_MESSAGE_ROUTED3(
PpapiMsg_PPBTalk_GetPermissionACK,
@@ -763,6 +780,12 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileSystem_Open,
ppapi::HostResource /* result */,
int64_t /* expected_size */)
+// PPB_NetworkMonitor_Private.
+IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBNetworkMonitor_Start,
+ uint32 /* plugin_dispatcher_id */)
+IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBNetworkMonitor_Stop,
+ uint32 /* plugin_dispatcher_id */)
+
// PPB_Graphics2D.
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBGraphics2D_Create,
PP_Instance /* instance */,
diff --git a/ppapi/proxy/ppb_network_monitor_private_proxy.cc b/ppapi/proxy/ppb_network_monitor_private_proxy.cc
new file mode 100644
index 0000000..4fa2d6e
--- /dev/null
+++ b/ppapi/proxy/ppb_network_monitor_private_proxy.cc
@@ -0,0 +1,146 @@
+// 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 "ppapi/proxy/ppb_network_monitor_private_proxy.h"
+
+#include "ppapi/proxy/enter_proxy.h"
+#include "ppapi/proxy/plugin_proxy_delegate.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/thunk/ppb_network_monitor_private_api.h"
+
+namespace ppapi {
+namespace proxy {
+
+class PPB_NetworkMonitor_Private_Proxy::NetworkMonitor
+ : public Resource,
+ public thunk::PPB_NetworkMonitor_Private_API,
+ public base::SupportsWeakPtr<
+ PPB_NetworkMonitor_Private_Proxy::NetworkMonitor> {
+ public:
+ NetworkMonitor(PP_Instance instance,
+ PPB_NetworkMonitor_Private_Proxy* proxy,
+ PPB_NetworkMonitor_Callback callback,
+ void* user_data)
+ : Resource(OBJECT_IS_PROXY, instance),
+ proxy_(proxy),
+ callback_(callback),
+ user_data_(user_data) {
+ }
+
+ virtual ~NetworkMonitor() {
+ proxy_->OnNetworkMonitorDeleted(this, pp_instance());
+ }
+
+
+ // Resource overrides.
+ virtual ppapi::thunk::PPB_NetworkMonitor_Private_API*
+ AsPPB_NetworkMonitor_Private_API() OVERRIDE {
+ return this;
+ }
+
+ void OnNetworkListReceived(const scoped_refptr<NetworkListStorage>& list) {
+ PP_Resource list_resource =
+ PPB_NetworkList_Private_Shared::Create(
+ OBJECT_IS_PROXY, pp_instance(), list);
+ CallWhileUnlocked(callback_, user_data_, list_resource);
+ }
+
+ private:
+ PPB_NetworkMonitor_Private_Proxy* proxy_;
+ PPB_NetworkMonitor_Callback callback_;
+ void* user_data_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkMonitor);
+};
+
+PPB_NetworkMonitor_Private_Proxy::PPB_NetworkMonitor_Private_Proxy(
+ Dispatcher* dispatcher)
+ : InterfaceProxy(dispatcher),
+ monitors_(new ObserverListThreadSafe<NetworkMonitor>()),
+ monitors_count_(0) {
+}
+
+PPB_NetworkMonitor_Private_Proxy::~PPB_NetworkMonitor_Private_Proxy() {
+ monitors_->AssertEmpty();
+}
+
+// static
+PP_Resource PPB_NetworkMonitor_Private_Proxy::CreateProxyResource(
+ PP_Instance instance,
+ PPB_NetworkMonitor_Callback callback,
+ void* user_data) {
+ if (!callback)
+ return 0;
+
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return 0;
+ PPB_NetworkMonitor_Private_Proxy* proxy =
+ static_cast<PPB_NetworkMonitor_Private_Proxy*>(
+ dispatcher->GetInterfaceProxy(kApiID));
+ if (!proxy)
+ return 0;
+
+ scoped_ptr<NetworkMonitor> result(
+ new NetworkMonitor(instance, proxy, callback, user_data));
+ proxy->monitors_->AddObserver(result.get());
+
+ proxy->monitors_count_++;
+ if (proxy->monitors_count_ == 1) {
+ // If that is the first network monitor then send Start message.
+ PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser(
+ new PpapiHostMsg_PPBNetworkMonitor_Start(
+ dispatcher->plugin_dispatcher_id()));
+
+ // We could have received network list message after sending the
+ // previous Stop message. This list is stale now, so reset it
+ // here.
+ proxy->current_list_ = NULL;
+ } else if (proxy->current_list_.get()) {
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
+ &NetworkMonitor::OnNetworkListReceived,
+ result->AsWeakPtr(), proxy->current_list_));
+ }
+
+ return result.release()->GetReference();
+}
+
+bool PPB_NetworkMonitor_Private_Proxy::OnMessageReceived(
+ const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PPB_NetworkMonitor_Private_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiMsg_PPBNetworkMonitor_NetworkList,
+ OnPluginMsgNetworkList)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PPB_NetworkMonitor_Private_Proxy::OnPluginMsgNetworkList(
+ uint32 plugin_dispatcher_id,
+ const ppapi::NetworkList& list) {
+ scoped_refptr<NetworkListStorage> list_storage(new NetworkListStorage(list));
+ current_list_ = list_storage;
+ monitors_->Notify(&NetworkMonitor::OnNetworkListReceived, list_storage);
+}
+
+void PPB_NetworkMonitor_Private_Proxy::OnNetworkMonitorDeleted(
+ NetworkMonitor* monitor,
+ PP_Instance instance) {
+ monitors_->RemoveObserver(monitor);
+ monitors_count_--;
+ if (monitors_count_ == 0) {
+ // Send Stop message if that was the last NetworkMonitor.
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (dispatcher) {
+ PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser(
+ new PpapiHostMsg_PPBNetworkMonitor_Stop(
+ dispatcher->plugin_dispatcher_id()));
+ }
+ current_list_ = NULL;
+ }
+}
+
+} // namespace proxy
+} // namespace ppapi
diff --git a/ppapi/proxy/ppb_network_monitor_private_proxy.h b/ppapi/proxy/ppb_network_monitor_private_proxy.h
new file mode 100644
index 0000000..3c420d8
--- /dev/null
+++ b/ppapi/proxy/ppb_network_monitor_private_proxy.h
@@ -0,0 +1,61 @@
+// 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.
+
+#ifndef PPAPI_PROXY_PPB_NETWORK_MONITOR_PRIVATE_PROXY_H_
+#define PPAPI_PROXY_PPB_NETWORK_MONITOR_PRIVATE_PROXY_H_
+
+#include <list>
+
+#include "base/observer_list_threadsafe.h"
+#include "ppapi/proxy/interface_proxy.h"
+#include "ppapi/shared_impl/ppb_network_list_private_shared.h"
+#include "ppapi/shared_impl/scoped_pp_resource.h"
+#include "ppapi/thunk/ppb_network_monitor_private_api.h"
+
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
+namespace ppapi {
+namespace proxy {
+
+class PPB_NetworkMonitor_Private_Proxy : public InterfaceProxy {
+ public:
+ explicit PPB_NetworkMonitor_Private_Proxy(Dispatcher* dispatcher);
+ virtual ~PPB_NetworkMonitor_Private_Proxy();
+
+ // Creates n NetworkManager object in the plugin process.
+ static PP_Resource CreateProxyResource(PP_Instance instance,
+ PPB_NetworkMonitor_Callback callback,
+ void* user_data);
+
+ // InterfaceProxy implementation.
+ virtual bool OnMessageReceived(const IPC::Message& msg);
+
+ static const ApiID kApiID = API_ID_PPB_NETWORKMANAGER_PRIVATE;
+
+ private:
+ class NetworkMonitor;
+ friend class NetworkMonitor;
+
+ // IPC message handler for the messages received from the browser.
+ void OnPluginMsgNetworkList(uint32 plugin_dispatcher_id,
+ const ppapi::NetworkList& list);
+
+ // Called by NetworkMonitor destructor.
+ void OnNetworkMonitorDeleted(NetworkMonitor* monitor,
+ PP_Instance instance);
+
+ scoped_refptr<ObserverListThreadSafe<NetworkMonitor> > monitors_;
+
+ int monitors_count_;
+ scoped_refptr<NetworkListStorage> current_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_NetworkMonitor_Private_Proxy);
+};
+
+} // namespace proxy
+} // namespace ppapi
+
+#endif // PPAPI_PROXY_PPB_NETWORK_MONITOR_PRIVATE_PROXY_H_
diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc
index b74840a..5e9cecf 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -25,6 +25,7 @@
#include "ppapi/proxy/ppb_graphics_3d_proxy.h"
#include "ppapi/proxy/ppb_host_resolver_private_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
+#include "ppapi/proxy/ppb_network_monitor_private_proxy.h"
#include "ppapi/proxy/ppb_talk_private_proxy.h"
#include "ppapi/proxy/ppb_tcp_server_socket_private_proxy.h"
#include "ppapi/proxy/ppb_tcp_socket_private_proxy.h"
@@ -249,8 +250,8 @@ PP_Resource ResourceCreationProxy::CreateNetworkMonitor(
PP_Instance instance,
PPB_NetworkMonitor_Callback callback,
void* user_data) {
- NOTIMPLEMENTED(); // Not proxied yet.
- return 0;
+ return PPB_NetworkMonitor_Private_Proxy::CreateProxyResource(
+ instance, callback, user_data);
}
PP_Resource ResourceCreationProxy::CreateGraphics3D(
diff --git a/ppapi/shared_impl/api_id.h b/ppapi/shared_impl/api_id.h
index f4f4a81..61af629 100644
--- a/ppapi/shared_impl/api_id.h
+++ b/ppapi/shared_impl/api_id.h
@@ -38,6 +38,7 @@ enum ApiID {
API_ID_PPB_IMAGE_DATA,
API_ID_PPB_INSTANCE,
API_ID_PPB_INSTANCE_PRIVATE,
+ API_ID_PPB_NETWORKMANAGER_PRIVATE,
API_ID_PPB_OPENGLES2,
API_ID_PPB_PDF,
API_ID_PPB_SURFACE_3D,
diff --git a/ppapi/shared_impl/ppb_network_list_private_shared.cc b/ppapi/shared_impl/ppb_network_list_private_shared.cc
index b06e4c5..6f8c67c 100644
--- a/ppapi/shared_impl/ppb_network_list_private_shared.cc
+++ b/ppapi/shared_impl/ppb_network_list_private_shared.cc
@@ -11,21 +11,28 @@
namespace ppapi {
-PPB_NetworkList_Private_Shared::NetworkInfo::NetworkInfo()
+NetworkInfo::NetworkInfo()
: type(PP_NETWORKLIST_UNKNOWN),
state(PP_NETWORKLIST_DOWN),
mtu(0) {
}
-PPB_NetworkList_Private_Shared::NetworkInfo::~NetworkInfo() {
+NetworkInfo::~NetworkInfo() {
+}
+
+NetworkListStorage::NetworkListStorage(const NetworkList& list)
+ : list_(list) {
+}
+
+NetworkListStorage::~NetworkListStorage() {
}
PPB_NetworkList_Private_Shared::PPB_NetworkList_Private_Shared(
ResourceObjectType type,
PP_Instance instance,
- scoped_ptr<NetworkList> list)
+ const scoped_refptr<NetworkListStorage>& list)
: Resource(type, instance),
- list_(list.Pass()) {
+ list_(list) {
}
PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() {
@@ -35,9 +42,9 @@ PPB_NetworkList_Private_Shared::~PPB_NetworkList_Private_Shared() {
PP_Resource PPB_NetworkList_Private_Shared::Create(
ResourceObjectType type,
PP_Instance instance,
- scoped_ptr<NetworkList> list) {
+ const scoped_refptr<NetworkListStorage>& list) {
scoped_refptr<PPB_NetworkList_Private_Shared> object(
- new PPB_NetworkList_Private_Shared(type, instance, list.Pass()));
+ new PPB_NetworkList_Private_Shared(type, instance, list));
return object->GetReference();
}
@@ -46,53 +53,57 @@ PPB_NetworkList_Private_Shared::AsPPB_NetworkList_Private_API() {
return this;
}
+const NetworkList& PPB_NetworkList_Private_Shared::GetNetworkListData() const {
+ return list_->list();
+}
+
uint32_t PPB_NetworkList_Private_Shared::GetCount() {
- return list_->size();
+ return list_->list().size();
}
PP_Var PPB_NetworkList_Private_Shared::GetName(uint32_t index) {
- if (index >= list_->size())
+ if (index >= list_->list().size())
return PP_MakeUndefined();
- return StringVar::StringToPPVar(list_->at(index).name);
+ return StringVar::StringToPPVar(list_->list().at(index).name);
}
PP_NetworkListType_Private PPB_NetworkList_Private_Shared::GetType(
uint32_t index) {
- if (index >= list_->size())
+ if (index >= list_->list().size())
return PP_NETWORKLIST_UNKNOWN;
- return list_->at(index).type;
+ return list_->list().at(index).type;
}
PP_NetworkListState_Private PPB_NetworkList_Private_Shared::GetState(
uint32_t index) {
- if (index >= list_->size())
+ if (index >= list_->list().size())
return PP_NETWORKLIST_DOWN;
- return list_->at(index).state;
+ return list_->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())
+ if (index >= list_->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]),
+ count, static_cast<uint32_t>(list_->list().at(index).addresses.size()));
+ memcpy(addresses, &(list_->list().at(index).addresses[0]),
sizeof(PP_NetAddress_Private) * count);
- return list_->at(index).addresses.size();
+ return list_->list().at(index).addresses.size();
}
PP_Var PPB_NetworkList_Private_Shared::GetDisplayName(uint32_t index) {
- if (index >= list_->size())
+ if (index >= list_->list().size())
return PP_MakeUndefined();
- return StringVar::StringToPPVar(list_->at(index).display_name);
+ return StringVar::StringToPPVar(list_->list().at(index).display_name);
}
uint32_t PPB_NetworkList_Private_Shared::GetMTU(uint32_t index) {
- if (index >= list_->size())
+ if (index >= list_->list().size())
return 0;
- return list_->at(index).mtu;
+ return list_->list().at(index).mtu;
}
} // namespace thunk
diff --git a/ppapi/shared_impl/ppb_network_list_private_shared.h b/ppapi/shared_impl/ppb_network_list_private_shared.h
index 1aecb2c..c15ccc3 100644
--- a/ppapi/shared_impl/ppb_network_list_private_shared.h
+++ b/ppapi/shared_impl/ppb_network_list_private_shared.h
@@ -14,26 +14,45 @@
namespace ppapi {
+struct PPAPI_SHARED_EXPORT NetworkInfo {
+ NetworkInfo();
+ ~NetworkInfo();
+
+ std::string name;
+ PP_NetworkListType_Private type;
+ PP_NetworkListState_Private state;
+ std::vector<PP_NetAddress_Private> addresses;
+ std::string display_name;
+ int mtu;
+};
+typedef std::vector<NetworkInfo> NetworkList;
+
+// NetworkListStorage is refcounted container for NetworkList. It
+// allows sharing of one NetworkList object between multiple
+// NetworkList resources.
+class PPAPI_SHARED_EXPORT NetworkListStorage
+ : public base::RefCountedThreadSafe<NetworkListStorage> {
+ public:
+ NetworkListStorage(const NetworkList& list);
+
+ const NetworkList& list() { return list_; }
+
+ private:
+ friend class base::RefCountedThreadSafe<NetworkListStorage>;
+ ~NetworkListStorage();
+
+ NetworkList list_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkListStorage);
+};
+
class PPAPI_SHARED_EXPORT PPB_NetworkList_Private_Shared
: public ::ppapi::Resource,
public ::ppapi::thunk::PPB_NetworkList_Private_API {
public:
- struct PPAPI_SHARED_EXPORT NetworkInfo {
- NetworkInfo();
- ~NetworkInfo();
-
- std::string name;
- PP_NetworkListType_Private type;
- PP_NetworkListState_Private state;
- std::vector<PP_NetAddress_Private> addresses;
- std::string display_name;
- int mtu;
- };
- typedef std::vector<NetworkInfo> NetworkList;
-
static PP_Resource Create(ResourceObjectType type,
PP_Instance instance,
- scoped_ptr<NetworkList> list);
+ const scoped_refptr<NetworkListStorage>& list);
virtual ~PPB_NetworkList_Private_Shared();
@@ -42,6 +61,7 @@ class PPAPI_SHARED_EXPORT PPB_NetworkList_Private_Shared
AsPPB_NetworkList_Private_API() OVERRIDE;
// PPB_NetworkList_Private_API implementation.
+ virtual const NetworkList& GetNetworkListData() const OVERRIDE;
virtual uint32_t GetCount() OVERRIDE;
virtual PP_Var GetName(uint32_t index) OVERRIDE;
virtual PP_NetworkListType_Private GetType(uint32_t index) OVERRIDE;
@@ -55,9 +75,9 @@ class PPAPI_SHARED_EXPORT PPB_NetworkList_Private_Shared
private:
PPB_NetworkList_Private_Shared(ResourceObjectType type,
PP_Instance instance,
- scoped_ptr<NetworkList> list);
+ const scoped_refptr<NetworkListStorage>& list);
- scoped_ptr<NetworkList> list_;
+ scoped_refptr<NetworkListStorage> list_;
DISALLOW_COPY_AND_ASSIGN(PPB_NetworkList_Private_Shared);
};
diff --git a/ppapi/tests/test_network_monitor_private.cc b/ppapi/tests/test_network_monitor_private.cc
index 6b7d49f..fa87ec1 100644
--- a/ppapi/tests/test_network_monitor_private.cc
+++ b/ppapi/tests/test_network_monitor_private.cc
@@ -6,6 +6,7 @@
#include <string.h>
+#include "ppapi/cpp/private/net_address_private.h"
#include "ppapi/cpp/private/network_list_private.h"
#include "ppapi/cpp/private/network_monitor_private.h"
#include "ppapi/tests/testing_instance.h"
@@ -20,7 +21,9 @@ struct CallbackData {
explicit CallbackData(PP_Instance instance)
: call_counter(0),
completion_callback(instance),
- list_resource(0) {
+ list_resource(0),
+ delete_monitor(false),
+ monitor(NULL) {
}
~CallbackData() {
if (list_resource)
@@ -29,6 +32,8 @@ struct CallbackData {
int call_counter;
TestCompletionCallback completion_callback;
PP_Resource list_resource;
+ bool delete_monitor;
+ pp::NetworkMonitorPrivate* monitor;
};
void TestCallback(void* user_data, PP_Resource network_list) {
@@ -39,6 +44,9 @@ void TestCallback(void* user_data, PP_Resource network_list) {
pp::Module::Get()->core()->ReleaseResource(data->list_resource);
data->list_resource = network_list;
+ if (data->delete_monitor)
+ delete data->monitor;
+
// Invoke completion callback only for the first change notification.
if (data->call_counter == 1)
static_cast<pp::CompletionCallback>(data->completion_callback).Run(PP_OK);
@@ -60,6 +68,7 @@ bool TestNetworkMonitorPrivate::Init() {
void TestNetworkMonitorPrivate::RunTests(const std::string& filter) {
RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter);
RUN_TEST_FORCEASYNC_AND_NOT(2Monitors, filter);
+ RUN_TEST_FORCEASYNC_AND_NOT(DeleteInCallback, filter);
}
std::string TestNetworkMonitorPrivate::VerifyNetworkList(
@@ -78,15 +87,26 @@ std::string TestNetworkMonitorPrivate::VerifyNetworkList(
ASSERT_TRUE(addresses.size() >= 1U);
// Verify that the addresses are valid.
for (size_t i = 0; i < addresses.size(); ++i) {
- ASSERT_TRUE(addresses[i].size == 4 || addresses[i].size == 16);
+ PP_NetAddressFamily_Private family =
+ pp::NetAddressPrivate::GetFamily(addresses[i]);
+
+ ASSERT_TRUE(family == PP_NETADDRESSFAMILY_IPV4 ||
+ family == PP_NETADDRESSFAMILY_IPV6);
+
+ char ip[16] = { 0 };
+ ASSERT_TRUE(pp::NetAddressPrivate::GetAddress(
+ addresses[i], ip, sizeof(ip)));
// Verify that the address is not zero.
size_t j;
- for (j = 0; j < addresses[i].size; ++j) {
- if (addresses[i].data[j] != 0)
+ for (j = 0; j < sizeof(ip); ++j) {
+ if (ip[j] != 0)
break;
}
ASSERT_TRUE(j != addresses[i].size);
+
+ // Verify that port is set to 0.
+ ASSERT_TRUE(pp::NetAddressPrivate::GetPort(addresses[i]) == 0);
}
// Verify that each interface has a unique name and a display name.
@@ -136,7 +156,7 @@ std::string TestNetworkMonitorPrivate::TestBasic() {
CallbackData callback_data(instance_->pp_instance());
pp::NetworkMonitorPrivate network_monitor(
- instance_, &TestCallback, reinterpret_cast<void*>(&callback_data));
+ instance_, &TestCallback, &callback_data);
ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data.call_counter, 1);
@@ -149,7 +169,7 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() {
CallbackData callback_data(instance_->pp_instance());
pp::NetworkMonitorPrivate network_monitor(
- instance_, &TestCallback, reinterpret_cast<void*>(&callback_data));
+ instance_, &TestCallback, &callback_data);
ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data.call_counter, 1);
@@ -158,7 +178,7 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() {
CallbackData callback_data_2(instance_->pp_instance());
pp::NetworkMonitorPrivate network_monitor_2(
- instance_, &TestCallback, reinterpret_cast<void*>(&callback_data_2));
+ instance_, &TestCallback, &callback_data_2);
ASSERT_EQ(callback_data_2.completion_callback.WaitForResult(), PP_OK);
ASSERT_EQ(callback_data_2.call_counter, 1);
@@ -166,3 +186,19 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() {
PASS();
}
+
+std::string TestNetworkMonitorPrivate::TestDeleteInCallback() {
+ CallbackData callback_data(instance_->pp_instance());
+
+ pp::NetworkMonitorPrivate* network_monitor = new pp::NetworkMonitorPrivate(
+ instance_, &TestCallback, &callback_data);
+ callback_data.delete_monitor = true;
+ callback_data.monitor = network_monitor;
+
+ ASSERT_EQ(callback_data.completion_callback.WaitForResult(), PP_OK);
+ ASSERT_EQ(callback_data.call_counter, 1);
+
+ ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data.list_resource));
+
+ PASS();
+}
diff --git a/ppapi/tests/test_network_monitor_private.h b/ppapi/tests/test_network_monitor_private.h
index 20a99d4..00a856a 100644
--- a/ppapi/tests/test_network_monitor_private.h
+++ b/ppapi/tests/test_network_monitor_private.h
@@ -21,6 +21,7 @@ class TestNetworkMonitorPrivate : public TestCase {
private:
std::string TestBasic();
std::string Test2Monitors();
+ std::string TestDeleteInCallback();
std::string VerifyNetworkList(PP_Resource network_resource);
};
diff --git a/ppapi/thunk/interfaces_ppb_private.h b/ppapi/thunk/interfaces_ppb_private.h
index 43776b0..f6cec07 100644
--- a/ppapi/thunk/interfaces_ppb_private.h
+++ b/ppapi/thunk/interfaces_ppb_private.h
@@ -13,6 +13,8 @@ PROXIED_API(PPB_Talk_Private)
PROXIED_API(PPB_TCPServerSocket_Private)
PROXIED_API(PPB_TCPSocket_Private)
PROXIED_API(PPB_UDPSocket_Private)
+UNPROXIED_API(PPB_NetworkList_Private)
+PROXIED_API(PPB_NetworkMonitor_Private)
PROXIED_IFACE(PPB_Broker, PPB_BROKER_TRUSTED_INTERFACE_0_2,
PPB_BrokerTrusted_0_2)
@@ -45,11 +47,11 @@ PROXIED_IFACE(PPB_UDPSocket_Private, PPB_UDPSOCKET_PRIVATE_INTERFACE_0_2,
PROXIED_IFACE(PPB_UDPSocket_Private, PPB_UDPSOCKET_PRIVATE_INTERFACE_0_3,
PPB_UDPSocket_Private_0_3)
-UNPROXIED_IFACE(PPB_NetworkList_Private, PPB_NETWORKLIST_PRIVATE_INTERFACE_0_2,
- PPB_NetworkList_Private_0_2)
-UNPROXIED_IFACE(PPB_NetworkMonitor_Private,
- PPB_NETWORKMONITOR_PRIVATE_INTERFACE_0_2,
- PPB_NetworkMonitor_Private_0_2)
+PROXIED_IFACE(NoAPIName, PPB_NETWORKLIST_PRIVATE_INTERFACE_0_2,
+ PPB_NetworkList_Private_0_2)
+PROXIED_IFACE(PPB_NetworkMonitor_Private,
+ PPB_NETWORKMONITOR_PRIVATE_INTERFACE_0_2,
+ PPB_NetworkMonitor_Private_0_2)
// Hack to keep font working. The Font 0.6 API is binary compatible with
// BrowserFont 1.0, so just map the string to the same thing.
diff --git a/ppapi/thunk/ppb_network_list_private_api.h b/ppapi/thunk/ppb_network_list_private_api.h
index fbe57f0..ea91349 100644
--- a/ppapi/thunk/ppb_network_list_private_api.h
+++ b/ppapi/thunk/ppb_network_list_private_api.h
@@ -5,16 +5,26 @@
#ifndef PPAPI_THUNK_PPB_NETWORK_LIST_PRIVATE_API_H_
#define PPAPI_THUNK_PPB_NETWORK_LIST_PRIVATE_API_H_
+#include <vector>
+
#include "ppapi/c/private/ppb_network_list_private.h"
#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
+
+struct NetworkInfo;
+typedef std::vector<NetworkInfo> NetworkList;
+
namespace thunk {
class PPAPI_THUNK_EXPORT PPB_NetworkList_Private_API {
public:
virtual ~PPB_NetworkList_Private_API() {}
+ // This function is not exposed through the C API, but returns the
+ // internal data for easy proxying.
+ virtual const NetworkList& GetNetworkListData() const = 0;
+
virtual uint32_t GetCount() = 0;
virtual PP_Var GetName(uint32_t index) = 0;
virtual PP_NetworkListType_Private GetType(uint32_t index) = 0;