dispatcher.cc revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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/dispatcher.h" 6 7#include <string.h> // For memset. 8 9#include <map> 10 11#include "base/compiler_specific.h" 12#include "base/logging.h" 13#include "base/memory/singleton.h" 14#include "ppapi/proxy/ppapi_messages.h" 15#include "ppapi/proxy/var_serialization_rules.h" 16 17namespace ppapi { 18namespace proxy { 19 20Dispatcher::Dispatcher(PP_GetInterface_Func local_get_interface, 21 const PpapiPermissions& permissions) 22 : local_get_interface_(local_get_interface), 23 permissions_(permissions) { 24} 25 26Dispatcher::~Dispatcher() { 27} 28 29InterfaceProxy* Dispatcher::GetInterfaceProxy(ApiID id) { 30 InterfaceProxy* proxy = proxies_[id].get(); 31 if (!proxy) { 32 // Handle the first time for a given API by creating the proxy for it. 33 InterfaceProxy::Factory factory = 34 InterfaceList::GetInstance()->GetFactoryForID(id); 35 if (!factory) { 36 NOTREACHED(); 37 return NULL; 38 } 39 proxy = factory(this); 40 DCHECK(proxy); 41 proxies_[id].reset(proxy); 42 } 43 return proxy; 44} 45 46void Dispatcher::AddIOThreadMessageFilter( 47 IPC::ChannelProxy::MessageFilter* filter) { 48 // Our filter is refcounted. The channel will call the destruct method on the 49 // filter when the channel is done with it, so the corresponding Release() 50 // happens there. 51 channel()->AddFilter(filter); 52} 53 54bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { 55 if (msg.routing_id() <= 0 || msg.routing_id() >= API_ID_COUNT) { 56 OnInvalidMessageReceived(); 57 return true; 58 } 59 60 InterfaceProxy* proxy = GetInterfaceProxy( 61 static_cast<ApiID>(msg.routing_id())); 62 if (!proxy) { 63 NOTREACHED(); 64 return true; 65 } 66 return proxy->OnMessageReceived(msg); 67} 68 69void Dispatcher::SetSerializationRules( 70 VarSerializationRules* var_serialization_rules) { 71 serialization_rules_ = var_serialization_rules; 72} 73 74void Dispatcher::OnInvalidMessageReceived() { 75} 76 77} // namespace proxy 78} // namespace ppapi 79