diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-14 07:46:26 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-14 07:46:26 +0000 |
commit | 1ffeb599fd56845978df5d3d45051cf6413843a8 (patch) | |
tree | 6e22873dbbe956527b782768e482cc39d1791632 /android_webview | |
parent | b0d2333cc16e93080a3b50c27f574c2a1c6ceb39 (diff) | |
download | chromium_src-1ffeb599fd56845978df5d3d45051cf6413843a8.zip chromium_src-1ffeb599fd56845978df5d3d45051cf6413843a8.tar.gz chromium_src-1ffeb599fd56845978df5d3d45051cf6413843a8.tar.bz2 |
Implement CookieManager.flushCookieStore
This can still be hit if an app calls CookieSyncManager.sync()
We can expose it as an explicit public method on CookieManager if needed in future
Also make all java methods non-static, for consistency.
BUG=
Review URL: https://chromiumcodereview.appspot.com/11553042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173126 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
3 files changed, 41 insertions, 11 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/CookieManager.java b/android_webview/java/src/org/chromium/android_webview/CookieManager.java index 8ed2b9e..a104c40 100644 --- a/android_webview/java/src/org/chromium/android_webview/CookieManager.java +++ b/android_webview/java/src/org/chromium/android_webview/CookieManager.java @@ -88,10 +88,14 @@ public final class CookieManager { nativeRemoveExpiredCookie(); } + public void flushCookieStore() { + nativeFlushCookieStore(); + } + /** * Whether cookies are accepted for file scheme URLs. */ - public static boolean allowFileSchemeCookies() { + public boolean allowFileSchemeCookies() { return nativeAllowFileSchemeCookies(); } @@ -104,7 +108,7 @@ public final class CookieManager { * Note that calls to this method will have no effect if made after a WebView or CookieManager * instance has been created. */ - public static void setAcceptFileSchemeCookies(boolean accept) { + public void setAcceptFileSchemeCookies(boolean accept) { nativeSetAcceptFileSchemeCookies(accept); } @@ -117,9 +121,10 @@ public final class CookieManager { private native void nativeRemoveSessionCookie(); private native void nativeRemoveAllCookie(); private native void nativeRemoveExpiredCookie(); + private native void nativeFlushCookieStore(); private native boolean nativeHasCookies(); - static native boolean nativeAllowFileSchemeCookies(); - static native void nativeSetAcceptFileSchemeCookies(boolean accept); + private native boolean nativeAllowFileSchemeCookies(); + private native void nativeSetAcceptFileSchemeCookies(boolean accept); } diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/CookieManagerTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/CookieManagerTest.java index 7482bb7..65435dd 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/CookieManagerTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/CookieManagerTest.java @@ -51,11 +51,11 @@ public class CookieManagerTest extends AndroidWebViewTestBase { @SmallTest @Feature({"AndroidWebView", "Privacy"}) public void testAllowFileSchemeCookies() throws Throwable { - assertFalse(CookieManager.allowFileSchemeCookies()); - CookieManager.setAcceptFileSchemeCookies(true); - assertTrue(CookieManager.allowFileSchemeCookies()); - CookieManager.setAcceptFileSchemeCookies(false); - assertFalse(CookieManager.allowFileSchemeCookies()); + assertFalse(mCookieManager.allowFileSchemeCookies()); + mCookieManager.setAcceptFileSchemeCookies(true); + assertTrue(mCookieManager.allowFileSchemeCookies()); + mCookieManager.setAcceptFileSchemeCookies(false); + assertFalse(mCookieManager.allowFileSchemeCookies()); } @MediumTest @@ -152,6 +152,7 @@ public class CookieManagerTest extends AndroidWebViewTestBase { // first there should be no cookie stored mCookieManager.removeAllCookie(); + mCookieManager.flushCookieStore(); assertFalse(mCookieManager.hasCookies()); String url = "http://www.example.com"; diff --git a/android_webview/native/cookie_manager.cc b/android_webview/native/cookie_manager.cc index 05cfb5f..cbc98ef 100644 --- a/android_webview/native/cookie_manager.cc +++ b/android_webview/native/cookie_manager.cc @@ -57,6 +57,7 @@ class CookieManager { void RemoveSessionCookie(); void RemoveAllCookie(); void RemoveExpiredCookie(); + void FlushCookieStore(); bool HasCookies(); bool AllowFileSchemeCookies(); void SetAcceptFileSchemeCookies(bool accept); @@ -89,6 +90,8 @@ class CookieManager { void RemoveAllCookieAsyncHelper(base::WaitableEvent* completion); void RemoveCookiesCompleted(int num_deleted); + void FlushCookieStoreAsyncHelper(base::WaitableEvent* completion); + void HasCookiesAsyncHelper(bool* result, base::WaitableEvent* completion); void HasCookiesCompleted(base::WaitableEvent* completion, @@ -241,6 +244,17 @@ void CookieManager::RemoveExpiredCookie() { HasCookies(); } +void CookieManager::FlushCookieStoreAsyncHelper( + base::WaitableEvent* completion) { + DCHECK(!completion); + cookie_monster_->FlushStore(base::Bind(&base::DoNothing)); +} + +void CookieManager::FlushCookieStore() { + ExecCookieTask(base::Bind(&CookieManager::FlushCookieStoreAsyncHelper, + base::Unretained(this)), false); +} + bool CookieManager::HasCookies() { bool has_cookies; ExecCookieTask(base::Bind(&CookieManager::HasCookiesAsyncHelper, @@ -271,6 +285,12 @@ bool CookieManager::AllowFileSchemeCookies() { } void CookieManager::SetAcceptFileSchemeCookies(bool accept) { + // The docs on CookieManager base class state the API must not be called after + // creating a CookieManager instance (which contradicts its own internal + // implementation) but this code does rely on the essence of that comment, as + // the monster will DCHECK here if it has already been lazy initialized (i.e. + // if cookies have been read or written from the store). If that turns out to + // be a problemin future, it looks like it maybe possible to relax the DCHECK. cookie_monster_->SetEnableFileScheme(accept); } @@ -311,15 +331,19 @@ static void RemoveExpiredCookie(JNIEnv* env, jobject obj) { CookieManager::GetInstance()->RemoveExpiredCookie(); } +static void FlushCookieStore(JNIEnv* env, jobject obj) { + CookieManager::GetInstance()->FlushCookieStore(); +} + static jboolean HasCookies(JNIEnv* env, jobject obj) { return CookieManager::GetInstance()->HasCookies(); } -static jboolean AllowFileSchemeCookies(JNIEnv* env, jclass obj) { +static jboolean AllowFileSchemeCookies(JNIEnv* env, jobject obj) { return CookieManager::GetInstance()->AllowFileSchemeCookies(); } -static void SetAcceptFileSchemeCookies(JNIEnv* env, jclass obj, +static void SetAcceptFileSchemeCookies(JNIEnv* env, jobject obj, jboolean accept) { return CookieManager::GetInstance()->SetAcceptFileSchemeCookies(accept); } |