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

Side by Side Diff: content/browser/ppapi_plugin_process_host.cc

Issue 8774040: Don't make classes derive from ChildProcessHost, and instead have them use it through composition... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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) 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/browser/ppapi_plugin_process_host.h" 5 #include "content/browser/ppapi_plugin_process_host.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "content/browser/plugin_service.h" 12 #include "content/browser/plugin_service.h"
13 #include "content/browser/renderer_host/render_message_filter.h" 13 #include "content/browser/renderer_host/render_message_filter.h"
14 #include "content/common/child_process_host.h"
14 #include "content/common/child_process_messages.h" 15 #include "content/common/child_process_messages.h"
15 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
16 #include "content/public/common/pepper_plugin_info.h" 17 #include "content/public/common/pepper_plugin_info.h"
17 #include "content/public/common/process_type.h" 18 #include "content/public/common/process_type.h"
18 #include "ipc/ipc_switches.h" 19 #include "ipc/ipc_switches.h"
19 #include "net/base/network_change_notifier.h" 20 #include "net/base/network_change_notifier.h"
20 #include "ppapi/proxy/ppapi_messages.h" 21 #include "ppapi/proxy/ppapi_messages.h"
21 22
22 class PpapiPluginProcessHost::PluginNetworkObserver 23 class PpapiPluginProcessHost::PluginNetworkObserver
23 : public net::NetworkChangeNotifier::IPAddressObserver, 24 : public net::NetworkChangeNotifier::IPAddressObserver,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 PpapiPluginProcessHost* plugin_host = 78 PpapiPluginProcessHost* plugin_host =
78 new PpapiPluginProcessHost(); 79 new PpapiPluginProcessHost();
79 if(plugin_host->Init(info)) 80 if(plugin_host->Init(info))
80 return plugin_host; 81 return plugin_host;
81 82
82 NOTREACHED(); // Init is not expected to fail. 83 NOTREACHED(); // Init is not expected to fail.
83 return NULL; 84 return NULL;
84 } 85 }
85 86
86 void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) { 87 void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) {
87 if (opening_channel()) { 88 if (child_process_host()->opening_channel()) {
88 // The channel is already in the process of being opened. Put 89 // The channel is already in the process of being opened. Put
89 // this "open channel" request into a queue of requests that will 90 // this "open channel" request into a queue of requests that will
90 // be run once the channel is open. 91 // be run once the channel is open.
91 pending_requests_.push_back(client); 92 pending_requests_.push_back(client);
92 return; 93 return;
93 } 94 }
94 95
95 // We already have an open channel, send a request right away to plugin. 96 // We already have an open channel, send a request right away to plugin.
96 RequestPluginChannel(client); 97 RequestPluginChannel(client);
97 } 98 }
98 99
99 PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver) 100 PpapiPluginProcessHost::PpapiPluginProcessHost(net::HostResolver* host_resolver)
100 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_PLUGIN), 101 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_PLUGIN),
101 filter_(new PepperMessageFilter(host_resolver)), 102 filter_(new PepperMessageFilter(host_resolver)),
102 network_observer_(new PluginNetworkObserver(this)), 103 network_observer_(new PluginNetworkObserver(this)),
103 is_broker_(false), 104 is_broker_(false),
104 process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) { 105 process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) {
105 AddFilter(filter_.get()); 106 child_process_host()->AddFilter(filter_.get());
106 } 107 }
107 108
108 PpapiPluginProcessHost::PpapiPluginProcessHost() 109 PpapiPluginProcessHost::PpapiPluginProcessHost()
109 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_BROKER), 110 : BrowserChildProcessHost(content::PROCESS_TYPE_PPAPI_BROKER),
110 is_broker_(true), 111 is_broker_(true),
111 process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) { 112 process_id_(ChildProcessHost::GenerateChildProcessUniqueId()) {
112 } 113 }
113 114
114 bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) { 115 bool PpapiPluginProcessHost::Init(const content::PepperPluginInfo& info) {
115 plugin_path_ = info.path; 116 plugin_path_ = info.path;
116 if (info.name.empty()) { 117 if (info.name.empty()) {
117 set_name(plugin_path_.BaseName().LossyDisplayName()); 118 set_name(plugin_path_.BaseName().LossyDisplayName());
118 } else { 119 } else {
119 set_name(UTF8ToUTF16(info.name)); 120 set_name(UTF8ToUTF16(info.name));
120 } 121 }
121 122
122 if (!CreateChannel()) 123 if (!child_process_host()->CreateChannel())
123 return false; 124 return false;
124 125
125 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 126 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
126 CommandLine::StringType plugin_launcher = 127 CommandLine::StringType plugin_launcher =
127 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher); 128 browser_command_line.GetSwitchValueNative(switches::kPpapiPluginLauncher);
128 129
129 #if defined(OS_LINUX) 130 #if defined(OS_LINUX)
130 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : 131 int flags = plugin_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF :
131 ChildProcessHost::CHILD_NORMAL; 132 ChildProcessHost::CHILD_NORMAL;
132 #else 133 #else
133 int flags = ChildProcessHost::CHILD_NORMAL; 134 int flags = ChildProcessHost::CHILD_NORMAL;
134 #endif 135 #endif
135 FilePath exe_path = ChildProcessHost::GetChildPath(flags); 136 FilePath exe_path = ChildProcessHost::GetChildPath(flags);
136 if (exe_path.empty()) 137 if (exe_path.empty())
137 return false; 138 return false;
138 139
139 CommandLine* cmd_line = new CommandLine(exe_path); 140 CommandLine* cmd_line = new CommandLine(exe_path);
140 cmd_line->AppendSwitchASCII(switches::kProcessType, 141 cmd_line->AppendSwitchASCII(switches::kProcessType,
141 is_broker_ ? switches::kPpapiBrokerProcess 142 is_broker_ ? switches::kPpapiBrokerProcess
142 : switches::kPpapiPluginProcess); 143 : switches::kPpapiPluginProcess);
143 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id()); 144 cmd_line->AppendSwitchASCII(switches::kProcessChannelID,
145 child_process_host()->channel_id());
144 146
145 // These switches are forwarded to both plugin and broker pocesses. 147 // These switches are forwarded to both plugin and broker pocesses.
146 static const char* kCommonForwardSwitches[] = { 148 static const char* kCommonForwardSwitches[] = {
147 switches::kVModule 149 switches::kVModule
148 }; 150 };
149 cmd_line->CopySwitchesFrom(browser_command_line, kCommonForwardSwitches, 151 cmd_line->CopySwitchesFrom(browser_command_line, kCommonForwardSwitches,
150 arraysize(kCommonForwardSwitches)); 152 arraysize(kCommonForwardSwitches));
151 153
152 if (!is_broker_) { 154 if (!is_broker_) {
153 // TODO(vtl): Stop passing flash args in the command line, on windows is 155 // TODO(vtl): Stop passing flash args in the command line, on windows is
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // a hang. See the similar code in PluginProcessHost for more description. 193 // a hang. See the similar code in PluginProcessHost for more description.
192 PpapiMsg_CreateChannel* msg = new PpapiMsg_CreateChannel(process_handle, 194 PpapiMsg_CreateChannel* msg = new PpapiMsg_CreateChannel(process_handle,
193 renderer_id); 195 renderer_id);
194 msg->set_unblock(true); 196 msg->set_unblock(true);
195 if (Send(msg)) 197 if (Send(msg))
196 sent_requests_.push(client); 198 sent_requests_.push(client);
197 else 199 else
198 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); 200 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle());
199 } 201 }
200 202
201 bool PpapiPluginProcessHost::CanShutdown() {
202 return true;
203 }
204
205 void PpapiPluginProcessHost::OnProcessLaunched() { 203 void PpapiPluginProcessHost::OnProcessLaunched() {
206 } 204 }
207 205
208 bool PpapiPluginProcessHost::OnMessageReceived(const IPC::Message& msg) { 206 bool PpapiPluginProcessHost::OnMessageReceived(const IPC::Message& msg) {
209 bool handled = true; 207 bool handled = true;
210 IPC_BEGIN_MESSAGE_MAP(PpapiPluginProcessHost, msg) 208 IPC_BEGIN_MESSAGE_MAP(PpapiPluginProcessHost, msg)
211 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, 209 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated,
212 OnRendererPluginChannelCreated) 210 OnRendererPluginChannelCreated)
213 IPC_MESSAGE_UNHANDLED(handled = false) 211 IPC_MESSAGE_UNHANDLED(handled = false)
214 IPC_END_MESSAGE_MAP() 212 IPC_END_MESSAGE_MAP()
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 ::DuplicateHandle(::GetCurrentProcess(), plugin_process, 278 ::DuplicateHandle(::GetCurrentProcess(), plugin_process,
281 renderer_process, &renderers_plugin_handle, 279 renderer_process, &renderers_plugin_handle,
282 0, FALSE, DUPLICATE_SAME_ACCESS); 280 0, FALSE, DUPLICATE_SAME_ACCESS);
283 #elif defined(OS_POSIX) 281 #elif defined(OS_POSIX)
284 // Don't need to duplicate anything on POSIX since it's just a PID. 282 // Don't need to duplicate anything on POSIX since it's just a PID.
285 base::ProcessHandle renderers_plugin_handle = plugin_process; 283 base::ProcessHandle renderers_plugin_handle = plugin_process;
286 #endif 284 #endif
287 285
288 client->OnChannelOpened(renderers_plugin_handle, channel_handle); 286 client->OnChannelOpened(renderers_plugin_handle, channel_handle);
289 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698