Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: chrome/plugin/plugin_channel.cc

Issue 164157: Delay releasing plugin process for 10s. (Closed)
Patch Set: prefer constant over magic number Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/common/child_process.h" 11 #include "chrome/common/child_process.h"
12 #include "chrome/common/plugin_messages.h" 12 #include "chrome/common/plugin_messages.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/plugin/plugin_thread.h" 14 #include "chrome/plugin/plugin_thread.h"
15 15
16 #if defined(OS_POSIX) 16 #if defined(OS_POSIX)
17 #include "ipc/ipc_channel_posix.h" 17 #include "ipc/ipc_channel_posix.h"
18 #endif 18 #endif
19 19
20 class PluginReleaseTask : public Task {
21 public:
22 void Run() {
23 ChildProcess::current()->ReleaseProcess();
24 }
25 };
26
27 // How long we wait before releasing the plugin process.
28 static const int kPluginReleaseTimeMS = 10000;
jam 2009/08/07 23:33:26 nit: the convention is to use "Ms"
29
20 PluginChannel* PluginChannel::GetPluginChannel( 30 PluginChannel* PluginChannel::GetPluginChannel(
21 int process_id, MessageLoop* ipc_message_loop) { 31 int process_id, MessageLoop* ipc_message_loop) {
22 // map renderer's process id to a (single) channel to that process 32 // map renderer's process id to a (single) channel to that process
23 std::string channel_name = StringPrintf( 33 std::string channel_name = StringPrintf(
24 "%d.r%d", base::GetCurrentProcId(), process_id); 34 "%d.r%d", base::GetCurrentProcId(), process_id);
25 35
26 return static_cast<PluginChannel*>(PluginChannelBase::GetChannel( 36 return static_cast<PluginChannel*>(PluginChannelBase::GetChannel(
27 channel_name, 37 channel_name,
28 IPC::Channel::MODE_SERVER, 38 IPC::Channel::MODE_SERVER,
29 ClassFactory, 39 ClassFactory,
(...skipping 17 matching lines...) Expand all
47 PluginChannel::~PluginChannel() { 57 PluginChannel::~PluginChannel() {
48 if (renderer_handle_) 58 if (renderer_handle_)
49 base::CloseProcessHandle(renderer_handle_); 59 base::CloseProcessHandle(renderer_handle_);
50 #if defined(OS_POSIX) 60 #if defined(OS_POSIX)
51 IPC::RemoveAndCloseChannelSocket(channel_name()); 61 IPC::RemoveAndCloseChannelSocket(channel_name());
52 // If we still have the renderer FD, close it. 62 // If we still have the renderer FD, close it.
53 if (renderer_fd_ != -1) { 63 if (renderer_fd_ != -1) {
54 close(renderer_fd_); 64 close(renderer_fd_);
55 } 65 }
56 #endif 66 #endif
57 ChildProcess::current()->ReleaseProcess(); 67 MessageLoop::current()->PostDelayedTask(FROM_HERE, new PluginReleaseTask(),
68 kPluginReleaseTimeMS);
58 } 69 }
59 70
60 bool PluginChannel::Send(IPC::Message* msg) { 71 bool PluginChannel::Send(IPC::Message* msg) {
61 in_send_++; 72 in_send_++;
62 if (log_messages_) { 73 if (log_messages_) {
63 LOG(INFO) << "sending message @" << msg << " on channel @" << this 74 LOG(INFO) << "sending message @" << msg << " on channel @" << this
64 << " with type " << msg->type(); 75 << " with type " << msg->type();
65 } 76 }
66 bool result = PluginChannelBase::Send(msg); 77 bool result = PluginChannelBase::Send(msg);
67 in_send_--; 78 in_send_--;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // This gets called when the PluginChannel is initially created. At this 166 // This gets called when the PluginChannel is initially created. At this
156 // point, create the socketpair and assign the plugin side FD to the channel 167 // point, create the socketpair and assign the plugin side FD to the channel
157 // name. Keep the renderer side FD as a member variable in the PluginChannel 168 // name. Keep the renderer side FD as a member variable in the PluginChannel
158 // to be able to transmit it through IPC. 169 // to be able to transmit it through IPC.
159 int plugin_fd; 170 int plugin_fd;
160 IPC::SocketPair(&plugin_fd, &renderer_fd_); 171 IPC::SocketPair(&plugin_fd, &renderer_fd_);
161 IPC::AddChannelSocket(channel_name(), plugin_fd); 172 IPC::AddChannelSocket(channel_name(), plugin_fd);
162 #endif 173 #endif
163 return PluginChannelBase::Init(ipc_message_loop, create_pipe_now); 174 return PluginChannelBase::Init(ipc_message_loop, create_pipe_now);
164 } 175 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698