Chromium Code Reviews| Index: chrome/browser/nacl_host/nacl_process_host.cc |
| diff --git a/chrome/browser/nacl_host/nacl_process_host.cc b/chrome/browser/nacl_host/nacl_process_host.cc |
| index 530ebbb50318b7ab873e46560581e670801946ad..6108c3abfc101ba543f54b349daca2aa66a8ab40 100644 |
| --- a/chrome/browser/nacl_host/nacl_process_host.cc |
| +++ b/chrome/browser/nacl_host/nacl_process_host.cc |
| @@ -25,7 +25,10 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/win/windows_version.h" |
| #include "build/build_config.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
|
Mark Seaborn
2013/11/15 01:32:56
I don't know if you want a review for this change
scheib
2013/12/11 21:35:40
Done.
|
| +#include "chrome/browser/extensions/extension_system.h" |
| #include "chrome/browser/nacl_host/nacl_host_message_filter.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "components/nacl/browser/nacl_browser.h" |
| #include "components/nacl/common/nacl_cmd_line.h" |
| @@ -36,9 +39,12 @@ |
| #include "content/public/browser/browser_child_process_host.h" |
| #include "content/public/browser/browser_ppapi_host.h" |
| #include "content/public/browser/child_process_data.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/site_instance.h" |
| #include "content/public/common/child_process_host.h" |
| #include "content/public/common/content_switches.h" |
| #include "content/public/common/process_type.h" |
| +#include "extensions/browser/process_manager.h" |
| #include "ipc/ipc_channel.h" |
| #include "ipc/ipc_switches.h" |
| #include "native_client/src/shared/imc/nacl_imc_c.h" |
| @@ -198,6 +204,90 @@ ppapi::PpapiPermissions GetNaClPermissions(uint32 permission_bits) { |
| return ppapi::PpapiPermissions::GetForCommandLine(masked_bits); |
| } |
| +// 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 monitors its activity and sends an IPC to the browser |
| +// process BrowserPpapiHost upon transitioning in our out of idleness. The |
| +// content::BrowserPpapiHost passes 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 |
| +// 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 OnIdleStateChangeOnUIThread( |
| + content::BrowserPpapiHost::OnIdleChangeInstanceData intance_data, |
| + const base::FilePath profile_data_directory, |
| + bool idle) { |
| + DCHECK(BrowserThread::CurrentlyOn(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); |
| + DCHECK(render_view_host); |
| + if (!render_view_host) |
| + return; |
| + |
| + content::SiteInstance* site_instance = render_view_host->GetSiteInstance(); |
| + DCHECK(site_instance); |
| + if (!site_instance) |
| + return; |
| + |
| + extensions::ExtensionSystem* extension_system = |
| + extensions::ExtensionSystem::GetForBrowserContext( |
| + site_instance->GetBrowserContext()); |
| + DCHECK(extension_system); |
| + if (!extension_system) |
| + return; |
| + |
| + const ExtensionService* extension_service = |
| + extension_system->extension_service(); |
| + DCHECK(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(); |
| + DCHECK(pm); |
| + if (!pm) |
| + return; |
| + |
| + if (idle) { |
| + fprintf(stderr, "%s:%s:%d DecrementLazyKeepaliveCount\n", |
| + __FILE__, __FUNCTION__, __LINE__); |
| + pm->DecrementLazyKeepaliveCount(extension); |
| + } else { |
| + fprintf(stderr, "%s:%s:%d IncrementLazyKeepaliveCount\n", |
| + __FILE__, __FUNCTION__, __LINE__); |
| + pm->IncrementLazyKeepaliveCount(extension); |
| + } |
| +} |
| + |
| +// Calls OnIdleStateChangeOnUIThread on UI thread. |
| +void OnIdleStateChange( |
| + content::BrowserPpapiHost::OnIdleChangeInstanceData intance_data, |
| + const base::FilePath profile_data_directory, |
| + bool idle) { |
| + DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&OnIdleStateChangeOnUIThread, |
| + intance_data, |
| + profile_data_directory, |
| + idle)); |
| +} |
| + |
| } // namespace |
| struct NaClProcessHost::NaClInternal { |
| @@ -797,6 +887,8 @@ void NaClProcessHost::OnPpapiChannelCreated( |
| render_view_id_, |
| profile_directory_)); |
| + ppapi_host_->SetOnIdleChangeCallback(base::Bind(&OnIdleStateChange)); |
| + |
| ppapi::PpapiNaClChannelArgs args; |
| args.off_the_record = nacl_host_message_filter_->off_the_record(); |
| args.permissions = permissions_; |