| OLD | NEW |
| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "android_webview/browser/aw_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
| 10 #include "android_webview/browser/aw_browser_main_parts.h" | 10 #include "android_webview/browser/aw_browser_main_parts.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 291 } |
| 292 | 292 |
| 293 AwContents::~AwContents() { | 293 AwContents::~AwContents() { |
| 294 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); | 294 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); |
| 295 web_contents_->RemoveUserData(kAwContentsUserDataKey); | 295 web_contents_->RemoveUserData(kAwContentsUserDataKey); |
| 296 if (find_helper_.get()) | 296 if (find_helper_.get()) |
| 297 find_helper_->SetListener(NULL); | 297 find_helper_->SetListener(NULL); |
| 298 if (icon_helper_.get()) | 298 if (icon_helper_.get()) |
| 299 icon_helper_->SetListener(NULL); | 299 icon_helper_->SetListener(NULL); |
| 300 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1); | 300 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1); |
| 301 // When the last WebView is destroyed free all discardable memory allocated by |
| 302 // Chromium, because the app process may continue to run for a long time |
| 303 // without ever using another WebView. |
| 304 if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) { |
| 305 base::MemoryPressureListener::NotifyMemoryPressure( |
| 306 base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL); |
| 307 } |
| 301 } | 308 } |
| 302 | 309 |
| 303 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { | 310 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { |
| 304 DCHECK(web_contents_); | 311 DCHECK(web_contents_); |
| 305 return reinterpret_cast<jint>(web_contents_.get()); | 312 return reinterpret_cast<jint>(web_contents_.get()); |
| 306 } | 313 } |
| 307 | 314 |
| 308 void AwContents::Destroy(JNIEnv* env, jobject obj) { | 315 void AwContents::Destroy(JNIEnv* env, jobject obj) { |
| 309 delete this; | 316 java_ref_.reset(); |
| 310 | 317 // We do not delete AwContents immediately. Some applications try to delete |
| 311 // When the last WebView is destroyed free all discardable memory allocated by | 318 // Webview in ShouldOverrideUrlLoading callback, which is a sync IPC from |
| 312 // Chromium, because the app process may continue to run for a long time | 319 // Webkit. |
| 313 // without ever using another WebView. | 320 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 314 if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) { | |
| 315 base::MemoryPressureListener::NotifyMemoryPressure( | |
| 316 base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL); | |
| 317 } | |
| 318 } | 321 } |
| 319 | 322 |
| 320 static jint Init(JNIEnv* env, jclass, jobject browser_context) { | 323 static jint Init(JNIEnv* env, jclass, jobject browser_context) { |
| 321 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather | 324 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather |
| 322 // than hard-code the default instance lookup here. | 325 // than hard-code the default instance lookup here. |
| 323 scoped_ptr<WebContents> web_contents(content::WebContents::Create( | 326 scoped_ptr<WebContents> web_contents(content::WebContents::Create( |
| 324 content::WebContents::CreateParams(AwBrowserContext::GetDefault()))); | 327 content::WebContents::CreateParams(AwBrowserContext::GetDefault()))); |
| 325 // Return an 'uninitialized' instance; most work is deferred until the | 328 // Return an 'uninitialized' instance; most work is deferred until the |
| 326 // subsequent SetJavaPeers() call. | 329 // subsequent SetJavaPeers() call. |
| 327 return reinterpret_cast<jint>(new AwContents(web_contents.Pass())); | 330 return reinterpret_cast<jint>(new AwContents(web_contents.Pass())); |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 | 917 |
| 915 void AwContents::TrimMemory(JNIEnv* env, jobject obj, jint level) { | 918 void AwContents::TrimMemory(JNIEnv* env, jobject obj, jint level) { |
| 916 browser_view_renderer_->TrimMemory(level); | 919 browser_view_renderer_->TrimMemory(level); |
| 917 } | 920 } |
| 918 | 921 |
| 919 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) { | 922 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) { |
| 920 g_should_download_favicons = true; | 923 g_should_download_favicons = true; |
| 921 } | 924 } |
| 922 | 925 |
| 923 } // namespace android_webview | 926 } // namespace android_webview |
| OLD | NEW |