diff options
-rw-r--r-- | chrome/browser/net/sqlite_persistent_cookie_store.cc | 29 | ||||
-rw-r--r-- | chrome/browser/net/sqlite_persistent_cookie_store.h | 4 | ||||
-rw-r--r-- | net/base/cookie_monster.cc | 9 | ||||
-rw-r--r-- | net/base/cookie_monster.h | 13 |
4 files changed, 55 insertions, 0 deletions
diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.cc b/chrome/browser/net/sqlite_persistent_cookie_store.cc index 9da5c76..9123ea2 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store.cc +++ b/chrome/browser/net/sqlite_persistent_cookie_store.cc @@ -68,6 +68,11 @@ class SQLitePersistentCookieStore::Backend // Batch a cookie deletion. void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc); +#if defined(ANDROID) + // Commit any pending operations. + void Flush(); +#endif + // Commit any pending operations and close the database. This must be called // before the object is destructed. void Close(); @@ -274,6 +279,23 @@ void SQLitePersistentCookieStore::Backend::Commit() { succeeded ? 0 : 1, 2); } +#if defined(ANDROID) +void SQLitePersistentCookieStore::Backend::Flush() { +// Keep this #ifdef when upstreaming to Chromium. +#if defined(ANDROID) + if (!getDbThread()) + return; + MessageLoop* loop = getDbThread()->message_loop(); + loop->PostTask(FROM_HERE, NewRunnableMethod(this, &Backend::Commit)); +#else + DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB)); + BrowserThread::PostTask( + BrowserThread::DB, FROM_HERE, + NewRunnableMethod(this, &Backend::Commit)); +#endif +} +#endif + // Fire off a close message to the background thread. We could still have a // pending commit timer that will be holding a reference on us, but if/when // this fires we will already have been cleaned up and it will be ignored. @@ -517,6 +539,13 @@ void SQLitePersistentCookieStore::DeleteCookie( backend_->DeleteCookie(cc); } +#if defined(ANDROID) +void SQLitePersistentCookieStore::Flush() { + if (backend_.get()) + backend_->Flush(); +} +#endif + // static void SQLitePersistentCookieStore::ClearLocalState( const FilePath& path) { diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.h b/chrome/browser/net/sqlite_persistent_cookie_store.h index d3bdfb7..4159e71 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store.h +++ b/chrome/browser/net/sqlite_persistent_cookie_store.h @@ -35,6 +35,10 @@ class SQLitePersistentCookieStore const net::CookieMonster::CanonicalCookie&); virtual void DeleteCookie(const net::CookieMonster::CanonicalCookie&); +#if defined(ANDROID) + virtual void Flush(); +#endif + static void ClearLocalState(const FilePath& path); private: diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc index c76573d..b1dba50 100644 --- a/net/base/cookie_monster.cc +++ b/net/base/cookie_monster.cc @@ -406,6 +406,15 @@ void CookieMonster::SetExpiryAndKeyScheme(ExpiryAndKeyScheme key_scheme) { expiry_and_key_scheme_ = key_scheme; } +#if defined(ANDROID) +void CookieMonster::FlushStore() { + AutoLock autolock(lock_); + InitIfNecessary(); + if (store_) + store_->Flush(); +} +#endif + // The system resolution is not high enough, so we can have multiple // set cookies that result in the same system time. When this happens, we // increment by one Time unit. Let's hope computers don't get too fast. diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h index f928d24..25563d2 100644 --- a/net/base/cookie_monster.h +++ b/net/base/cookie_monster.h @@ -213,6 +213,14 @@ class CookieMonster : public CookieStore { static void EnableFileScheme(); static bool enable_file_scheme_; +#if defined(ANDROID) + // Flush the backing store to disk. This is not synchronous, and is not + // guaranteed to do anything at all; it's just a hint that now is a good time + // to flush the store. (In Android, we call this when the browser is sent to + // the background.) + void FlushStore(); +#endif + private: ~CookieMonster(); @@ -692,6 +700,11 @@ class CookieMonster::PersistentCookieStore virtual void UpdateCookieAccessTime(const CanonicalCookie&) = 0; virtual void DeleteCookie(const CanonicalCookie&) = 0; +#if defined(ANDROID) + // Hint that this is a good time to start flushing the store (may be a no-op). + virtual void Flush() = 0; +#endif + protected: PersistentCookieStore() { } |