diff options
author | cjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-15 20:26:43 +0000 |
---|---|---|
committer | cjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-15 20:26:43 +0000 |
commit | df630986834eb937ea75be5a62b9b9eee6c8ca32 (patch) | |
tree | 3b7617b2820a4ee8bc4d46ad32ab84198c9cfdc4 /content/browser | |
parent | 896443ab2572df762937af04661eec3305c83434 (diff) | |
download | chromium_src-df630986834eb937ea75be5a62b9b9eee6c8ca32.zip chromium_src-df630986834eb937ea75be5a62b9b9eee6c8ca32.tar.gz chromium_src-df630986834eb937ea75be5a62b9b9eee6c8ca32.tar.bz2 |
Ensure that the foreground tab's process has high priority
To reclaim memory, Android will kill renderer processes before killing
the browser process (See
http://developer.android.com/guide/components/processes-and-threads.html).
That is, the browser process is a foreground process while the renderer
processes are service processes. A foreground process can bind to a
service process so that that process has the same priority as the
foreground process (in terms of what should be killed).
BUG=159980
Review URL: https://chromiumcodereview.appspot.com/11361252
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168007 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r-- | content/browser/android/content_view_core_impl.cc | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index 9151608..95c5180 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -74,6 +74,17 @@ namespace { jfieldID g_native_content_view; const void* kContentViewUserDataKey = &kContentViewUserDataKey; + +int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { + DCHECK(host); + RenderProcessHost* render_process = host->GetProcess(); + DCHECK(render_process); + if (render_process->HasConnection()) + return render_process->GetHandle(); + else + return 0; +} + } // namespace // Enables a callback when the underlying WebContents is destroyed, to enable @@ -198,9 +209,12 @@ void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(JNIEnv* env, void ContentViewCoreImpl::InitWebContents() { DCHECK(web_contents_); - notification_registrar_.Add(this, - NOTIFICATION_RENDER_VIEW_HOST_CHANGED, + notification_registrar_.Add( + this, NOTIFICATION_RENDER_VIEW_HOST_CHANGED, Source<NavigationController>(&web_contents_->GetController())); + notification_registrar_.Add( + this, NOTIFICATION_RENDERER_PROCESS_CREATED, + content::NotificationService::AllBrowserContextsAndSources()); static_cast<WebContentsViewAndroid*>(web_contents_->GetView())-> SetContentViewCore(this); @@ -213,6 +227,45 @@ void ContentViewCoreImpl::Observe(int type, const NotificationSource& source, const NotificationDetails& details) { switch (type) { + case NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { + std::pair<RenderViewHost*, RenderViewHost*>* switched_details = + Details<std::pair<RenderViewHost*, RenderViewHost*> >(details).ptr(); + int old_pid = 0; + if (switched_details->first) { + old_pid = GetRenderProcessIdFromRenderViewHost( + switched_details->first); + } + int new_pid = GetRenderProcessIdFromRenderViewHost( + web_contents_->GetRenderViewHost()); + if (new_pid != old_pid) { + // Notify the Java side of the change of the current renderer process. + JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); + if (!obj.is_null()) { + Java_ContentViewCore_onRenderProcessSwap( + env, obj.obj(), old_pid, new_pid); + } + } + break; + } + case NOTIFICATION_RENDERER_PROCESS_CREATED: { + // Notify the Java side of the current renderer process. + RenderProcessHost* source_process_host = + Source<RenderProcessHost>(source).ptr(); + RenderProcessHost* current_process_host = + web_contents_->GetRenderViewHost()->GetProcess(); + + if (source_process_host == current_process_host) { + int pid = GetRenderProcessIdFromRenderViewHost( + web_contents_->GetRenderViewHost()); + JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); + if (!obj.is_null()) { + Java_ContentViewCore_onRenderProcessSwap(env, obj.obj(), 0, pid); + } + } + break; + } case NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT: { if (!web_contents_ || Source<RenderViewHost>(source).ptr() != web_contents_->GetRenderViewHost()) { @@ -630,14 +683,8 @@ void ContentViewCoreImpl::LoadUrl( } jint ContentViewCoreImpl::GetCurrentRenderProcessId(JNIEnv* env, jobject obj) { - RenderViewHost* host = web_contents_->GetRenderViewHost(); - DCHECK(host); - RenderProcessHost* render_process = host->GetProcess(); - DCHECK(render_process); - if (render_process->HasConnection()) - return render_process->GetHandle(); - else - return 0; + return GetRenderProcessIdFromRenderViewHost( + web_contents_->GetRenderViewHost()); } void ContentViewCoreImpl::SetAllUserAgentOverridesInHistory( |