| OLD | NEW |
| 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/plugin/plugin_channel.h" | 5 #include "content/plugin/plugin_channel.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class PluginReleaseTask : public Task { | 28 class PluginReleaseTask : public Task { |
| 29 public: | 29 public: |
| 30 void Run() { | 30 void Run() { |
| 31 ChildProcess::current()->ReleaseProcess(); | 31 ChildProcess::current()->ReleaseProcess(); |
| 32 } | 32 } |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class PluginProcessExitTask : public Task { | |
| 36 public: | |
| 37 void Run() { | |
| 38 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); | |
| 39 } | |
| 40 }; | |
| 41 | |
| 42 // How long we wait before releasing the plugin process. | 35 // How long we wait before releasing the plugin process. |
| 43 const int kPluginReleaseTimeMs = 5 * 60 * 1000; // 5 minutes | 36 const int kPluginReleaseTimeMs = 5 * 60 * 1000; // 5 minutes |
| 44 | 37 |
| 45 // How long we wait before forcibly shutting down the process. | |
| 46 const int kPluginProcessTerminateTimeoutMs = 3000; | |
| 47 | |
| 48 } // namespace | 38 } // namespace |
| 49 | 39 |
| 50 // If a sync call to the renderer results in a modal dialog, we need to have a | 40 // If a sync call to the renderer results in a modal dialog, we need to have a |
| 51 // way to know so that we can run a nested message loop to simulate what would | 41 // way to know so that we can run a nested message loop to simulate what would |
| 52 // happen in a single process browser and avoid deadlock. | 42 // happen in a single process browser and avoid deadlock. |
| 53 class PluginChannel::MessageFilter : public IPC::ChannelProxy::MessageFilter { | 43 class PluginChannel::MessageFilter : public IPC::ChannelProxy::MessageFilter { |
| 54 public: | 44 public: |
| 55 MessageFilter() : channel_(NULL) { } | 45 MessageFilter() : channel_(NULL) { } |
| 56 ~MessageFilter() { | 46 ~MessageFilter() { |
| 57 // Clean up in case of renderer crash. | 47 // Clean up in case of renderer crash. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 81 } |
| 92 | 82 |
| 93 bool Send(IPC::Message* message) { | 83 bool Send(IPC::Message* message) { |
| 94 // Need this function for the IPC_MESSAGE_HANDLER_DELAY_REPLY macro. | 84 // Need this function for the IPC_MESSAGE_HANDLER_DELAY_REPLY macro. |
| 95 return channel_->Send(message); | 85 return channel_->Send(message); |
| 96 } | 86 } |
| 97 | 87 |
| 98 private: | 88 private: |
| 99 void OnFilterAdded(IPC::Channel* channel) { channel_ = channel; } | 89 void OnFilterAdded(IPC::Channel* channel) { channel_ = channel; } |
| 100 | 90 |
| 101 virtual void OnChannelError() { | |
| 102 // Ensure that we don't wait indefinitely for the plugin to shutdown. | |
| 103 // as the browser does not terminate plugin processes on shutdown. | |
| 104 // We achieve this by posting an exit process task on the IO thread. | |
| 105 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
| 106 new PluginProcessExitTask(), | |
| 107 kPluginProcessTerminateTimeoutMs); | |
| 108 } | |
| 109 | |
| 110 bool OnMessageReceived(const IPC::Message& message) { | 91 bool OnMessageReceived(const IPC::Message& message) { |
| 111 IPC_BEGIN_MESSAGE_MAP(PluginChannel::MessageFilter, message) | 92 IPC_BEGIN_MESSAGE_MAP(PluginChannel::MessageFilter, message) |
| 112 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_Init, OnInit) | 93 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_Init, OnInit) |
| 113 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, | 94 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, |
| 114 OnSignalModalDialogEvent) | 95 OnSignalModalDialogEvent) |
| 115 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, | 96 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, |
| 116 OnResetModalDialogEvent) | 97 OnResetModalDialogEvent) |
| 117 IPC_END_MESSAGE_MAP() | 98 IPC_END_MESSAGE_MAP() |
| 118 return message.type() == PluginMsg_SignalModalDialogEvent::ID || | 99 return message.type() == PluginMsg_SignalModalDialogEvent::ID || |
| 119 message.type() == PluginMsg_ResetModalDialogEvent::ID; | 100 message.type() == PluginMsg_ResetModalDialogEvent::ID; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 325 |
| 345 bool PluginChannel::Init(base::MessageLoopProxy* ipc_message_loop, | 326 bool PluginChannel::Init(base::MessageLoopProxy* ipc_message_loop, |
| 346 bool create_pipe_now) { | 327 bool create_pipe_now) { |
| 347 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) | 328 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) |
| 348 return false; | 329 return false; |
| 349 | 330 |
| 350 channel_->AddFilter(filter_.get()); | 331 channel_->AddFilter(filter_.get()); |
| 351 return true; | 332 return true; |
| 352 } | 333 } |
| 353 | 334 |
| OLD | NEW |