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

Side by Side Diff: content/ppapi_plugin/ppapi_thread.cc

Issue 7655002: Convert the pp::proxy namespace to the ppapi::proxy namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months 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 "content/ppapi_plugin/ppapi_thread.h" 5 #include "content/ppapi_plugin/ppapi_thread.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 local_pp_module_( 44 local_pp_module_(
45 base::RandInt(0, std::numeric_limits<PP_Module>::max())), 45 base::RandInt(0, std::numeric_limits<PP_Module>::max())),
46 next_plugin_dispatcher_id_(1) { 46 next_plugin_dispatcher_id_(1) {
47 } 47 }
48 48
49 PpapiThread::~PpapiThread() { 49 PpapiThread::~PpapiThread() {
50 if (!library_.is_valid()) 50 if (!library_.is_valid())
51 return; 51 return;
52 52
53 // The ShutdownModule/ShutdownBroker function is optional. 53 // The ShutdownModule/ShutdownBroker function is optional.
54 pp::proxy::ProxyChannel::ShutdownModuleFunc shutdown_function = 54 ppapi::proxy::ProxyChannel::ShutdownModuleFunc shutdown_function =
55 is_broker_ ? 55 is_broker_ ?
56 reinterpret_cast<pp::proxy::ProxyChannel::ShutdownModuleFunc>( 56 reinterpret_cast<ppapi::proxy::ProxyChannel::ShutdownModuleFunc>(
57 library_.GetFunctionPointer("PPP_ShutdownBroker")) : 57 library_.GetFunctionPointer("PPP_ShutdownBroker")) :
58 reinterpret_cast<pp::proxy::ProxyChannel::ShutdownModuleFunc>( 58 reinterpret_cast<ppapi::proxy::ProxyChannel::ShutdownModuleFunc>(
59 library_.GetFunctionPointer("PPP_ShutdownModule")); 59 library_.GetFunctionPointer("PPP_ShutdownModule"));
60 if (shutdown_function) 60 if (shutdown_function)
61 shutdown_function(); 61 shutdown_function();
62 } 62 }
63 63
64 // The "regular" ChildThread implements this function and does some standard 64 // The "regular" ChildThread implements this function and does some standard
65 // dispatching, then uses the message router. We don't actually need any of 65 // dispatching, then uses the message router. We don't actually need any of
66 // this so this function just overrides that one. 66 // this so this function just overrides that one.
67 // 67 //
68 // Note that this function is called only for messages from the channel to the 68 // Note that this function is called only for messages from the channel to the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 const base::Closure& task) { 105 const base::Closure& task) {
106 if (!webkit_thread_.get()) 106 if (!webkit_thread_.get())
107 webkit_thread_.reset(new PpapiWebKitThread); 107 webkit_thread_.reset(new PpapiWebKitThread);
108 webkit_thread_->PostTask(from_here, task); 108 webkit_thread_->PostTask(from_here, task);
109 } 109 }
110 110
111 bool PpapiThread::SendToBrowser(IPC::Message* msg) { 111 bool PpapiThread::SendToBrowser(IPC::Message* msg) {
112 return Send(msg); 112 return Send(msg);
113 } 113 }
114 114
115 uint32 PpapiThread::Register(pp::proxy::PluginDispatcher* plugin_dispatcher) { 115 uint32 PpapiThread::Register(ppapi::proxy::PluginDispatcher* plugin_dispatcher) {
116 if (!plugin_dispatcher || 116 if (!plugin_dispatcher ||
117 plugin_dispatchers_.size() >= std::numeric_limits<uint32>::max()) { 117 plugin_dispatchers_.size() >= std::numeric_limits<uint32>::max()) {
118 return 0; 118 return 0;
119 } 119 }
120 120
121 uint32 id = 0; 121 uint32 id = 0;
122 do { 122 do {
123 // Although it is unlikely, make sure that we won't cause any trouble when 123 // Although it is unlikely, make sure that we won't cause any trouble when
124 // the counter overflows. 124 // the counter overflows.
125 id = next_plugin_dispatcher_id_++; 125 id = next_plugin_dispatcher_id_++;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 LOG(WARNING) << "InitBroker failed with error " << init_error; 172 LOG(WARNING) << "InitBroker failed with error " << init_error;
173 return; 173 return;
174 } 174 }
175 if (!connect_instance_func_) { 175 if (!connect_instance_func_) {
176 LOG(WARNING) << "InitBroker did not provide PP_ConnectInstance_Func"; 176 LOG(WARNING) << "InitBroker did not provide PP_ConnectInstance_Func";
177 return; 177 return;
178 } 178 }
179 } else { 179 } else {
180 // Get the GetInterface function (required). 180 // Get the GetInterface function (required).
181 get_plugin_interface_ = 181 get_plugin_interface_ =
182 reinterpret_cast<pp::proxy::Dispatcher::GetInterfaceFunc>( 182 reinterpret_cast<ppapi::proxy::Dispatcher::GetInterfaceFunc>(
183 library.GetFunctionPointer("PPP_GetInterface")); 183 library.GetFunctionPointer("PPP_GetInterface"));
184 if (!get_plugin_interface_) { 184 if (!get_plugin_interface_) {
185 LOG(WARNING) << "No PPP_GetInterface in plugin library"; 185 LOG(WARNING) << "No PPP_GetInterface in plugin library";
186 return; 186 return;
187 } 187 }
188 188
189 #if defined(OS_MACOSX) 189 #if defined(OS_MACOSX)
190 // We need to do this after getting |PPP_GetInterface()| (or presumably 190 // We need to do this after getting |PPP_GetInterface()| (or presumably
191 // doing something nontrivial with the library), else the sandbox 191 // doing something nontrivial with the library), else the sandbox
192 // intercedes. 192 // intercedes.
193 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess(); 193 CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
194 SandboxInitWrapper sandbox_wrapper; 194 SandboxInitWrapper sandbox_wrapper;
195 if (!sandbox_wrapper.InitializeSandbox(*parsed_command_line, 195 if (!sandbox_wrapper.InitializeSandbox(*parsed_command_line,
196 switches::kPpapiPluginProcess)) 196 switches::kPpapiPluginProcess))
197 LOG(WARNING) << "Failed to initialize sandbox"; 197 LOG(WARNING) << "Failed to initialize sandbox";
198 #endif 198 #endif
199 199
200 // Get the InitializeModule function (required). 200 // Get the InitializeModule function (required).
201 pp::proxy::Dispatcher::InitModuleFunc init_module = 201 ppapi::proxy::Dispatcher::InitModuleFunc init_module =
202 reinterpret_cast<pp::proxy::Dispatcher::InitModuleFunc>( 202 reinterpret_cast<ppapi::proxy::Dispatcher::InitModuleFunc>(
203 library.GetFunctionPointer("PPP_InitializeModule")); 203 library.GetFunctionPointer("PPP_InitializeModule"));
204 if (!init_module) { 204 if (!init_module) {
205 LOG(WARNING) << "No PPP_InitializeModule in plugin library"; 205 LOG(WARNING) << "No PPP_InitializeModule in plugin library";
206 return; 206 return;
207 } 207 }
208 int32_t init_error = init_module( 208 int32_t init_error = init_module(
209 local_pp_module_, 209 local_pp_module_,
210 &pp::proxy::PluginDispatcher::GetInterfaceFromDispatcher); 210 &ppapi::proxy::PluginDispatcher::GetInterfaceFromDispatcher);
211 if (init_error != PP_OK) { 211 if (init_error != PP_OK) {
212 LOG(WARNING) << "InitModule failed with error " << init_error; 212 LOG(WARNING) << "InitModule failed with error " << init_error;
213 return; 213 return;
214 } 214 }
215 } 215 }
216 216
217 library_.Reset(library.Release()); 217 library_.Reset(library.Release());
218 } 218 }
219 219
220 void PpapiThread::OnMsgCreateChannel(base::ProcessHandle host_process_handle, 220 void PpapiThread::OnMsgCreateChannel(base::ProcessHandle host_process_handle,
(...skipping 19 matching lines...) Expand all
240 } 240 }
241 241
242 void PpapiThread::OnPluginDispatcherMessageReceived(const IPC::Message& msg) { 242 void PpapiThread::OnPluginDispatcherMessageReceived(const IPC::Message& msg) {
243 // The first parameter should be a plugin dispatcher ID. 243 // The first parameter should be a plugin dispatcher ID.
244 void* iter = NULL; 244 void* iter = NULL;
245 uint32 id = 0; 245 uint32 id = 0;
246 if (!msg.ReadUInt32(&iter, &id)) { 246 if (!msg.ReadUInt32(&iter, &id)) {
247 NOTREACHED(); 247 NOTREACHED();
248 return; 248 return;
249 } 249 }
250 std::map<uint32, pp::proxy::PluginDispatcher*>::iterator dispatcher = 250 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher =
251 plugin_dispatchers_.find(id); 251 plugin_dispatchers_.find(id);
252 if (dispatcher != plugin_dispatchers_.end()) 252 if (dispatcher != plugin_dispatchers_.end())
253 dispatcher->second->OnMessageReceived(msg); 253 dispatcher->second->OnMessageReceived(msg);
254 } 254 }
255 255
256 bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, 256 bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle,
257 int renderer_id, 257 int renderer_id,
258 IPC::ChannelHandle* handle) { 258 IPC::ChannelHandle* handle) {
259 DCHECK(is_broker_ == (connect_instance_func_ != NULL)); 259 DCHECK(is_broker_ == (connect_instance_func_ != NULL));
260 DCHECK(is_broker_ == (get_plugin_interface_ == NULL)); 260 DCHECK(is_broker_ == (get_plugin_interface_ == NULL));
261 IPC::ChannelHandle plugin_handle; 261 IPC::ChannelHandle plugin_handle;
262 plugin_handle.name = StringPrintf("%d.r%d", base::GetCurrentProcId(), 262 plugin_handle.name = StringPrintf("%d.r%d", base::GetCurrentProcId(),
263 renderer_id); 263 renderer_id);
264 264
265 pp::proxy::ProxyChannel* dispatcher = NULL; 265 ppapi::proxy::ProxyChannel* dispatcher = NULL;
266 bool init_result = false; 266 bool init_result = false;
267 if (is_broker_) { 267 if (is_broker_) {
268 BrokerProcessDispatcher* broker_dispatcher = 268 BrokerProcessDispatcher* broker_dispatcher =
269 new BrokerProcessDispatcher(host_process_handle, 269 new BrokerProcessDispatcher(host_process_handle,
270 connect_instance_func_); 270 connect_instance_func_);
271 init_result = broker_dispatcher->InitBrokerWithChannel(this, 271 init_result = broker_dispatcher->InitBrokerWithChannel(this,
272 plugin_handle, 272 plugin_handle,
273 false); 273 false);
274 dispatcher = broker_dispatcher; 274 dispatcher = broker_dispatcher;
275 } else { 275 } else {
(...skipping 14 matching lines...) Expand all
290 #if defined(OS_POSIX) 290 #if defined(OS_POSIX)
291 // On POSIX, pass the renderer-side FD. 291 // On POSIX, pass the renderer-side FD.
292 handle->socket = base::FileDescriptor(::dup(dispatcher->GetRendererFD()), 292 handle->socket = base::FileDescriptor(::dup(dispatcher->GetRendererFD()),
293 true); 293 true);
294 #endif 294 #endif
295 295
296 // From here, the dispatcher will manage its own lifetime according to the 296 // From here, the dispatcher will manage its own lifetime according to the
297 // lifetime of the attached channel. 297 // lifetime of the attached channel.
298 return true; 298 return true;
299 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698