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

Side by Side Diff: ppapi/proxy/plugin_main_nacl.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: . 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) 2012 The Chromium Authors. All rights reserved. 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 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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 // Need to include this before most other files because it defines 9 // Need to include this before most other files because it defines
10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define 10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define
11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the 11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the
12 // ViewMsgLog et al. functions. 12 // ViewMsgLog et al. functions.
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "components/tracing/child_trace_message_filter.h" 18 #include "components/tracing/child_trace_message_filter.h"
19 #include "ipc/ipc_channel_handle.h" 19 #include "ipc/ipc_channel_handle.h"
20 #include "ipc/ipc_logging.h" 20 #include "ipc/ipc_logging.h"
21 #include "ipc/ipc_message.h" 21 #include "ipc/ipc_message.h"
22 #include "native_client/src/shared/srpc/nacl_srpc.h" 22 #include "native_client/src/shared/srpc/nacl_srpc.h"
23 #include "native_client/src/untrusted/irt/irt_ppapi.h" 23 #include "native_client/src/untrusted/irt/irt_ppapi.h"
24 #include "ppapi/c/ppp.h" 24 #include "ppapi/c/ppp.h"
25 #include "ppapi/c/ppp_instance.h" 25 #include "ppapi/c/ppp_instance.h"
26 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" 26 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h"
27 #include "ppapi/proxy/plugin_dispatcher.h" 27 #include "ppapi/proxy/plugin_dispatcher.h"
28 #include "ppapi/proxy/plugin_globals.h" 28 #include "ppapi/proxy/plugin_globals.h"
29 #include "ppapi/proxy/plugin_message_filter.h"
29 #include "ppapi/proxy/plugin_proxy_delegate.h" 30 #include "ppapi/proxy/plugin_proxy_delegate.h"
31 #include "ppapi/proxy/resource_reply_thread_registrar.h"
30 #include "ppapi/shared_impl/ppb_audio_shared.h" 32 #include "ppapi/shared_impl/ppb_audio_shared.h"
31 33
32 #if defined(IPC_MESSAGE_LOG_ENABLED) 34 #if defined(IPC_MESSAGE_LOG_ENABLED)
33 #include "base/containers/hash_tables.h" 35 #include "base/containers/hash_tables.h"
34 36
35 LogFunctionMap g_log_function_mapping; 37 LogFunctionMap g_log_function_mapping;
36 38
37 #define IPC_MESSAGE_MACROS_LOG_ENABLED 39 #define IPC_MESSAGE_MACROS_LOG_ENABLED
38 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ 40 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \
39 g_log_function_mapping[msg_id] = logger 41 g_log_function_mapping[msg_id] = logger
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 const PP_BrowserFont_Trusted_Description& desc, 86 const PP_BrowserFont_Trusted_Description& desc,
85 const ppapi::Preferences& prefs) OVERRIDE; 87 const ppapi::Preferences& prefs) OVERRIDE;
86 88
87 // IPC::Listener implementation. 89 // IPC::Listener implementation.
88 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 90 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
89 91
90 private: 92 private:
91 void OnMsgCreateNaClChannel(int renderer_id, 93 void OnMsgCreateNaClChannel(int renderer_id,
92 const ppapi::PpapiNaClChannelArgs& args, 94 const ppapi::PpapiNaClChannelArgs& args,
93 SerializedHandle handle); 95 SerializedHandle handle);
94 void OnMsgResourceReply(
95 const ppapi::proxy::ResourceMessageReplyParams& reply_params,
96 const IPC::Message& nested_msg);
97 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); 96 void OnPluginDispatcherMessageReceived(const IPC::Message& msg);
98 97
99 std::set<PP_Instance> instances_; 98 std::set<PP_Instance> instances_;
100 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; 99 std::map<uint32, PluginDispatcher*> plugin_dispatchers_;
101 uint32 next_plugin_dispatcher_id_; 100 uint32 next_plugin_dispatcher_id_;
102 scoped_refptr<base::MessageLoopProxy> message_loop_; 101 scoped_refptr<base::MessageLoopProxy> message_loop_;
103 base::WaitableEvent shutdown_event_; 102 base::WaitableEvent shutdown_event_;
104 }; 103 };
105 104
106 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) 105 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop)
107 : next_plugin_dispatcher_id_(0), 106 : next_plugin_dispatcher_id_(0),
108 message_loop_(io_loop), 107 message_loop_(io_loop),
109 shutdown_event_(true, false) { 108 shutdown_event_(true, false) {
110 IPC::ChannelHandle channel_handle( 109 IPC::ChannelHandle channel_handle(
111 "NaCl IPC", base::FileDescriptor(NACL_IPC_FD, false)); 110 "NaCl IPC", base::FileDescriptor(NACL_IPC_FD, false));
112 // We don't have/need a PID since handle sharing happens outside of the 111 // We don't have/need a PID since handle sharing happens outside of the
113 // NaCl sandbox. 112 // NaCl sandbox.
114 InitWithChannel(this, base::kNullProcessId, channel_handle, 113 InitWithChannel(this, base::kNullProcessId, channel_handle,
115 false); // Channel is server. 114 false); // Channel is server.
115 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter(
116 NULL, PluginGlobals::Get()->resource_reply_thread_registrar()));
dmichael (off chromium) 2013/12/11 21:30:36 Why do we need this *and* the one that PluginDispa
yzshen1 2013/12/11 22:22:07 Please see my comment in ppapi_thread.cc.
116 channel()->AddFilter( 117 channel()->AddFilter(
117 new tracing::ChildTraceMessageFilter(message_loop_.get())); 118 new tracing::ChildTraceMessageFilter(message_loop_.get()));
118 } 119 }
119 120
120 base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() { 121 base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() {
121 return message_loop_.get(); 122 return message_loop_.get();
122 } 123 }
123 124
124 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() { 125 base::WaitableEvent* PpapiDispatcher::GetShutdownEvent() {
125 return &shutdown_event_; 126 return &shutdown_event_;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 PP_Instance instance, 180 PP_Instance instance,
180 const PP_BrowserFont_Trusted_Description& desc, 181 const PP_BrowserFont_Trusted_Description& desc,
181 const ppapi::Preferences& prefs) { 182 const ppapi::Preferences& prefs) {
182 NOTIMPLEMENTED(); 183 NOTIMPLEMENTED();
183 return 0; 184 return 0;
184 } 185 }
185 186
186 bool PpapiDispatcher::OnMessageReceived(const IPC::Message& msg) { 187 bool PpapiDispatcher::OnMessageReceived(const IPC::Message& msg) {
187 IPC_BEGIN_MESSAGE_MAP(PpapiDispatcher, msg) 188 IPC_BEGIN_MESSAGE_MAP(PpapiDispatcher, msg)
188 IPC_MESSAGE_HANDLER(PpapiMsg_CreateNaClChannel, OnMsgCreateNaClChannel) 189 IPC_MESSAGE_HANDLER(PpapiMsg_CreateNaClChannel, OnMsgCreateNaClChannel)
189 IPC_MESSAGE_HANDLER(PpapiPluginMsg_ResourceReply, OnMsgResourceReply)
190 // All other messages are simply forwarded to a PluginDispatcher. 190 // All other messages are simply forwarded to a PluginDispatcher.
191 IPC_MESSAGE_UNHANDLED(OnPluginDispatcherMessageReceived(msg)) 191 IPC_MESSAGE_UNHANDLED(OnPluginDispatcherMessageReceived(msg))
192 IPC_END_MESSAGE_MAP() 192 IPC_END_MESSAGE_MAP()
193 return true; 193 return true;
194 } 194 }
195 195
196 void PpapiDispatcher::OnMsgCreateNaClChannel( 196 void PpapiDispatcher::OnMsgCreateNaClChannel(
197 int renderer_id, 197 int renderer_id,
198 const ppapi::PpapiNaClChannelArgs& args, 198 const ppapi::PpapiNaClChannelArgs& args,
199 SerializedHandle handle) { 199 SerializedHandle handle) {
(...skipping 28 matching lines...) Expand all
228 IPC::ChannelHandle channel_handle("nacl", handle.descriptor()); 228 IPC::ChannelHandle channel_handle("nacl", handle.descriptor());
229 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId, 229 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId,
230 channel_handle, false)) { 230 channel_handle, false)) {
231 delete dispatcher; 231 delete dispatcher;
232 return; 232 return;
233 } 233 }
234 // From here, the dispatcher will manage its own lifetime according to the 234 // From here, the dispatcher will manage its own lifetime according to the
235 // lifetime of the attached channel. 235 // lifetime of the attached channel.
236 } 236 }
237 237
238 void PpapiDispatcher::OnMsgResourceReply(
239 const ppapi::proxy::ResourceMessageReplyParams& reply_params,
240 const IPC::Message& nested_msg) {
241 ppapi::proxy::PluginDispatcher::DispatchResourceReply(reply_params,
242 nested_msg);
243 }
244
245 void PpapiDispatcher::OnPluginDispatcherMessageReceived( 238 void PpapiDispatcher::OnPluginDispatcherMessageReceived(
246 const IPC::Message& msg) { 239 const IPC::Message& msg) {
247 // The first parameter should be a plugin dispatcher ID. 240 // The first parameter should be a plugin dispatcher ID.
248 PickleIterator iter(msg); 241 PickleIterator iter(msg);
249 uint32 id = 0; 242 uint32 id = 0;
250 if (!msg.ReadUInt32(&iter, &id)) { 243 if (!msg.ReadUInt32(&iter, &id)) {
251 NOTREACHED(); 244 NOTREACHED();
252 return; 245 return;
253 } 246 }
254 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = 247 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 return 1; 279 return 1;
287 } 280 }
288 281
289 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); 282 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy());
290 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); 283 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher);
291 284
292 loop.Run(); 285 loop.Run();
293 286
294 return 0; 287 return 0;
295 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698