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..b79a28b10cd4826986c6b98de8d98837a0b04764 100644 |
--- a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc |
+++ b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc |
@@ -7,9 +7,9 @@ |
#include "content/browser/renderer_host/pepper/pepper_message_filter.h" |
#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/common/process_type.h" |
#include "ipc/ipc_message_macros.h" |
+#include "ppapi/proxy/ppapi_messages.h" |
namespace content { |
@@ -54,8 +54,11 @@ BrowserPpapiHostImpl::BrowserPpapiHostImpl( |
profile_data_directory_(profile_data_directory), |
in_process_(in_process), |
external_plugin_(external_plugin), |
- ssl_context_helper_(new SSLContextHelper()) { |
- message_filter_ = new HostMessageFilter(ppapi_host_.get()); |
+ ssl_context_helper_(new SSLContextHelper()), |
+ weak_factory_(this) { |
+ message_filter_ = new HostMessageFilter(ppapi_host_.get(), |
+ base::Bind(&BrowserPpapiHostImpl::OnIdleChange, |
+ weak_factory_.GetWeakPtr())); |
ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( |
new ContentBrowserPepperHostFactory(this))); |
} |
@@ -126,6 +129,11 @@ GURL BrowserPpapiHostImpl::GetPluginURLForInstance(PP_Instance instance) { |
return found->second.plugin_url; |
} |
+void BrowserPpapiHostImpl::SetOnIdleChangeCallback( |
+ const BrowserPpapiHost::OnIdleChangeCallback callback) { |
+ on_idle_change_callback_ = callback; |
+} |
+ |
void BrowserPpapiHostImpl::AddInstance( |
PP_Instance instance, |
const PepperRendererInstanceData& instance_data) { |
@@ -142,21 +150,28 @@ void BrowserPpapiHostImpl::DeleteInstance(PP_Instance instance) { |
instance_map_.erase(found); |
} |
+BrowserPpapiHostImpl::HostMessageFilter::HostMessageFilter( |
+ ppapi::host::PpapiHost* ppapi_host, |
+ const OnIdleChangeCallback on_idle_change_callback) |
+ : ppapi_host_(ppapi_host), |
+ on_idle_change_callback_(on_idle_change_callback) |
+{ |
yzshen1
2013/11/21 18:01:50
put it on the previous line, please
scheib
2013/12/11 21:35:40
Done.
|
+} |
+ |
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_IdleStateChange, |
+ OnIdleStateChange) |
IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) |
IPC_END_MESSAGE_MAP(); |
return handled; |
- */ |
- return ppapi_host_->OnMessageReceived(msg); |
} |
void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { |
@@ -164,4 +179,41 @@ void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { |
ppapi_host_ = NULL; |
} |
+BrowserPpapiHostImpl::HostMessageFilter::~HostMessageFilter() |
+{ |
yzshen1
2013/11/21 18:01:50
previous line, please
scheib
2013/12/11 21:35:40
Done.
|
+} |
+ |
+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.
|
+ on_idle_change_callback_.Run(idle); |
+} |
+ |
+void BrowserPpapiHostImpl::OnIdleChange(bool idle) { |
+ // 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.
|
+ // used to permit the content embedder to handle this, e.g. by shutting down |
+ // processes that have gone idle. |
+ // |
+ // Currently embedders do not need to distinguish between instances having |
+ // different idle state, and thus this implementation tracks idle |
+ // state for all instances together. |
+ |
+ if (on_idle_change_callback_.is_null()) |
+ return; |
+ |
+ BrowserPpapiHost::OnIdleChangeInstanceData |
+ instance_data(instance_map_.size()); |
+ |
+ InstanceMap::iterator instance = instance_map_.begin(); |
+ |
+ int i = 0; |
+ while (instance != instance_map_.end()) { |
+ instance_data[i].render_process_id = instance->second.render_process_id; |
+ instance_data[i].render_view_id = instance->second.render_view_id; |
+ instance_data[i].document_url = instance->second.document_url; |
+ ++instance; |
+ ++i; |
+ } |
+ on_idle_change_callback_.Run(instance_data, profile_data_directory_, |
+ idle); |
+} |
+ |
} // namespace content |