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

Unified Diff: chrome/browser/nacl_host/nacl_browser_delegate_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: rebase 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/nacl_host/nacl_browser_delegate_impl.cc
diff --git a/chrome/browser/nacl_host/nacl_browser_delegate_impl.cc b/chrome/browser/nacl_host/nacl_browser_delegate_impl.cc
index a0e92bdc6839b1e3b57e5ab74587166f2b38154d..29fc0e1ccc3a07c04b9caaceea47737d6cf6d5d0 100644
--- a/chrome/browser/nacl_host/nacl_browser_delegate_impl.cc
+++ b/chrome/browser/nacl_host/nacl_browser_delegate_impl.cc
@@ -9,15 +9,20 @@
#include "base/strings/string_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h"
+#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/nacl_host/nacl_infobar_delegate.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/logging_chrome.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/site_instance.h"
#include "extensions/browser/info_map.h"
+#include "extensions/browser/process_manager.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/shared_module_info.h"
@@ -26,6 +31,77 @@
using extensions::SharedModuleInfo;
+namespace {
+
+// Handles an extension's NaCl process transitioning in or out of idle state by
+// relaying the state to the extension's process manager.
+//
+// A NaCl instance, when active, sends keepalive IPCs to the browser process
+// BrowserPpapiHost at a trottled rate. The content::BrowserPpapiHost passes
Mark Seaborn 2013/12/16 22:40:46 Typo: "throttled". Could you emphasise here that
scheib 2013/12/16 23:13:44 Done. "throttled". Bugged: https://code.google.com
Mark Seaborn 2013/12/18 09:11:43 Oh, I think I misread "active" in the comment as a
+// context information up to the chrome level NaClProcessHost where we use the
+// instance's context to find the associated extension process manager.
+//
+// There is 1:many relationship for extension:nacl-embeds, but only a
dmichael (off chromium) 2013/12/16 22:17:54 nit: "is +a+ 1:many"
scheib 2013/12/16 23:13:44 Done.
+// 1:1 relationship for NaClProcessHost:PP_Instance. The content layer doesn't
+// rely on this knowledge because it routes messages for ppapi non-nacl
+// instances as well, though they won't have callbacks set. Here the 1:1
+// assumption is made and DCHECKed.
+void OnKeepaliveOnUIThread(
+ const content::BrowserPpapiHost::OnKeepaliveInstanceData& intance_data,
Mark Seaborn 2013/12/16 22:40:46 "instance_data"
scheib 2013/12/16 23:13:44 Done.
+ const base::FilePath& profile_data_directory) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ // Only one instance will exist for NaCl embeds, even when more than one
+ // embed of the same plugin exists on the same page.
+ DCHECK(intance_data.size() == 1);
+ if (intance_data.size() < 1)
+ return;
+
+ content::RenderViewHost* render_view_host = content::RenderViewHost::FromID(
+ intance_data[0].render_process_id, intance_data[0].render_view_id);
+ if (!render_view_host)
+ return;
+
+ content::SiteInstance* site_instance = render_view_host->GetSiteInstance();
+ if (!site_instance)
+ return;
+
+ extensions::ExtensionSystem* extension_system =
+ extensions::ExtensionSystem::GetForBrowserContext(
+ site_instance->GetBrowserContext());
+ if (!extension_system)
+ return;
+
+ const ExtensionService* extension_service =
+ extension_system->extension_service();
+ if (!extension_service)
+ return;
+
+ const extensions::Extension* extension = extension_service->GetExtensionById(
+ intance_data[0].document_url.host(), false);
+ if (!extension)
+ return;
+
+ extensions::ProcessManager* pm = extension_system->process_manager();
+ if (!pm)
+ return;
+
+ pm->KeepaliveImpulse(extension);
+}
+
+// Calls OnKeepaliveOnUIThread on UI thread.
+void OnKeepalive(
+ const content::BrowserPpapiHost::OnKeepaliveInstanceData& intance_data,
Mark Seaborn 2013/12/16 22:40:46 "instance_data"
scheib 2013/12/16 23:13:44 Done.
+ const base::FilePath& profile_data_directory) {
+ DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&OnKeepaliveOnUIThread,
+ intance_data,
+ profile_data_directory));
+}
+
+} // namespace
+
NaClBrowserDelegateImpl::NaClBrowserDelegateImpl(
extensions::InfoMap* extension_info_map)
: extension_info_map_(extension_info_map), inverse_debug_patterns_(false) {}
@@ -181,3 +257,8 @@ bool NaClBrowserDelegateImpl::MapUrlToLocalFilePath(
*file_path = resource_file_path;
return true;
}
+
+content::BrowserPpapiHost::OnKeepaliveCallback
+NaClBrowserDelegateImpl::GetOnKeepaliveCallback() {
+ return base::Bind(&OnKeepalive);
+}

Powered by Google App Engine
This is Rietveld 408576698