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 |
35 // How long we wait before releasing the plugin process. | 42 // How long we wait before releasing the plugin process. |
36 const int kPluginReleaseTimeMs = 5 * 60 * 1000; // 5 minutes | 43 const int kPluginReleaseTimeMs = 5 * 60 * 1000; // 5 minutes |
37 | 44 |
| 45 // How long we wait before forcibly shutting down the process. |
| 46 const int kPluginProcessTerminateTimeoutMs = 3000; |
| 47 |
38 } // namespace | 48 } // namespace |
39 | 49 |
40 // If a sync call to the renderer results in a modal dialog, we need to have a | 50 // If a sync call to the renderer results in a modal dialog, we need to have a |
41 // way to know so that we can run a nested message loop to simulate what would | 51 // way to know so that we can run a nested message loop to simulate what would |
42 // happen in a single process browser and avoid deadlock. | 52 // happen in a single process browser and avoid deadlock. |
43 class PluginChannel::MessageFilter : public IPC::ChannelProxy::MessageFilter { | 53 class PluginChannel::MessageFilter : public IPC::ChannelProxy::MessageFilter { |
44 public: | 54 public: |
45 MessageFilter() : channel_(NULL) { } | 55 MessageFilter() : channel_(NULL) { } |
46 ~MessageFilter() { | 56 ~MessageFilter() { |
47 // Clean up in case of renderer crash. | 57 // Clean up in case of renderer crash. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 91 } |
82 | 92 |
83 bool Send(IPC::Message* message) { | 93 bool Send(IPC::Message* message) { |
84 // Need this function for the IPC_MESSAGE_HANDLER_DELAY_REPLY macro. | 94 // Need this function for the IPC_MESSAGE_HANDLER_DELAY_REPLY macro. |
85 return channel_->Send(message); | 95 return channel_->Send(message); |
86 } | 96 } |
87 | 97 |
88 private: | 98 private: |
89 void OnFilterAdded(IPC::Channel* channel) { channel_ = channel; } | 99 void OnFilterAdded(IPC::Channel* channel) { channel_ = channel; } |
90 | 100 |
| 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 |
91 bool OnMessageReceived(const IPC::Message& message) { | 110 bool OnMessageReceived(const IPC::Message& message) { |
92 IPC_BEGIN_MESSAGE_MAP(PluginChannel::MessageFilter, message) | 111 IPC_BEGIN_MESSAGE_MAP(PluginChannel::MessageFilter, message) |
93 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_Init, OnInit) | 112 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_Init, OnInit) |
94 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, | 113 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, |
95 OnSignalModalDialogEvent) | 114 OnSignalModalDialogEvent) |
96 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, | 115 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, |
97 OnResetModalDialogEvent) | 116 OnResetModalDialogEvent) |
98 IPC_END_MESSAGE_MAP() | 117 IPC_END_MESSAGE_MAP() |
99 return message.type() == PluginMsg_SignalModalDialogEvent::ID || | 118 return message.type() == PluginMsg_SignalModalDialogEvent::ID || |
100 message.type() == PluginMsg_ResetModalDialogEvent::ID; | 119 message.type() == PluginMsg_ResetModalDialogEvent::ID; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 344 |
326 bool PluginChannel::Init(base::MessageLoopProxy* ipc_message_loop, | 345 bool PluginChannel::Init(base::MessageLoopProxy* ipc_message_loop, |
327 bool create_pipe_now) { | 346 bool create_pipe_now) { |
328 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) | 347 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) |
329 return false; | 348 return false; |
330 | 349 |
331 channel_->AddFilter(filter_.get()); | 350 channel_->AddFilter(filter_.get()); |
332 return true; | 351 return true; |
333 } | 352 } |
334 | 353 |
OLD | NEW |