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

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

Issue 5598010: Convert over to channel handles (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed up bad whitespace Created 10 years 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 | Annotate | Revision Log
OLDNEW
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/lock.h" 8 #include "base/lock.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 155 }
156 156
157 // static 157 // static
158 void PluginChannel::NotifyRenderersOfPendingShutdown() { 158 void PluginChannel::NotifyRenderersOfPendingShutdown() {
159 Broadcast(new PluginHostMsg_PluginShuttingDown()); 159 Broadcast(new PluginHostMsg_PluginShuttingDown());
160 } 160 }
161 161
162 PluginChannel::PluginChannel() 162 PluginChannel::PluginChannel()
163 : renderer_handle_(0), 163 : renderer_handle_(0),
164 renderer_id_(-1), 164 renderer_id_(-1),
165 #if defined(OS_POSIX)
166 renderer_fd_(-1),
167 #endif
168 in_send_(0), 165 in_send_(0),
169 off_the_record_(false), 166 off_the_record_(false),
170 filter_(new MessageFilter()) { 167 filter_(new MessageFilter()) {
171 set_send_unblocking_only_during_unblock_dispatch(); 168 set_send_unblocking_only_during_unblock_dispatch();
172 ChildProcess::current()->AddRefProcess(); 169 ChildProcess::current()->AddRefProcess();
173 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 170 const CommandLine* command_line = CommandLine::ForCurrentProcess();
174 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); 171 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages);
175 } 172 }
176 173
177 PluginChannel::~PluginChannel() { 174 PluginChannel::~PluginChannel() {
178 #if defined(OS_POSIX)
179 // Won't be needing this any more.
180 CloseRendererFD();
181 #endif
182
183 if (renderer_handle_) 175 if (renderer_handle_)
184 base::CloseProcessHandle(renderer_handle_); 176 base::CloseProcessHandle(renderer_handle_);
185 177
186 MessageLoop::current()->PostDelayedTask(FROM_HERE, new PluginReleaseTask(), 178 MessageLoop::current()->PostDelayedTask(FROM_HERE, new PluginReleaseTask(),
187 kPluginReleaseTimeMS); 179 kPluginReleaseTimeMS);
188 } 180 }
189 181
190 bool PluginChannel::Send(IPC::Message* msg) { 182 bool PluginChannel::Send(IPC::Message* msg) {
191 in_send_++; 183 in_send_++;
192 if (log_messages_) { 184 if (log_messages_) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 278 }
287 Send(new PluginHostMsg_ClearSiteDataResult(success)); 279 Send(new PluginHostMsg_ClearSiteDataResult(success));
288 } 280 }
289 281
290 base::WaitableEvent* PluginChannel::GetModalDialogEvent( 282 base::WaitableEvent* PluginChannel::GetModalDialogEvent(
291 gfx::NativeViewId containing_window) { 283 gfx::NativeViewId containing_window) {
292 return filter_->GetModalDialogEvent(containing_window); 284 return filter_->GetModalDialogEvent(containing_window);
293 } 285 }
294 286
295 void PluginChannel::OnChannelConnected(int32 peer_pid) { 287 void PluginChannel::OnChannelConnected(int32 peer_pid) {
296 #if defined(OS_POSIX)
297 // By this point, the renderer must have its own copy of the plugin channel
298 // FD.
299 CloseRendererFD();
300 #endif
301
302 base::ProcessHandle handle; 288 base::ProcessHandle handle;
303 if (!base::OpenProcessHandle(peer_pid, &handle)) { 289 if (!base::OpenProcessHandle(peer_pid, &handle)) {
304 NOTREACHED(); 290 NOTREACHED();
305 } 291 }
306 renderer_handle_ = handle; 292 renderer_handle_ = handle;
307 PluginChannelBase::OnChannelConnected(peer_pid); 293 PluginChannelBase::OnChannelConnected(peer_pid);
308 } 294 }
309 295
310 void PluginChannel::OnChannelError() { 296 void PluginChannel::OnChannelError() {
311 #if defined(OS_POSIX)
312 // Won't be needing this any more.
313 CloseRendererFD();
314 #endif
315
316 base::CloseProcessHandle(renderer_handle_); 297 base::CloseProcessHandle(renderer_handle_);
317 renderer_handle_ = 0; 298 renderer_handle_ = 0;
318 PluginChannelBase::OnChannelError(); 299 PluginChannelBase::OnChannelError();
319 CleanUp(); 300 CleanUp();
320 } 301 }
321 302
322 void PluginChannel::CleanUp() { 303 void PluginChannel::CleanUp() {
323 // We need to clean up the stubs so that they call NPPDestroy. This will 304 // We need to clean up the stubs so that they call NPPDestroy. This will
324 // also lead to them releasing their reference on this object so that it can 305 // also lead to them releasing their reference on this object so that it can
325 // be deleted. 306 // be deleted.
326 for (size_t i = 0; i < plugin_stubs_.size(); ++i) 307 for (size_t i = 0; i < plugin_stubs_.size(); ++i)
327 RemoveRoute(plugin_stubs_[i]->instance_id()); 308 RemoveRoute(plugin_stubs_[i]->instance_id());
328 309
329 // Need to addref this object temporarily because otherwise removing the last 310 // Need to addref this object temporarily because otherwise removing the last
330 // stub will cause the destructor of this object to be called, however at 311 // stub will cause the destructor of this object to be called, however at
331 // that point plugin_stubs_ will have one element and its destructor will be 312 // that point plugin_stubs_ will have one element and its destructor will be
332 // called twice. 313 // called twice.
333 scoped_refptr<PluginChannel> me(this); 314 scoped_refptr<PluginChannel> me(this);
334 315
335 plugin_stubs_.clear(); 316 plugin_stubs_.clear();
336 } 317 }
337 318
338 bool PluginChannel::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) { 319 bool PluginChannel::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) {
339 #if defined(OS_POSIX)
340 // This gets called when the PluginChannel is initially created. At this
341 // point, create the socketpair and assign the plugin side FD to the channel
342 // name. Keep the renderer side FD as a member variable in the PluginChannel
343 // to be able to transmit it through IPC.
344 int plugin_fd;
345 if (!IPC::SocketPair(&plugin_fd, &renderer_fd_))
346 return false;
347 IPC::AddChannelSocket(channel_name(), plugin_fd);
348 #endif
349
350 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now)) 320 if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now))
351 return false; 321 return false;
352 322
353 channel_->AddFilter(filter_.get()); 323 channel_->AddFilter(filter_.get());
354 return true; 324 return true;
355 } 325 }
356 326
357 #if defined(OS_POSIX)
358 void PluginChannel::CloseRendererFD() {
359 if (renderer_fd_ != -1) {
360 if (HANDLE_EINTR(close(renderer_fd_)) < 0)
361 PLOG(ERROR) << "close";
362 renderer_fd_ = -1;
363 }
364 }
365 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698