OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/plugin/plugin_channel.h" | 5 #include "chrome/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" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/common/child_process.h" | 13 #include "chrome/common/child_process.h" |
14 #include "chrome/common/plugin_messages.h" | 14 #include "chrome/common/plugin_messages.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/plugin/plugin_thread.h" | 16 #include "chrome/plugin/plugin_thread.h" |
17 #include "chrome/plugin/webplugin_delegate_stub.h" | 17 #include "chrome/plugin/webplugin_delegate_stub.h" |
18 #include "chrome/plugin/webplugin_proxy.h" | 18 #include "chrome/plugin/webplugin_proxy.h" |
19 #include "webkit/plugins/npapi/plugin_instance.h" | 19 #include "webkit/plugins/npapi/plugin_instance.h" |
20 | 20 |
21 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
22 #include "base/eintr_wrapper.h" | 22 #include "base/eintr_wrapper.h" |
23 #include "ipc/ipc_channel_posix.h" | 23 #include "ipc/ipc_channel_posix.h" |
24 #endif | 24 #endif |
25 | 25 |
| 26 namespace { |
| 27 |
26 class PluginReleaseTask : public Task { | 28 class PluginReleaseTask : public Task { |
27 public: | 29 public: |
28 void Run() { | 30 void Run() { |
29 ChildProcess::current()->ReleaseProcess(); | 31 ChildProcess::current()->ReleaseProcess(); |
30 } | 32 } |
31 }; | 33 }; |
32 | 34 |
33 // How long we wait before releasing the plugin process. | 35 // How long we wait before releasing the plugin process. |
34 static const int kPluginReleaseTimeMS = 5 * 60 * 1000; // 5 minutes | 36 const int kPluginReleaseTimeMs = 5 * 60 * 1000; // 5 minutes |
35 | 37 |
| 38 } // namespace |
36 | 39 |
37 // 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 |
38 // 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 |
39 // happen in a single process browser and avoid deadlock. | 42 // happen in a single process browser and avoid deadlock. |
40 class PluginChannel::MessageFilter : public IPC::ChannelProxy::MessageFilter { | 43 class PluginChannel::MessageFilter : public IPC::ChannelProxy::MessageFilter { |
41 public: | 44 public: |
42 MessageFilter() : channel_(NULL) { } | 45 MessageFilter() : channel_(NULL) { } |
43 ~MessageFilter() { | 46 ~MessageFilter() { |
44 // Clean up in case of renderer crash. | 47 // Clean up in case of renderer crash. |
45 for (ModalDialogEventMap::iterator i = modal_dialog_event_map_.begin(); | 48 for (ModalDialogEventMap::iterator i = modal_dialog_event_map_.begin(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 base::WaitableEvent* event; | 129 base::WaitableEvent* event; |
127 int refcount; // There could be multiple plugin instances per tab. | 130 int refcount; // There could be multiple plugin instances per tab. |
128 }; | 131 }; |
129 typedef std::map<gfx::NativeViewId, WaitableEventWrapper> ModalDialogEventMap; | 132 typedef std::map<gfx::NativeViewId, WaitableEventWrapper> ModalDialogEventMap; |
130 ModalDialogEventMap modal_dialog_event_map_; | 133 ModalDialogEventMap modal_dialog_event_map_; |
131 base::Lock modal_dialog_event_map_lock_; | 134 base::Lock modal_dialog_event_map_lock_; |
132 | 135 |
133 IPC::Channel* channel_; | 136 IPC::Channel* channel_; |
134 }; | 137 }; |
135 | 138 |
136 | |
137 PluginChannel* PluginChannel::GetPluginChannel(int renderer_id, | 139 PluginChannel* PluginChannel::GetPluginChannel(int renderer_id, |
138 MessageLoop* ipc_message_loop) { | 140 MessageLoop* ipc_message_loop) { |
139 // Map renderer ID to a (single) channel to that process. | 141 // Map renderer ID to a (single) channel to that process. |
140 std::string channel_key = StringPrintf( | 142 std::string channel_key = StringPrintf( |
141 "%d.r%d", base::GetCurrentProcId(), renderer_id); | 143 "%d.r%d", base::GetCurrentProcId(), renderer_id); |
142 | 144 |
143 PluginChannel* channel = | 145 PluginChannel* channel = |
144 static_cast<PluginChannel*>(PluginChannelBase::GetChannel( | 146 static_cast<PluginChannel*>(PluginChannelBase::GetChannel( |
145 channel_key, | 147 channel_key, |
146 IPC::Channel::MODE_SERVER, | 148 IPC::Channel::MODE_SERVER, |
(...skipping 22 matching lines...) Expand all Loading... |
169 ChildProcess::current()->AddRefProcess(); | 171 ChildProcess::current()->AddRefProcess(); |
170 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 172 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
171 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); | 173 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); |
172 } | 174 } |
173 | 175 |
174 PluginChannel::~PluginChannel() { | 176 PluginChannel::~PluginChannel() { |
175 if (renderer_handle_) | 177 if (renderer_handle_) |
176 base::CloseProcessHandle(renderer_handle_); | 178 base::CloseProcessHandle(renderer_handle_); |
177 | 179 |
178 MessageLoop::current()->PostDelayedTask(FROM_HERE, new PluginReleaseTask(), | 180 MessageLoop::current()->PostDelayedTask(FROM_HERE, new PluginReleaseTask(), |
179 kPluginReleaseTimeMS); | 181 kPluginReleaseTimeMs); |
180 } | 182 } |
181 | 183 |
182 bool PluginChannel::Send(IPC::Message* msg) { | 184 bool PluginChannel::Send(IPC::Message* msg) { |
183 in_send_++; | 185 in_send_++; |
184 if (log_messages_) { | 186 if (log_messages_) { |
185 VLOG(1) << "sending message @" << msg << " on channel @" << this | 187 VLOG(1) << "sending message @" << msg << " on channel @" << this |
186 << " with type " << msg->type(); | 188 << " with type " << msg->type(); |
187 } | 189 } |
188 bool result = PluginChannelBase::Send(msg); | 190 bool result = PluginChannelBase::Send(msg); |
189 in_send_--; | 191 in_send_--; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 319 } |
318 | 320 |
319 bool PluginChannel::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) { | 321 bool PluginChannel::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) { |
320 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) | 322 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) |
321 return false; | 323 return false; |
322 | 324 |
323 channel_->AddFilter(filter_.get()); | 325 channel_->AddFilter(filter_.get()); |
324 return true; | 326 return true; |
325 } | 327 } |
326 | 328 |
OLD | NEW |