OLD | NEW |
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 "content/browser/ppapi_plugin_process_host.h" | 5 #include "content/browser/ppapi_plugin_process_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 << "~PpapiPluginProcessHost()"; | 110 << "~PpapiPluginProcessHost()"; |
111 CancelRequests(); | 111 CancelRequests(); |
112 } | 112 } |
113 | 113 |
114 // static | 114 // static |
115 PpapiPluginProcessHost* PpapiPluginProcessHost::CreatePluginHost( | 115 PpapiPluginProcessHost* PpapiPluginProcessHost::CreatePluginHost( |
116 const PepperPluginInfo& info, | 116 const PepperPluginInfo& info, |
117 const base::FilePath& profile_data_directory) { | 117 const base::FilePath& profile_data_directory) { |
118 PpapiPluginProcessHost* plugin_host = new PpapiPluginProcessHost( | 118 PpapiPluginProcessHost* plugin_host = new PpapiPluginProcessHost( |
119 info, profile_data_directory); | 119 info, profile_data_directory); |
| 120 DCHECK(plugin_host); |
120 if (plugin_host->Init(info)) | 121 if (plugin_host->Init(info)) |
121 return plugin_host; | 122 return plugin_host; |
122 | 123 |
123 NOTREACHED(); // Init is not expected to fail. | 124 NOTREACHED(); // Init is not expected to fail. |
124 return NULL; | 125 return NULL; |
125 } | 126 } |
126 | 127 |
127 // static | 128 // static |
128 PpapiPluginProcessHost* PpapiPluginProcessHost::CreateBrokerHost( | 129 PpapiPluginProcessHost* PpapiPluginProcessHost::CreateBrokerHost( |
129 const PepperPluginInfo& info) { | 130 const PepperPluginInfo& info) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 247 |
247 bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) { | 248 bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) { |
248 plugin_path_ = info.path; | 249 plugin_path_ = info.path; |
249 if (info.name.empty()) { | 250 if (info.name.empty()) { |
250 process_->SetName(plugin_path_.BaseName().LossyDisplayName()); | 251 process_->SetName(plugin_path_.BaseName().LossyDisplayName()); |
251 } else { | 252 } else { |
252 process_->SetName(UTF8ToUTF16(info.name)); | 253 process_->SetName(UTF8ToUTF16(info.name)); |
253 } | 254 } |
254 | 255 |
255 std::string channel_id = process_->GetHost()->CreateChannel(); | 256 std::string channel_id = process_->GetHost()->CreateChannel(); |
256 if (channel_id.empty()) | 257 if (channel_id.empty()) { |
| 258 VLOG(1) << "Could not create pepper host channel."; |
257 return false; | 259 return false; |
| 260 } |
258 | 261 |
259 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 262 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
260 CommandLine::StringType plugin_launcher = | 263 CommandLine::StringType plugin_launcher = |
261 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); | 264 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); |
262 | 265 |
263 #if defined(OS_LINUX) | 266 #if defined(OS_LINUX) |
264 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : | 267 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : |
265 ChildProcessHost::CHILD_NORMAL; | 268 ChildProcessHost::CHILD_NORMAL; |
266 #else | 269 #else |
267 int flags = ChildProcessHost::CHILD_NORMAL; | 270 int flags = ChildProcessHost::CHILD_NORMAL; |
268 #endif | 271 #endif |
269 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); | 272 base::FilePath exe_path = ChildProcessHost::GetChildPath(flags); |
270 if (exe_path.empty()) | 273 if (exe_path.empty()) { |
| 274 VLOG(1) << "Pepper plugin exe path is empty."; |
271 return false; | 275 return false; |
| 276 } |
272 | 277 |
273 CommandLine* cmd_line = new CommandLine(exe_path); | 278 CommandLine* cmd_line = new CommandLine(exe_path); |
274 cmd_line->AppendSwitchASCII(switches::kProcessType, | 279 cmd_line->AppendSwitchASCII(switches::kProcessType, |
275 is_broker_ ? switches::kPpapiBrokerProcess | 280 is_broker_ ? switches::kPpapiBrokerProcess |
276 : switches::kPpapiPluginProcess); | 281 : switches::kPpapiPluginProcess); |
277 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 282 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
278 | 283 |
279 // These switches are forwarded to both plugin and broker pocesses. | 284 // These switches are forwarded to both plugin and broker pocesses. |
280 static const char* kCommonForwardSwitches[] = { | 285 static const char* kCommonForwardSwitches[] = { |
281 switches::kVModule | 286 switches::kVModule |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 process_id, renderer_child_id, client->OffTheRecord()); | 355 process_id, renderer_child_id, client->OffTheRecord()); |
351 msg->set_unblock(true); | 356 msg->set_unblock(true); |
352 if (Send(msg)) { | 357 if (Send(msg)) { |
353 sent_requests_.push(client); | 358 sent_requests_.push(client); |
354 } else { | 359 } else { |
355 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); | 360 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
356 } | 361 } |
357 } | 362 } |
358 | 363 |
359 void PpapiPluginProcessHost::OnProcessLaunched() { | 364 void PpapiPluginProcessHost::OnProcessLaunched() { |
| 365 VLOG(2) << "ppapi plugin process launched."; |
360 host_impl_->set_plugin_process_handle(process_->GetHandle()); | 366 host_impl_->set_plugin_process_handle(process_->GetHandle()); |
361 } | 367 } |
362 | 368 |
363 void PpapiPluginProcessHost::OnProcessCrashed(int exit_code) { | 369 void PpapiPluginProcessHost::OnProcessCrashed(int exit_code) { |
| 370 VLOG(1) << "ppapi plugin process crashed."; |
364 PluginServiceImpl::GetInstance()->RegisterPluginCrash(plugin_path_); | 371 PluginServiceImpl::GetInstance()->RegisterPluginCrash(plugin_path_); |
365 } | 372 } |
366 | 373 |
367 bool PpapiPluginProcessHost::OnMessageReceived(const IPC::Message& msg) { | 374 bool PpapiPluginProcessHost::OnMessageReceived(const IPC::Message& msg) { |
368 bool handled = true; | 375 bool handled = true; |
369 IPC_BEGIN_MESSAGE_MAP(PpapiPluginProcessHost, msg) | 376 IPC_BEGIN_MESSAGE_MAP(PpapiPluginProcessHost, msg) |
370 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, | 377 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, |
371 OnRendererPluginChannelCreated) | 378 OnRendererPluginChannelCreated) |
372 IPC_MESSAGE_UNHANDLED(handled = false) | 379 IPC_MESSAGE_UNHANDLED(handled = false) |
373 IPC_END_MESSAGE_MAP() | 380 IPC_END_MESSAGE_MAP() |
(...skipping 10 matching lines...) Expand all Loading... |
384 | 391 |
385 // Process all pending channel requests from the renderers. | 392 // Process all pending channel requests from the renderers. |
386 for (size_t i = 0; i < pending_requests_.size(); i++) | 393 for (size_t i = 0; i < pending_requests_.size(); i++) |
387 RequestPluginChannel(pending_requests_[i]); | 394 RequestPluginChannel(pending_requests_[i]); |
388 pending_requests_.clear(); | 395 pending_requests_.clear(); |
389 } | 396 } |
390 | 397 |
391 // Called when the browser <--> plugin channel has an error. This normally | 398 // Called when the browser <--> plugin channel has an error. This normally |
392 // means the plugin has crashed. | 399 // means the plugin has crashed. |
393 void PpapiPluginProcessHost::OnChannelError() { | 400 void PpapiPluginProcessHost::OnChannelError() { |
394 DVLOG(1) << "PpapiPluginProcessHost" << (is_broker_ ? "[broker]" : "") | 401 VLOG(1) << "PpapiPluginProcessHost" << (is_broker_ ? "[broker]" : "") |
395 << "::OnChannelError()"; | 402 << "::OnChannelError()"; |
396 // We don't need to notify the renderers that were communicating with the | 403 // We don't need to notify the renderers that were communicating with the |
397 // plugin since they have their own channels which will go into the error | 404 // plugin since they have their own channels which will go into the error |
398 // state at the same time. Instead, we just need to notify any renderers | 405 // state at the same time. Instead, we just need to notify any renderers |
399 // that have requested a connection but have not yet received one. | 406 // that have requested a connection but have not yet received one. |
400 CancelRequests(); | 407 CancelRequests(); |
401 } | 408 } |
402 | 409 |
403 void PpapiPluginProcessHost::CancelRequests() { | 410 void PpapiPluginProcessHost::CancelRequests() { |
404 DVLOG(1) << "PpapiPluginProcessHost" << (is_broker_ ? "[broker]" : "") | 411 DVLOG(1) << "PpapiPluginProcessHost" << (is_broker_ ? "[broker]" : "") |
405 << "CancelRequests()"; | 412 << "CancelRequests()"; |
(...skipping 20 matching lines...) Expand all Loading... |
426 // sent_requests_ queue should be the one that the plugin just created. | 433 // sent_requests_ queue should be the one that the plugin just created. |
427 Client* client = sent_requests_.front(); | 434 Client* client = sent_requests_.front(); |
428 sent_requests_.pop(); | 435 sent_requests_.pop(); |
429 | 436 |
430 const ChildProcessData& data = process_->GetData(); | 437 const ChildProcessData& data = process_->GetData(); |
431 client->OnPpapiChannelOpened(channel_handle, base::GetProcId(data.handle), | 438 client->OnPpapiChannelOpened(channel_handle, base::GetProcId(data.handle), |
432 data.id); | 439 data.id); |
433 } | 440 } |
434 | 441 |
435 } // namespace content | 442 } // namespace content |
OLD | NEW |