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

Unified Diff: android_webview/native/aw_contents.cc

Issue 24228003: Upstream ShouldOverrideUrlLoading changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed code review Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/native/aw_contents.cc
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index 4bdcf7ee2662a29f596dde2c22969756fc4adf9e..5770a07537a6fe2743ab14eecfce29bfb1ba155f 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -298,6 +298,13 @@ AwContents::~AwContents() {
if (icon_helper_.get())
icon_helper_->SetListener(NULL);
base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1);
+ // When the last WebView is destroyed free all discardable memory allocated by
+ // Chromium, because the app process may continue to run for a long time
+ // without ever using another WebView.
+ if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) {
+ base::MemoryPressureListener::NotifyMemoryPressure(
+ base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
+ }
}
jint AwContents::GetWebContents(JNIEnv* env, jobject obj) {
@@ -306,15 +313,11 @@ jint AwContents::GetWebContents(JNIEnv* env, jobject obj) {
}
void AwContents::Destroy(JNIEnv* env, jobject obj) {
- delete this;
-
- // When the last WebView is destroyed free all discardable memory allocated by
- // Chromium, because the app process may continue to run for a long time
- // without ever using another WebView.
- if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) {
- base::MemoryPressureListener::NotifyMemoryPressure(
- base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
- }
+ java_ref_.reset();
+ // We do not delete AwContents immediately. Some applications try to delete
+ // Webview in ShouldOverrideUrlLoading callback, which is a sync IPC from
+ // Webkit.
+ BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
}
static jint Init(JNIEnv* env, jclass, jobject browser_context) {

Powered by Google App Engine
This is Rietveld 408576698