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

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: Move callback impl to nacl_browser_delegate_impl.cc. Created 7 years, 1 month 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 24 matching lines...) Expand all
47 const base::FilePath& profile_data_directory, 47 const base::FilePath& profile_data_directory,
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 weak_factory_(this) {
59 message_filter_ = new HostMessageFilter(ppapi_host_.get(),
60 base::Bind(&BrowserPpapiHostImpl::OnIdleChange,
61 weak_factory_.GetWeakPtr()));
59 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( 62 ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>(
60 new ContentBrowserPepperHostFactory(this))); 63 new ContentBrowserPepperHostFactory(this)));
61 } 64 }
62 65
63 BrowserPpapiHostImpl::~BrowserPpapiHostImpl() { 66 BrowserPpapiHostImpl::~BrowserPpapiHostImpl() {
64 // Notify the filter so it won't foward messages to us. 67 // Notify the filter so it won't foward messages to us.
65 message_filter_->OnHostDestroyed(); 68 message_filter_->OnHostDestroyed();
66 69
67 // Delete the host explicitly first. This shutdown will destroy the 70 // Delete the host explicitly first. This shutdown will destroy the
68 // resources, which may want to do cleanup in their destructors and expect 71 // 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; 122 return found->second.document_url;
120 } 123 }
121 124
122 GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) { 125 GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) {
123 InstanceMap::const_iterator found = instance_map_.find(instance); 126 InstanceMap::const_iterator found = instance_map_.find(instance);
124 if (found == instance_map_.end()) 127 if (found == instance_map_.end())
125 return GURL(); 128 return GURL();
126 return found->second.plugin_url; 129 return found->second.plugin_url;
127 } 130 }
128 131
132 void BrowserPpapiHostImpl::SetOnIdleChangeCallback(
133 const BrowserPpapiHost::OnIdleChangeCallback callback) {
134 on_idle_change_callback_ = callback;
135 }
136
129 void BrowserPpapiHostImpl::AddInstance( 137 void BrowserPpapiHostImpl::AddInstance(
130 PP_Instance instance, 138 PP_Instance instance,
131 const PepperRendererInstanceData& instance_data) { 139 const PepperRendererInstanceData& instance_data) {
132 DCHECK(instance_map_.find(instance) == instance_map_.end()); 140 DCHECK(instance_map_.find(instance) == instance_map_.end());
133 instance_map_[instance] = instance_data; 141 instance_map_[instance] = instance_data;
134 } 142 }
135 143
136 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { 144 void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) {
137 InstanceMap::iterator found = instance_map_.find(instance); 145 InstanceMap::iterator found = instance_map_.find(instance);
138 if (found == instance_map_.end()) { 146 if (found == instance_map_.end()) {
139 NOTREACHED(); 147 NOTREACHED();
140 return; 148 return;
141 } 149 }
142 instance_map_.erase(found); 150 instance_map_.erase(found);
143 } 151 }
144 152
153 BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter(
154 ppapi::host::PpapiHost* ppapi_host,
155 const OnIdleChangeCallback on_idle_change_callback)
156 : ppapi_host_(ppapi_host),
157 on_idle_change_callback_(on_idle_change_callback)
158 {
yzshen1 2013/11/21 18:01:50 put it on the previous line, please
scheib 2013/12/11 21:35:40 Done.
159 }
160
145 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( 161 bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived(
146 const IPC::Message& msg) { 162 const IPC::Message& msg) {
147 // Don't forward messages if our owner object has been destroyed. 163 // Don't forward messages if our owner object has been destroyed.
148 if (!ppapi_host_) 164 if (!ppapi_host_)
149 return false; 165 return false;
150 166
151 /* TODO(brettw) when we add messages, here, the code should look like this:
152 bool handled = true; 167 bool handled = true;
153 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) 168 IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl::HostMessageFilter, msg)
154 // Add necessary message handlers here. 169 // Add necessary message handlers here.
170 IPC_MESSAGE_HANDLER(PpapiHostMsg_IdleStateChange,
171 OnIdleStateChange)
155 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) 172 IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg))
156 IPC_END_MESSAGE_MAP(); 173 IPC_END_MESSAGE_MAP();
157 return handled; 174 return handled;
158 */
159 return ppapi_host_->OnMessageReceived(msg);
160 } 175 }
161 176
162 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { 177 void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() {
163 DCHECK(ppapi_host_); 178 DCHECK(ppapi_host_);
164 ppapi_host_ = NULL; 179 ppapi_host_ = NULL;
165 } 180 }
166 181
182 BrowserPpapiHostImpl::HostMessageFilter::~HostMessageFilter()
183 {
yzshen1 2013/11/21 18:01:50 previous line, please
scheib 2013/12/11 21:35:40 Done.
184 }
185
186 void BrowserPpapiHostImpl::HostMessageFilter::OnIdleStateChange(bool idle) {
yzshen1 2013/11/21 18:01:50 nit: it is better to reorder the method definition
scheib 2013/12/11 21:35:40 Done.
187 on_idle_change_callback_.Run(idle);
188 }
189
190 void BrowserPpapiHostImpl::OnIdleChange(bool idle) {
191 // An instance has become idle or active. The on_idle_chnge_callback_ will be
yzshen1 2013/11/21 18:01:50 chnge -> change
scheib 2013/12/11 21:35:40 Done.
192 // used to permit the content embedder to handle this, e.g. by shutting down
193 // processes that have gone idle.
194 //
195 // Currently embedders do not need to distinguish between instances having
196 // different idle state, and thus this implementation tracks idle
197 // state for all instances together.
198
199 if (on_idle_change_callback_.is_null())
200 return;
201
202 BrowserPpapiHost::OnIdleChangeInstanceData
203 instance_data(instance_map_.size());
204
205 InstanceMap::iterator instance = instance_map_.begin();
206
207 int i = 0;
208 while (instance != instance_map_.end()) {
209 instance_data[i].render_process_id = instance->second.render_process_id;
210 instance_data[i].render_view_id = instance->second.render_view_id;
211 instance_data[i].document_url = instance->second.document_url;
212 ++instance;
213 ++i;
214 }
215 on_idle_change_callback_.Run(instance_data, profile_data_directory_,
216 idle);
217 }
218
167 } // namespace content 219 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698