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

Side by Side Diff: android_webview/native/aw_contents.cc

Issue 23888003: Free memory when the last WebView instance is destroyed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding comment Created 7 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/native/aw_contents.h" 5 #include "android_webview/native/aw_contents.h"
6 6
7 #include "android_webview/browser/aw_browser_context.h" 7 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_browser_main_parts.h" 8 #include "android_webview/browser/aw_browser_main_parts.h"
9 #include "android_webview/browser/gpu_memory_buffer_factory_impl.h" 9 #include "android_webview/browser/gpu_memory_buffer_factory_impl.h"
10 #include "android_webview/browser/in_process_view_renderer.h" 10 #include "android_webview/browser/in_process_view_renderer.h"
11 #include "android_webview/browser/net_disk_cache_remover.h" 11 #include "android_webview/browser/net_disk_cache_remover.h"
12 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h" 12 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h"
13 #include "android_webview/common/aw_hit_test_data.h" 13 #include "android_webview/common/aw_hit_test_data.h"
14 #include "android_webview/native/aw_autofill_manager_delegate.h" 14 #include "android_webview/native/aw_autofill_manager_delegate.h"
15 #include "android_webview/native/aw_browser_dependency_factory.h" 15 #include "android_webview/native/aw_browser_dependency_factory.h"
16 #include "android_webview/native/aw_contents_client_bridge.h" 16 #include "android_webview/native/aw_contents_client_bridge.h"
17 #include "android_webview/native/aw_contents_io_thread_client_impl.h" 17 #include "android_webview/native/aw_contents_io_thread_client_impl.h"
18 #include "android_webview/native/aw_picture.h" 18 #include "android_webview/native/aw_picture.h"
19 #include "android_webview/native/aw_web_contents_delegate.h" 19 #include "android_webview/native/aw_web_contents_delegate.h"
20 #include "android_webview/native/java_browser_view_renderer_helper.h" 20 #include "android_webview/native/java_browser_view_renderer_helper.h"
21 #include "android_webview/native/state_serializer.h" 21 #include "android_webview/native/state_serializer.h"
22 #include "android_webview/public/browser/draw_gl.h" 22 #include "android_webview/public/browser/draw_gl.h"
23 #include "base/android/jni_android.h" 23 #include "base/android/jni_android.h"
24 #include "base/android/jni_array.h" 24 #include "base/android/jni_array.h"
25 #include "base/android/jni_string.h" 25 #include "base/android/jni_string.h"
26 #include "base/android/scoped_java_ref.h" 26 #include "base/android/scoped_java_ref.h"
27 #include "base/atomicops.h" 27 #include "base/atomicops.h"
28 #include "base/bind.h" 28 #include "base/bind.h"
29 #include "base/callback.h" 29 #include "base/callback.h"
30 #include "base/memory/memory_pressure_listener.h"
30 #include "base/message_loop/message_loop.h" 31 #include "base/message_loop/message_loop.h"
31 #include "base/pickle.h" 32 #include "base/pickle.h"
32 #include "base/strings/string16.h" 33 #include "base/strings/string16.h"
33 #include "base/supports_user_data.h" 34 #include "base/supports_user_data.h"
34 #include "components/autofill/content/browser/autofill_driver_impl.h" 35 #include "components/autofill/content/browser/autofill_driver_impl.h"
35 #include "components/autofill/core/browser/autofill_manager.h" 36 #include "components/autofill/core/browser/autofill_manager.h"
36 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 37 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
37 #include "components/navigation_interception/intercept_navigation_delegate.h" 38 #include "components/navigation_interception/intercept_navigation_delegate.h"
38 #include "content/public/browser/android/content_view_core.h" 39 #include "content/public/browser/android/content_view_core.h"
39 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1); 244 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1);
244 } 245 }
245 246
246 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { 247 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) {
247 DCHECK(web_contents_); 248 DCHECK(web_contents_);
248 return reinterpret_cast<jint>(web_contents_.get()); 249 return reinterpret_cast<jint>(web_contents_.get());
249 } 250 }
250 251
251 void AwContents::Destroy(JNIEnv* env, jobject obj) { 252 void AwContents::Destroy(JNIEnv* env, jobject obj) {
252 delete this; 253 delete this;
254
255 // When the last WebView is destroyed free all discardable memory allocated by
256 // Chromium, because the app process may continue to run for a long time
257 // without ever using another WebView.
258 if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) {
259 base::MemoryPressureListener::NotifyMemoryPressure(
260 base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
261 }
253 } 262 }
254 263
255 static jint Init(JNIEnv* env, jclass, jobject browser_context) { 264 static jint Init(JNIEnv* env, jclass, jobject browser_context) {
256 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather 265 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather
257 // than hard-code the default instance lookup here. 266 // than hard-code the default instance lookup here.
258 scoped_ptr<WebContents> web_contents(content::WebContents::Create( 267 scoped_ptr<WebContents> web_contents(content::WebContents::Create(
259 content::WebContents::CreateParams(AwBrowserContext::GetDefault()))); 268 content::WebContents::CreateParams(AwBrowserContext::GetDefault())));
260 // Return an 'uninitialized' instance; most work is deferred until the 269 // Return an 'uninitialized' instance; most work is deferred until the
261 // subsequent SetJavaPeers() call. 270 // subsequent SetJavaPeers() call.
262 return reinterpret_cast<jint>(new AwContents(web_contents.Pass())); 271 return reinterpret_cast<jint>(new AwContents(web_contents.Pass()));
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 browser_view_renderer_->EnableOnNewPicture(enabled); 805 browser_view_renderer_->EnableOnNewPicture(enabled);
797 } 806 }
798 807
799 void AwContents::SetJsOnlineProperty(JNIEnv* env, 808 void AwContents::SetJsOnlineProperty(JNIEnv* env,
800 jobject obj, 809 jobject obj,
801 jboolean network_up) { 810 jboolean network_up) {
802 render_view_host_ext_->SetJsOnlineProperty(network_up); 811 render_view_host_ext_->SetJsOnlineProperty(network_up);
803 } 812 }
804 813
805 } // namespace android_webview 814 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698