Make sure webrtc::VideoSource is released when WebRtcVideoTrackAdapter is destroyed.
[chromium-blink-merge.git] / ppapi / proxy / dispatcher.cc
blob786c24d8b074380b127bf27202ceb66ba060ebb8
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 IPC {
18 class MessageFilter;
21 namespace ppapi {
22 namespace proxy {
24 Dispatcher::Dispatcher(PP_GetInterface_Func local_get_interface,
25 const PpapiPermissions& permissions)
26 : local_get_interface_(local_get_interface),
27 permissions_(permissions) {
30 Dispatcher::~Dispatcher() {
33 InterfaceProxy* Dispatcher::GetInterfaceProxy(ApiID id) {
34 InterfaceProxy* proxy = proxies_[id].get();
35 if (!proxy) {
36 // Handle the first time for a given API by creating the proxy for it.
37 InterfaceProxy::Factory factory =
38 InterfaceList::GetInstance()->GetFactoryForID(id);
39 if (!factory) {
40 NOTREACHED();
41 return NULL;
43 proxy = factory(this);
44 DCHECK(proxy);
45 proxies_[id].reset(proxy);
47 return proxy;
50 void Dispatcher::AddIOThreadMessageFilter(IPC::MessageFilter* filter) {
51 // Our filter is refcounted. The channel will call the destruct method on the
52 // filter when the channel is done with it, so the corresponding Release()
53 // happens there.
54 channel()->AddFilter(filter);
57 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) {
58 if (msg.routing_id() <= 0 || msg.routing_id() >= API_ID_COUNT) {
59 OnInvalidMessageReceived();
60 return true;
63 InterfaceProxy* proxy = GetInterfaceProxy(
64 static_cast<ApiID>(msg.routing_id()));
65 if (!proxy) {
66 NOTREACHED();
67 return true;
69 return proxy->OnMessageReceived(msg);
72 void Dispatcher::SetSerializationRules(
73 VarSerializationRules* var_serialization_rules) {
74 serialization_rules_ = var_serialization_rules;
77 void Dispatcher::OnInvalidMessageReceived() {
80 } // namespace proxy
81 } // namespace ppapi