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

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

Issue 42054: Stop using renderer specific host ids in ResourceDispatcher. This allows it ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/plugin/plugin_channel.h ('k') | chrome/plugin/plugin_thread.h » ('j') | 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 <windows.h> 5 #include <windows.h>
6 6
7 #include "chrome/plugin/plugin_channel.h" 7 #include "chrome/plugin/plugin_channel.h"
8 8
9 #include "chrome/common/plugin_messages.h" 9 #include "chrome/common/plugin_messages.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/process_util.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "chrome/plugin/plugin_process.h" 14 #include "chrome/plugin/plugin_process.h"
14 #include "chrome/plugin/plugin_thread.h" 15 #include "chrome/plugin/plugin_thread.h"
15 16
16 PluginChannel* PluginChannel::GetPluginChannel( 17 PluginChannel* PluginChannel::GetPluginChannel(MessageLoop* ipc_message_loop) {
17 int process_id, HANDLE renderer_handle, MessageLoop* ipc_message_loop) { 18 static int next_id;
18 // map renderer's process id to a (single) channel to that process
19 std::wstring channel_name = StringPrintf( 19 std::wstring channel_name = StringPrintf(
20 L"%d.r%d", GetCurrentProcessId(), process_id); 20 L"%d.r%d", GetCurrentProcessId(), ++next_id);
21 21
22 PluginChannelBase* result = PluginChannelBase::GetChannel( 22 return static_cast<PluginChannel*>(PluginChannelBase::GetChannel(
23 channel_name, 23 channel_name,
24 IPC::Channel::MODE_SERVER, 24 IPC::Channel::MODE_SERVER,
25 ClassFactory, 25 ClassFactory,
26 ipc_message_loop, 26 ipc_message_loop,
27 false); 27 false));
28
29 PluginChannel* channel = static_cast<PluginChannel*>(result);
30 if (channel && !channel->renderer_handle())
31 channel->renderer_handle_.Set(renderer_handle);
32
33 return channel;
34 } 28 }
35 29
36 PluginChannel::PluginChannel() : in_send_(0) { 30 PluginChannel::PluginChannel() : in_send_(0) {
37 SendUnblockingOnlyDuringDispatch(); 31 SendUnblockingOnlyDuringDispatch();
38 PluginProcess::current()->AddRefProcess(); 32 PluginProcess::current()->AddRefProcess();
39 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 33 const CommandLine* command_line = CommandLine::ForCurrentProcess();
40 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); 34 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages);
41 } 35 }
42 36
43 PluginChannel::~PluginChannel() { 37 PluginChannel::~PluginChannel() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 92
99 void PluginChannel::OnGenerateRouteID(int* route_id) { 93 void PluginChannel::OnGenerateRouteID(int* route_id) {
100 *route_id = GenerateRouteID(); 94 *route_id = GenerateRouteID();
101 } 95 }
102 96
103 int PluginChannel::GenerateRouteID() { 97 int PluginChannel::GenerateRouteID() {
104 static LONG last_id = 0; 98 static LONG last_id = 0;
105 return InterlockedIncrement(&last_id); 99 return InterlockedIncrement(&last_id);
106 } 100 }
107 101
102 void PluginChannel::OnChannelConnected(int32 peer_pid) {
103 renderer_handle_.Set(base::OpenProcessHandle(peer_pid));
104 PluginChannelBase::OnChannelConnected(peer_pid);
105 }
106
108 void PluginChannel::OnChannelError() { 107 void PluginChannel::OnChannelError() {
109 renderer_handle_.Set(NULL); 108 renderer_handle_.Set(NULL);
110 PluginChannelBase::OnChannelError(); 109 PluginChannelBase::OnChannelError();
111 CleanUp(); 110 CleanUp();
112 } 111 }
113 112
114 void PluginChannel::CleanUp() { 113 void PluginChannel::CleanUp() {
115 // We need to clean up the stubs so that they call NPPDestroy. This will 114 // We need to clean up the stubs so that they call NPPDestroy. This will
116 // also lead to them releasing their reference on this object so that it can 115 // also lead to them releasing their reference on this object so that it can
117 // be deleted. 116 // be deleted.
118 for (size_t i = 0; i < plugin_stubs_.size(); ++i) 117 for (size_t i = 0; i < plugin_stubs_.size(); ++i)
119 RemoveRoute(plugin_stubs_[i]->instance_id()); 118 RemoveRoute(plugin_stubs_[i]->instance_id());
120 119
121 // Need to addref this object temporarily because otherwise removing the last 120 // Need to addref this object temporarily because otherwise removing the last
122 // stub will cause the destructor of this object to be called, however at 121 // stub will cause the destructor of this object to be called, however at
123 // that point plugin_stubs_ will have one element and its destructor will be 122 // that point plugin_stubs_ will have one element and its destructor will be
124 // called twice. 123 // called twice.
125 scoped_refptr<PluginChannel> me(this); 124 scoped_refptr<PluginChannel> me(this);
126 125
127 plugin_stubs_.clear(); 126 plugin_stubs_.clear();
128 } 127 }
OLDNEW
« no previous file with comments | « chrome/plugin/plugin_channel.h ('k') | chrome/plugin/plugin_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698