Convert TestOldCompletionCallback in WebSocketJobTest.
[chromium-blink-merge.git] / ppapi / proxy / dispatcher.cc
blob8ba7830b1160a57834e3df948e23c2adc7533004
1 // Copyright (c) 2011 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.
5 #include "ppapi/proxy/dispatcher.h"
7 #include <string.h> // For memset.
9 #include <map>
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"
17 namespace ppapi {
18 namespace proxy {
20 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle,
21 GetInterfaceFunc local_get_interface)
22 : ProxyChannel(remote_process_handle),
23 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable.
24 local_get_interface_(local_get_interface) {
27 Dispatcher::~Dispatcher() {
30 InterfaceProxy* Dispatcher::GetInterfaceProxy(ApiID id) {
31 InterfaceProxy* proxy = proxies_[id].get();
32 if (!proxy) {
33 // Handle the first time for a given API by creating the proxy for it.
34 InterfaceProxy::Factory factory =
35 InterfaceList::GetInstance()->GetFactoryForID(id);
36 if (!factory) {
37 NOTREACHED();
38 return NULL;
40 proxy = factory(this);
41 DCHECK(proxy);
42 proxies_[id].reset(proxy);
44 return proxy;
47 base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() {
48 return delegate()->GetIPCMessageLoop();
51 void Dispatcher::AddIOThreadMessageFilter(
52 IPC::ChannelProxy::MessageFilter* filter) {
53 channel()->AddFilter(filter);
56 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) {
57 if (msg.routing_id() <= 0 || msg.routing_id() >= API_ID_COUNT) {
58 OnInvalidMessageReceived();
59 return true;
62 InterfaceProxy* proxy = GetInterfaceProxy(
63 static_cast<ApiID>(msg.routing_id()));
64 if (!proxy) {
65 NOTREACHED();
66 return true;
68 return proxy->OnMessageReceived(msg);
71 void Dispatcher::SetSerializationRules(
72 VarSerializationRules* var_serialization_rules) {
73 serialization_rules_.reset(var_serialization_rules);
76 void Dispatcher::OnInvalidMessageReceived() {
79 } // namespace proxy
80 } // namespace ppapi