diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 20:19:39 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-20 20:19:39 +0000 |
commit | 5b9b80e284fb0b6a4885209ade02093aecc7eb86 (patch) | |
tree | badaaf0bccfb0ea5413c8949250ba50fec420aba /ppapi/proxy | |
parent | 1769870244a943241f8d34dc01b2d98b4f2b38f4 (diff) | |
download | chromium_src-5b9b80e284fb0b6a4885209ade02093aecc7eb86.zip chromium_src-5b9b80e284fb0b6a4885209ade02093aecc7eb86.tar.gz chromium_src-5b9b80e284fb0b6a4885209ade02093aecc7eb86.tar.bz2 |
Out-of-process implementation of the PPB_NetworkMonitor_Private interface.
BUG=114808
Review URL: http://codereview.chromium.org/9677060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/interface_list.cc | 1 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 23 | ||||
-rw-r--r-- | ppapi/proxy/ppb_network_monitor_private_proxy.cc | 146 | ||||
-rw-r--r-- | ppapi/proxy/ppb_network_monitor_private_proxy.h | 61 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 5 |
5 files changed, 234 insertions, 2 deletions
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( |