Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/proxy/ppb_host_resolver_private_proxy.h" | |
| 6 | |
| 7 #include <cstddef> | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "ppapi/proxy/plugin_dispatcher.h" | |
| 12 #include "ppapi/proxy/plugin_globals.h" | |
| 13 #include "ppapi/proxy/plugin_proxy_delegate.h" | |
| 14 #include "ppapi/proxy/ppapi_messages.h" | |
| 15 #include "ppapi/shared_impl/host_resource.h" | |
| 16 | |
| 17 namespace ppapi { | |
| 18 namespace proxy { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 typedef std::map<uint32, PPB_HostResolver_Shared*> IDToHostResolverMap; | |
| 23 IDToHostResolverMap* g_id_to_host_resolver = NULL; | |
| 24 | |
| 25 class HostResolver : public PPB_HostResolver_Shared { | |
| 26 public: | |
| 27 HostResolver(const HostResource& resource, | |
| 28 uint32 plugin_dispatcher_id); | |
| 29 virtual ~HostResolver(); | |
| 30 | |
| 31 virtual void SendResolve(const HostPortPair& host_port, | |
| 32 const PP_HostResolver_Private_Hint* hint) OVERRIDE; | |
| 33 | |
| 34 private: | |
| 35 void SendToBrowser(IPC::Message* msg); | |
| 36 | |
| 37 const uint32 plugin_dispatcher_id_; | |
| 38 | |
| 39 DISALLOW_COPY_AND_ASSIGN(HostResolver); | |
| 40 }; | |
| 41 | |
| 42 HostResolver::HostResolver(const HostResource& resource, | |
| 43 uint32 plugin_dispatcher_id) | |
| 44 : PPB_HostResolver_Shared(resource), | |
| 45 plugin_dispatcher_id_(plugin_dispatcher_id) { | |
| 46 if (!g_id_to_host_resolver) | |
| 47 g_id_to_host_resolver = new IDToHostResolverMap(); | |
| 48 DCHECK(g_id_to_host_resolver->find(host_resolver_id_) == | |
| 49 g_id_to_host_resolver->end()); | |
| 50 (*g_id_to_host_resolver)[host_resolver_id_] = this; | |
|
yzshen1
2012/02/29 19:11:49
Should you remove entries somewhere?
ygorshenin1
2012/03/01 09:37:34
Thanks for pointing this out. I added cleanup code
| |
| 51 } | |
| 52 | |
| 53 HostResolver::~HostResolver() { | |
| 54 } | |
| 55 | |
| 56 void HostResolver::SendResolve(const HostPortPair& host_port, | |
| 57 const PP_HostResolver_Private_Hint* hint) { | |
| 58 SendToBrowser(new PpapiHostMsg_PPBHostResolver_Resolve( | |
| 59 API_ID_PPB_HOSTRESOLVER_PRIVATE, | |
| 60 plugin_dispatcher_id_, | |
| 61 host_resolver_id_, | |
| 62 host_port, | |
| 63 *hint)); | |
| 64 } | |
| 65 | |
| 66 void HostResolver::SendToBrowser(IPC::Message* msg) { | |
| 67 PluginGlobals::Get()->plugin_proxy_delegate()->SendToBrowser(msg); | |
| 68 } | |
| 69 | |
| 70 } // namespace | |
| 71 | |
| 72 //------------------------------------------------------------------------------ | |
| 73 | |
| 74 PPB_HostResolver_Private_Proxy::PPB_HostResolver_Private_Proxy( | |
| 75 Dispatcher* dispatcher) : InterfaceProxy(dispatcher) { | |
| 76 } | |
| 77 | |
| 78 PPB_HostResolver_Private_Proxy::~PPB_HostResolver_Private_Proxy() { | |
| 79 } | |
| 80 | |
| 81 // static | |
| 82 PP_Resource PPB_HostResolver_Private_Proxy::CreateProxyResource( | |
| 83 PP_Instance instance) { | |
| 84 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
| 85 if (!dispatcher) | |
| 86 return 0; | |
| 87 | |
| 88 HostResolver* host_resolver = | |
| 89 new HostResolver(HostResource::MakeInstanceOnly(instance), | |
| 90 dispatcher->plugin_dispatcher_id()); | |
| 91 return host_resolver->GetReference(); | |
| 92 } | |
| 93 | |
| 94 bool PPB_HostResolver_Private_Proxy::OnMessageReceived( | |
| 95 const IPC::Message& msg) { | |
| 96 bool handled = true; | |
| 97 IPC_BEGIN_MESSAGE_MAP(PPB_HostResolver_Private_Proxy, msg) | |
| 98 IPC_MESSAGE_HANDLER(PpapiMsg_PPBHostResolver_ResolveACK, OnMsgResolveACK) | |
| 99 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 100 IPC_END_MESSAGE_MAP() | |
| 101 return handled; | |
| 102 } | |
| 103 | |
| 104 void PPB_HostResolver_Private_Proxy::OnMsgResolveACK( | |
| 105 uint32 plugin_dispatcher_id, | |
| 106 uint32 host_resolver_id, | |
| 107 bool succeeded, | |
| 108 const ppapi::NetworkList& network_list) { | |
| 109 if (!g_id_to_host_resolver) { | |
| 110 NOTREACHED(); | |
| 111 return; | |
| 112 } | |
| 113 IDToHostResolverMap::iterator it = | |
| 114 g_id_to_host_resolver->find(host_resolver_id); | |
| 115 if (it == g_id_to_host_resolver->end()) | |
| 116 return; | |
| 117 it->second->OnResolveCompleted(succeeded, network_list); | |
| 118 } | |
| 119 | |
| 120 } // namespace proxy | |
| 121 } // namespace ppapi | |
| OLD | NEW |