Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: ppapi/proxy/plugin_message_filter.cc

Issue 46433002: Support using TrackedCallbacks as hints to determine the handling thread of resource reply messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/plugin_message_filter.h" 5 #include "ppapi/proxy/plugin_message_filter.h"
6 6
7 #include "base/bind.h"
8 #include "base/logging.h"
7 #include "ppapi/proxy/ppapi_messages.h" 9 #include "ppapi/proxy/ppapi_messages.h"
10 #include "ppapi/proxy/resource_message_params.h"
11 #include "ppapi/proxy/resource_reply_thread_registrar.h"
12 #include "ppapi/shared_impl/ppapi_globals.h"
13 #include "ppapi/shared_impl/proxy_lock.h"
14 #include "ppapi/shared_impl/resource.h"
15 #include "ppapi/shared_impl/resource_tracker.h"
8 16
9 namespace ppapi { 17 namespace ppapi {
10 namespace proxy { 18 namespace proxy {
11 19
12 PluginMessageFilter::PluginMessageFilter( 20 PluginMessageFilter::PluginMessageFilter(
13 std::set<PP_Instance>* seen_instance_ids) 21 std::set<PP_Instance>* seen_instance_ids,
22 scoped_refptr<ResourceReplyThreadRegistrar> registrar)
14 : seen_instance_ids_(seen_instance_ids), 23 : seen_instance_ids_(seen_instance_ids),
24 resource_reply_thread_registrar_(registrar),
15 channel_(NULL) { 25 channel_(NULL) {
16 } 26 }
17 27
18 PluginMessageFilter::~PluginMessageFilter() { 28 PluginMessageFilter::~PluginMessageFilter() {
19 } 29 }
20 30
21 void PluginMessageFilter::OnFilterAdded(IPC::Channel* channel) { 31 void PluginMessageFilter::OnFilterAdded(IPC::Channel* channel) {
22 channel_ = channel; 32 channel_ = channel;
23 } 33 }
24 34
25 void PluginMessageFilter::OnFilterRemoved() { 35 void PluginMessageFilter::OnFilterRemoved() {
26 channel_ = NULL; 36 channel_ = NULL;
27 } 37 }
28 38
29 bool PluginMessageFilter::OnMessageReceived(const IPC::Message& message) { 39 bool PluginMessageFilter::OnMessageReceived(const IPC::Message& message) {
30 bool handled = true; 40 bool handled = true;
31 IPC_BEGIN_MESSAGE_MAP(PluginMessageFilter, message) 41 IPC_BEGIN_MESSAGE_MAP(PluginMessageFilter, message)
32 IPC_MESSAGE_HANDLER(PpapiMsg_ReserveInstanceId, OnMsgReserveInstanceId) 42 IPC_MESSAGE_HANDLER(PpapiMsg_ReserveInstanceId, OnMsgReserveInstanceId)
43 IPC_MESSAGE_HANDLER(PpapiPluginMsg_ResourceReply, OnMsgResourceReply)
33 IPC_MESSAGE_UNHANDLED(handled = false) 44 IPC_MESSAGE_UNHANDLED(handled = false)
34 IPC_END_MESSAGE_MAP() 45 IPC_END_MESSAGE_MAP()
35 return handled; 46 return handled;
36 } 47 }
37 48
38 bool PluginMessageFilter::Send(IPC::Message* msg) { 49 bool PluginMessageFilter::Send(IPC::Message* msg) {
39 if (channel_) 50 if (channel_)
40 return channel_->Send(msg); 51 return channel_->Send(msg);
41 delete msg; 52 delete msg;
42 return false; 53 return false;
43 } 54 }
44 55
56 // static
57 void PluginMessageFilter::DispatchResourceReplyForTest(
58 const ResourceMessageReplyParams& reply_params,
59 const IPC::Message& nested_msg) {
60 DispatchResourceReply(reply_params, nested_msg);
61 }
62
45 void PluginMessageFilter::OnMsgReserveInstanceId(PP_Instance instance, 63 void PluginMessageFilter::OnMsgReserveInstanceId(PP_Instance instance,
46 bool* usable) { 64 bool* usable) {
47 // See the message definition for how this works. 65 // See the message definition for how this works.
48 if (seen_instance_ids_->find(instance) != seen_instance_ids_->end()) { 66 if (seen_instance_ids_->find(instance) != seen_instance_ids_->end()) {
49 // Instance ID already seen, reject it. 67 // Instance ID already seen, reject it.
50 *usable = false; 68 *usable = false;
51 return; 69 return;
52 } 70 }
53 71
54 // This instance ID is new so we can return that it's usable and mark it as 72 // This instance ID is new so we can return that it's usable and mark it as
55 // used for future reference. 73 // used for future reference.
56 seen_instance_ids_->insert(instance); 74 seen_instance_ids_->insert(instance);
57 *usable = true; 75 *usable = true;
58 } 76 }
59 77
78 void PluginMessageFilter::OnMsgResourceReply(
79 const ResourceMessageReplyParams& reply_params,
80 const IPC::Message& nested_msg) {
81 // TODO(yzshen): Bind() will do an extra copy, do I need to somehow eliminate
82 // it? Compare with the previous code.
83 scoped_refptr<base::MessageLoopProxy> target =
84 resource_reply_thread_registrar_->GetTargetThread(
85 reply_params.pp_resource(), reply_params.sequence());
86
87 target->PostTask(
88 FROM_HERE,
89 base::Bind(&DispatchResourceReply, reply_params, nested_msg));
90 }
91
92 // TODO(yzshen): I think new resources in in-process mode don't use plugin
93 // dispatcher, make sure that is right.
94 // static
95 void PluginMessageFilter::DispatchResourceReply(
96 const ResourceMessageReplyParams& reply_params,
97 const IPC::Message& nested_msg) {
98 ProxyAutoLock lock;
99 Resource* resource = PpapiGlobals::Get()->GetResourceTracker()->GetResource(
100 reply_params.pp_resource());
101 if (!resource) {
102 DVLOG_IF(1, reply_params.sequence() != 0)
103 << "Pepper resource reply message received but the resource doesn't "
104 "exist (probably has been destroyed).";
105 return;
106 }
107 resource->OnReplyReceived(reply_params, nested_msg);
108 }
109
60 } // namespace proxy 110 } // namespace proxy
61 } // namespace ppapi 111 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698