diff options
author | ygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 01:21:27 +0000 |
---|---|---|
committer | ygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 01:21:27 +0000 |
commit | 24931101f4aa1992a91e2117ba5df8307b3b9aa5 (patch) | |
tree | 968d5eddf6f6cb7545a64b3aa9d92148441c17d0 /ppapi/proxy/ppb_host_resolver_private_proxy.cc | |
parent | fbd7f4da37401dc3d79f2c78b59468ce89353c79 (diff) | |
download | chromium_src-24931101f4aa1992a91e2117ba5df8307b3b9aa5.zip chromium_src-24931101f4aa1992a91e2117ba5df8307b3b9aa5.tar.gz chromium_src-24931101f4aa1992a91e2117ba5df8307b3b9aa5.tar.bz2 |
HostResolver is exposed to plugin.
BUG=114225
TEST=UI test TestHostResolverPrivate
Review URL: http://codereview.chromium.org/9455092
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126813 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/ppb_host_resolver_private_proxy.cc')
-rw-r--r-- | ppapi/proxy/ppb_host_resolver_private_proxy.cc | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/ppapi/proxy/ppb_host_resolver_private_proxy.cc b/ppapi/proxy/ppb_host_resolver_private_proxy.cc new file mode 100644 index 0000000..984ef9e --- /dev/null +++ b/ppapi/proxy/ppb_host_resolver_private_proxy.cc @@ -0,0 +1,123 @@ +// 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_host_resolver_private_proxy.h" + +#include <cstddef> +#include <map> + +#include "base/logging.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_globals.h" +#include "ppapi/proxy/plugin_proxy_delegate.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/host_resource.h" + +namespace ppapi { +namespace proxy { + +namespace { + +typedef std::map<uint32, PPB_HostResolver_Shared*> IDToHostResolverMap; +IDToHostResolverMap* g_id_to_host_resolver = NULL; + +class HostResolver : public PPB_HostResolver_Shared { + public: + HostResolver(const HostResource& resource, + uint32 plugin_dispatcher_id); + virtual ~HostResolver(); + + virtual void SendResolve(const HostPortPair& host_port, + const PP_HostResolver_Private_Hint* hint) OVERRIDE; + + private: + void SendToBrowser(IPC::Message* msg); + + const uint32 plugin_dispatcher_id_; + + DISALLOW_COPY_AND_ASSIGN(HostResolver); +}; + +HostResolver::HostResolver(const HostResource& resource, + uint32 plugin_dispatcher_id) + : PPB_HostResolver_Shared(resource), + plugin_dispatcher_id_(plugin_dispatcher_id) { + if (!g_id_to_host_resolver) + g_id_to_host_resolver = new IDToHostResolverMap(); + DCHECK(g_id_to_host_resolver->find(host_resolver_id_) == + g_id_to_host_resolver->end()); + (*g_id_to_host_resolver)[host_resolver_id_] = this; +} + +HostResolver::~HostResolver() { + g_id_to_host_resolver->erase(host_resolver_id_); +} + +void HostResolver::SendResolve(const HostPortPair& host_port, + const PP_HostResolver_Private_Hint* hint) { + SendToBrowser(new PpapiHostMsg_PPBHostResolver_Resolve( + API_ID_PPB_HOSTRESOLVER_PRIVATE, + plugin_dispatcher_id_, + host_resolver_id_, + host_port, + *hint)); +} + +void HostResolver::SendToBrowser(IPC::Message* msg) { + PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser(msg); +} + +} // namespace + +//------------------------------------------------------------------------------ + +PPB_HostResolver_Private_Proxy::PPB_HostResolver_Private_Proxy( + Dispatcher* dispatcher) : InterfaceProxy(dispatcher) { +} + +PPB_HostResolver_Private_Proxy::~PPB_HostResolver_Private_Proxy() { +} + +// static +PP_Resource PPB_HostResolver_Private_Proxy::CreateProxyResource( + PP_Instance instance) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return 0; + + HostResolver* host_resolver = + new HostResolver(HostResource::MakeInstanceOnly(instance), + dispatcher->plugin_dispatcher_id()); + return host_resolver->GetReference(); +} + +bool PPB_HostResolver_Private_Proxy::OnMessageReceived( + const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(PPB_HostResolver_Private_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiMsg_PPBHostResolver_ResolveACK, OnMsgResolveACK) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void PPB_HostResolver_Private_Proxy::OnMsgResolveACK( + uint32 plugin_dispatcher_id, + uint32 host_resolver_id, + bool succeeded, + const std::string& canonical_name, + const ppapi::NetAddressList& net_address_list) { + if (!g_id_to_host_resolver) { + NOTREACHED(); + return; + } + IDToHostResolverMap::iterator it = + g_id_to_host_resolver->find(host_resolver_id); + if (it == g_id_to_host_resolver->end()) + return; + it->second->OnResolveCompleted(succeeded, canonical_name, net_address_list); +} + +} // namespace proxy +} // namespace ppapi |