Rename GDataSystemService to DriveSystemService
[chromium-blink-merge.git] / ppapi / proxy / dispatcher.cc
blob3ef2c270a39505f84a7ba9684b2eb9027c39d2a0
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.
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(PP_GetInterface_Func local_get_interface)
21 : disallow_trusted_interfaces_(false), // TODO(brettw) make this settable.
22 local_get_interface_(local_get_interface) {
25 Dispatcher::~Dispatcher() {
28 void Dispatcher::AddFilter(IPC::Listener* listener) {
29 filters_.push_back(listener);
32 InterfaceProxy* Dispatcher::GetInterfaceProxy(ApiID id) {
33 InterfaceProxy* proxy = proxies_[id].get();
34 if (!proxy) {
35 // Handle the first time for a given API by creating the proxy for it.
36 InterfaceProxy::Factory factory =
37 InterfaceList::GetInstance()->GetFactoryForID(id);
38 if (!factory) {
39 NOTREACHED();
40 return NULL;
42 proxy = factory(this);
43 DCHECK(proxy);
44 proxies_[id].reset(proxy);
46 return proxy;
49 base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() {
50 return delegate()->GetIPCMessageLoop();
53 void Dispatcher::AddIOThreadMessageFilter(
54 IPC::ChannelProxy::MessageFilter* filter) {
55 // Our filter is refcounted. The channel will call the destruct method on the
56 // filter when the channel is done with it, so the corresponding Release()
57 // happens there.
58 channel()->AddFilter(filter);
61 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) {
62 if (msg.routing_id() <= 0 || msg.routing_id() >= API_ID_COUNT) {
63 OnInvalidMessageReceived();
64 return true;
67 InterfaceProxy* proxy = GetInterfaceProxy(
68 static_cast<ApiID>(msg.routing_id()));
69 if (!proxy) {
70 NOTREACHED();
71 return true;
73 return proxy->OnMessageReceived(msg);
76 void Dispatcher::SetSerializationRules(
77 VarSerializationRules* var_serialization_rules) {
78 serialization_rules_ = var_serialization_rules;
81 void Dispatcher::OnInvalidMessageReceived() {
84 } // namespace proxy
85 } // namespace ppapi