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

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: comment for 'active' instance. 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 BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter(
151 ppapi::host::PpapiHost* ppapi_host,
152 BrowserPpapiHostImpl* browser_ppapi_host_impl)
153 : ppapi_host_(ppapi_host),
154 browser_ppapi_host_impl_(browser_ppapi_host_impl) {
155 }
156
145 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( 157 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived(
146 const IPC::Message& msg) { 158 const IPC::Message& msg) {
147 // Don't forward messages if our owner object has been destroyed. 159 // Don't forward messages if our owner object has been destroyed.
148 if (!ppapi_host_) 160 if (!ppapi_host_)
149 return false; 161 return false;
150 162
151 /* TODO(brettw) when we add messages, here, the code should look like this:
152 bool handled = true; 163 bool handled = true;
153 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) 164 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl::HostMessageFilter, msg)
154 // Add necessary message handlers here. 165 // Add necessary message handlers here.
166 IPC_MESSAGE_HANDLER(PpapiHostMsg_Keepalive, OnKeepalive)
155 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) 167 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg))
156 IPC_END_MESSAGE_MAP(); 168 IPC_END_MESSAGE_MAP();
157 return handled; 169 return handled;
158 */
159 return ppapi_host_->OnMessageReceived(msg);
160 } 170 }
161 171
162 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { 172 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() {
163 DCHECK(ppapi_host_); 173 DCHECK(ppapi_host_);
164 ppapi_host_ = NULL; 174 ppapi_host_ = NULL;
175 browser_ppapi_host_impl_ = NULL;
176 }
177
178 BrowserPpapiHostImpl::HostMessageFilter::~HostMessageFilter() {
179 }
180
181 void BrowserPpapiHostImpl::HostMessageFilter::OnKeepalive() {
182 if (browser_ppapi_host_impl_)
183 browser_ppapi_host_impl_->OnKeepalive();
184 }
185
186 void BrowserPpapiHostImpl::OnKeepalive() {
187 // An instance has been active. The on_keepalive_callback_ will be
188 // used to permit the content embedder to handle this, e.g. by tracking
189 // activity and shutting down processes that go idle.
190 //
191 // Currently embedders do not need to distinguish between instances having
192 // different idle state, and thus this implementation handles all instances
193 // for this module together.
194
195 if (on_keepalive_callback_.is_null())
196 return;
197
198 BrowserPpapiHost::OnKeepaliveInstanceData
199 instance_data(instance_map_.size());
200
201 InstanceMap::iterator instance = instance_map_.begin();
202 int i = 0;
203 while (instance != instance_map_.end()) {
204 instance_data[i].render_process_id = instance->second.render_process_id;
205 instance_data[i].render_view_id = instance->second.render_view_id;
206 instance_data[i].document_url = instance->second.document_url;
207 ++instance;
208 ++i;
209 }
210 on_keepalive_callback_.Run(instance_data, profile_data_directory_);
165 } 211 }
166 212
167 } // namespace content 213 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper/browser_ppapi_host_impl.h ('k') | content/public/browser/browser_ppapi_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698