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

Side by Side Diff: content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc

Issue 61063003: Keep NaCl plugins used in app background pages alive when active. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments in patch 3 & 4. Created 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer_host/pepper/browser_ppapi_host_impl.h" 5 #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h"
6 6
7 #include "content/browser/renderer_host/pepper/pepper_message_filter.h" 7 #include "content/browser/renderer_host/pepper/pepper_message_filter.h"
8 #include "content/browser/tracing/trace_message_filter.h" 8 #include "content/browser/tracing/trace_message_filter.h"
9 #include "content/common/pepper_renderer_instance_data.h" 9 #include "content/common/pepper_renderer_instance_data.h"
10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/common/process_type.h" 10 #include "content/public/common/process_type.h"
12 #include "ipc/ipc_message_macros.h" 11 #include "ipc/ipc_message_macros.h"
12 #include "ppapi/proxy/ppapi_messages.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 // static 16 // static
17 BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess( 17 BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess(
18 IPC::Sender* sender, 18 IPC::Sender* sender,
19 ppapi::PpapiPermissions permissions, 19 ppapi::PpapiPermissions permissions,
20 base::ProcessHandle plugin_child_process, 20 base::ProcessHandle plugin_child_process,
21 IPC::ChannelProxy* channel, 21 IPC::ChannelProxy* channel,
22 int render_process_id, 22 int render_process_id,
(...skipping 25 matching lines...) Expand all
48 bool in_process, 48 bool in_process,
49 bool external_plugin) 49 bool external_plugin)
50 : ppapi_host_(new ppapi::host::PpapiHost(sender, permissions)), 50 : ppapi_host_(new ppapi::host::PpapiHost(sender, permissions)),
51 plugin_process_handle_(base::kNullProcessHandle), 51 plugin_process_handle_(base::kNullProcessHandle),
52 plugin_name_(plugin_name), 52 plugin_name_(plugin_name),
53 plugin_path_(plugin_path), 53 plugin_path_(plugin_path),
54 profile_data_directory_(profile_data_directory), 54 profile_data_directory_(profile_data_directory),
55 in_process_(in_process), 55 in_process_(in_process),
56 external_plugin_(external_plugin), 56 external_plugin_(external_plugin),
57 ssl_context_helper_(new SSLContextHelper()) { 57 ssl_context_helper_(new SSLContextHelper()) {
58 message_filter_ = new HostMessageFilter(ppapi_host_.get()); 58 message_filter_ = new HostMessageFilter(ppapi_host_.get(), this);
59 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( 59 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>(
60 new ContentBrowserPepperHostFactory(this))); 60 new ContentBrowserPepperHostFactory(this)));
61 } 61 }
62 62
63 BrowserPpapiHostImpl::~BrowserPpapiHostImpl() { 63 BrowserPpapiHostImpl::~BrowserPpapiHostImpl() {
64 // Notify the filter so it won't foward messages to us. 64 // Notify the filter so it won't foward messages to us.
65 message_filter_->OnHostDestroyed(); 65 message_filter_->OnHostDestroyed();
66 66
67 // Delete the host explicitly first. This shutdown will destroy the 67 // Delete the host explicitly first. This shutdown will destroy the
68 // resources, which may want to do cleanup in their destructors and expect 68 // resources, which may want to do cleanup in their destructors and expect
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return found->second.document_url; 119 return found->second.document_url;
120 } 120 }
121 121
122 GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) { 122 GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) {
123 InstanceMap::const_iterator found = instance_map_.find(instance); 123 InstanceMap::const_iterator found = instance_map_.find(instance);
124 if (found == instance_map_.end()) 124 if (found == instance_map_.end())
125 return GURL(); 125 return GURL();
126 return found->second.plugin_url; 126 return found->second.plugin_url;
127 } 127 }
128 128
129 void BrowserPpapiHostImpl::SetOnKeepaliveCallback(
130 const BrowserPpapiHost::OnKeepaliveCallback& callback) {
131 on_keepalive_callback_ = callback;
132 }
133
129 void BrowserPpapiHostImpl::AddInstance( 134 void BrowserPpapiHostImpl::AddInstance(
130 PP_Instance instance, 135 PP_Instance instance,
131 const PepperRendererInstanceData& instance_data) { 136 const PepperRendererInstanceData& instance_data) {
132 DCHECK(instance_map_.find(instance) == instance_map_.end()); 137 DCHECK(instance_map_.find(instance) == instance_map_.end());
133 instance_map_[instance] = instance_data; 138 instance_map_[instance] = instance_data;
134 } 139 }
135 140
136 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { 141 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) {
137 InstanceMap::iterator found = instance_map_.find(instance); 142 InstanceMap::iterator found = instance_map_.find(instance);
138 if (found == instance_map_.end()) { 143 if (found == instance_map_.end()) {
139 NOTREACHED(); 144 NOTREACHED();
140 return; 145 return;
141 } 146 }
142 instance_map_.erase(found); 147 instance_map_.erase(found);
143 } 148 }
144 149
150 void BrowserPpapiHostImpl::OnKeepalive() {
yzshen1 2013/12/13 21:23:15 I notice you used Keep*a*live in quite some places
scheib 2013/12/14 00:07:41 I've moved everything to "keepalive". Both are us
yzshen1 2013/12/14 00:36:33 Sounds good. Thanks! On 2013/12/14 00:07:41, schei
151 // An instance has been active. The on_keepalive_callback_ will be
152 // used to permit the content embedder to handle this, e.g. by shutting down
yzshen1 2013/12/13 21:23:15 It seems we need to update the comment, now that i
scheib 2013/12/14 00:07:41 Done.
153 // processes that have gone idle.
154 //
155 // Currently embedders do not need to distinguish between instances having
156 // different idle state, and thus this implementation handles all instances
157 // for this module together.
158
159 if (on_keepalive_callback_.is_null())
160 return;
161
162 BrowserPpapiHost::OnKeepaliveInstanceData
163 instance_data(instance_map_.size());
164
165 InstanceMap::iterator instance = instance_map_.begin();
166 int i = 0;
167 while (instance != instance_map_.end()) {
168 instance_data[i].render_process_id = instance->second.render_process_id;
169 instance_data[i].render_view_id = instance->second.render_view_id;
170 instance_data[i].document_url = instance->second.document_url;
171 ++instance;
172 ++i;
173 }
174 on_keepalive_callback_.Run(instance_data, profile_data_directory_);
175 }
176
177 BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter(
178 ppapi::host::PpapiHost* ppapi_host,
179 BrowserPpapiHostImpl* browser_ppapi_host_impl)
180 : ppapi_host_(ppapi_host),
181 browser_ppapi_host_impl_(browser_ppapi_host_impl)
182 {}
yzshen1 2013/12/13 21:23:15 { should be on the previous line.
scheib 2013/12/14 00:07:41 Done.
183
145 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( 184 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived(
146 const IPC::Message& msg) { 185 const IPC::Message& msg) {
147 // Don't forward messages if our owner object has been destroyed. 186 // Don't forward messages if our owner object has been destroyed.
148 if (!ppapi_host_) 187 if (!ppapi_host_)
149 return false; 188 return false;
150 189
151 /* TODO(brettw) when we add messages, here, the code should look like this:
152 bool handled = true; 190 bool handled = true;
153 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) 191 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl::HostMessageFilter, msg)
154 // Add necessary message handlers here. 192 // Add necessary message handlers here.
193 IPC_MESSAGE_HANDLER(PpapiHostMsg_Keepalive, OnKeepalive)
155 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) 194 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg))
156 IPC_END_MESSAGE_MAP(); 195 IPC_END_MESSAGE_MAP();
157 return handled; 196 return handled;
158 */
159 return ppapi_host_->OnMessageReceived(msg);
160 } 197 }
161 198
162 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { 199 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() {
163 DCHECK(ppapi_host_); 200 DCHECK(ppapi_host_);
164 ppapi_host_ = NULL; 201 ppapi_host_ = NULL;
202 browser_ppapi_host_impl_ = NULL;
203 }
204
205 BrowserPpapiHostImpl::HostMessageFilter::~HostMessageFilter()
206 {}
yzshen1 2013/12/13 21:23:15 ditto.
scheib 2013/12/14 00:07:41 Done.
207
208 void BrowserPpapiHostImpl::HostMessageFilter::OnKeepalive() {
209 if (browser_ppapi_host_impl_)
210 browser_ppapi_host_impl_->OnKeepalive();
165 } 211 }
166 212
167 } // namespace content 213 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698