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

Unified 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: fix ref counted compile warning 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc
diff --git a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc
index c3c2c6f39323a35caaf4f3a0da7cfab6e9a168b0..4109a99858341bec77eabe5dc0ddce609eca6feb 100644
--- a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc
+++ b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc
@@ -8,13 +8,16 @@
#include "content/browser/tracing/trace_message_filter.h"
#include "content/common/pepper_renderer_instance_data.h"
#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/site_instance.h"
#include "content/public/common/process_type.h"
#include "ipc/ipc_message_macros.h"
+#include "ppapi/proxy/ppapi_messages.h"
namespace content {
// static
-BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess(
+scoped_refptr<BrowserPpapiHost> BrowserPpapiHost::CreateExternalPluginProcess(
+ BrowserPpapiHost::Delegate* delegate,
IPC::Sender* sender,
ppapi::PpapiPermissions permissions,
base::ProcessHandle plugin_child_process,
@@ -23,8 +26,8 @@ BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess(
int render_view_id,
const base::FilePath& profile_directory) {
// The plugin name and path shouldn't be needed for external plugins.
- BrowserPpapiHostImpl* browser_ppapi_host =
- new BrowserPpapiHostImpl(sender, permissions, std::string(),
+ scoped_refptr<BrowserPpapiHostImpl> browser_ppapi_host =
+ new BrowserPpapiHostImpl(delegate, sender, permissions, std::string(),
base::FilePath(), profile_directory,
false /* in_process */,
true /* external_plugin */);
@@ -40,6 +43,7 @@ BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess(
}
BrowserPpapiHostImpl::BrowserPpapiHostImpl(
+ BrowserPpapiHost::Delegate* delegate,
IPC::Sender* sender,
const ppapi::PpapiPermissions& permissions,
const std::string& plugin_name,
@@ -47,7 +51,8 @@ BrowserPpapiHostImpl::BrowserPpapiHostImpl(
const base::FilePath& profile_data_directory,
bool in_process,
bool external_plugin)
- : ppapi_host_(new ppapi::host::PpapiHost(sender, permissions)),
+ : delegate_(delegate),
+ ppapi_host_(new ppapi::host::PpapiHost(sender, permissions)),
plugin_process_handle_(base::kNullProcessHandle),
plugin_name_(plugin_name),
plugin_path_(plugin_path),
@@ -55,21 +60,11 @@ BrowserPpapiHostImpl::BrowserPpapiHostImpl(
in_process_(in_process),
external_plugin_(external_plugin),
ssl_context_helper_(new SSLContextHelper()) {
- message_filter_ = new HostMessageFilter(ppapi_host_.get());
+ message_filter_ = new HostMessageFilter(this, ppapi_host_.get());
ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>(
new ContentBrowserPepperHostFactory(this)));
}
-BrowserPpapiHostImpl::~BrowserPpapiHostImpl() {
- // Notify the filter so it won't foward messages to us.
- message_filter_->OnHostDestroyed();
-
- // Delete the host explicitly first. This shutdown will destroy the
- // resources, which may want to do cleanup in their destructors and expect
- // their pointers to us to be valid.
- ppapi_host_.reset();
-}
-
ppapi::host::PpapiHost* BrowserPpapiHostImpl::GetPpapiHost() {
return ppapi_host_.get();
}
@@ -142,26 +137,60 @@ void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) {
instance_map_.erase(found);
}
+void BrowserPpapiHostImpl::OnIdleState(bool idle) {
+ if (!delegate_)
+ return;
+
+ for (InstanceMap::iterator i = instance_map_.begin();
+ i != instance_map_.end();
+ ++i) {
+ RenderViewHost* render_view_host = RenderViewHost::FromID(
+ i->second.render_process_id, i->second.render_view_id);
+
+ delegate_->OnIdleState(idle, profile_data_directory_, render_view_host,
+ i->second.document_url);
+ }
+}
+
+BrowserPpapiHostImpl::~BrowserPpapiHostImpl() {
+ // Notify the filter so it won't foward messages to us.
+ message_filter_->OnHostDestroyed();
+
+ // Delete the host explicitly first. This shutdown will destroy the
+ // resources, which may want to do cleanup in their destructors and expect
+ // their pointers to us to be valid.
+ ppapi_host_.reset();
+}
+
bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived(
const IPC::Message& msg) {
// Don't forward messages if our owner object has been destroyed.
if (!ppapi_host_)
return false;
- /* TODO(brettw) when we add messages, here, the code should look like this:
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg)
+ IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl::HostMessageFilter, msg)
// Add necessary message handlers here.
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_IdleState,
+ OnIdleState)
IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg))
IPC_END_MESSAGE_MAP();
return handled;
- */
- return ppapi_host_->OnMessageReceived(msg);
}
void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() {
+ browser_ppapi_host_impl_ = NULL;
DCHECK(ppapi_host_);
ppapi_host_ = NULL;
}
+void BrowserPpapiHostImpl::HostMessageFilter::OnIdleState(bool idle) {
+ if (browser_ppapi_host_impl_) {
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&BrowserPpapiHostImpl::OnIdleState,
yzshen1 2013/11/06 22:43:15 Important: BrowserPpapiHostImpl should be accessed
scheib 2013/11/15 01:22:17 Done.
+ browser_ppapi_host_impl_,
+ idle));
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698