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 29 matching lines...) Expand all Loading... | |
77 // Delete the event when the stack unwinds as it could be in use now. | 87 // Delete the event when the stack unwinds as it could be in use now. |
78 MessageLoop::current()->DeleteSoon( | 88 MessageLoop::current()->DeleteSoon( |
79 FROM_HERE, modal_dialog_event_map_[containing_window].event); | 89 FROM_HERE, modal_dialog_event_map_[containing_window].event); |
80 modal_dialog_event_map_.erase(containing_window); | 90 modal_dialog_event_map_.erase(containing_window); |
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 |
jam
2011/05/24 20:46:13
nit: extra line
ananta
2011/05/24 20:56:26
Done.
| |
98 | |
88 private: | 99 private: |
89 void OnFilterAdded(IPC::Channel* channel) { channel_ = channel; } | 100 void OnFilterAdded(IPC::Channel* channel) { channel_ = channel; } |
90 | 101 |
102 virtual void OnChannelError() { | |
103 // Ensure that we don't wait indefinitely for the plugin to shutdown. | |
jam
2011/05/24 20:46:13
nit: can you please add just one extra line to say
ananta
2011/05/24 20:56:26
Done.
| |
104 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
105 new PluginProcessExitTask(), | |
106 kPluginProcessTerminateTimeoutMs); | |
107 } | |
108 | |
91 bool OnMessageReceived(const IPC::Message& message) { | 109 bool OnMessageReceived(const IPC::Message& message) { |
92 IPC_BEGIN_MESSAGE_MAP(PluginChannel::MessageFilter, message) | 110 IPC_BEGIN_MESSAGE_MAP(PluginChannel::MessageFilter, message) |
93 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_Init, OnInit) | 111 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginMsg_Init, OnInit) |
94 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, | 112 IPC_MESSAGE_HANDLER(PluginMsg_SignalModalDialogEvent, |
95 OnSignalModalDialogEvent) | 113 OnSignalModalDialogEvent) |
96 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, | 114 IPC_MESSAGE_HANDLER(PluginMsg_ResetModalDialogEvent, |
97 OnResetModalDialogEvent) | 115 OnResetModalDialogEvent) |
98 IPC_END_MESSAGE_MAP() | 116 IPC_END_MESSAGE_MAP() |
99 return message.type() == PluginMsg_SignalModalDialogEvent::ID || | 117 return message.type() == PluginMsg_SignalModalDialogEvent::ID || |
100 message.type() == PluginMsg_ResetModalDialogEvent::ID; | 118 message.type() == PluginMsg_ResetModalDialogEvent::ID; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 | 343 |
326 bool PluginChannel::Init(base::MessageLoopProxy* ipc_message_loop, | 344 bool PluginChannel::Init(base::MessageLoopProxy* ipc_message_loop, |
327 bool create_pipe_now) { | 345 bool create_pipe_now) { |
328 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) | 346 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) |
329 return false; | 347 return false; |
330 | 348 |
331 channel_->AddFilter(filter_.get()); | 349 channel_->AddFilter(filter_.get()); |
332 return true; | 350 return true; |
333 } | 351 } |
334 | 352 |
OLD | NEW |