summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-10-25 10:29:56 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-10-25 10:29:56 -0700
commit3e233ada0c8478e05c8a262eb2d4a7939e3d0aeb (patch)
treeb04233f2e91a2dad7bfe301441f98e37c3f4e544
parentf97d22b88d9f81aed4cb5cfb3776b8df162ed2ae (diff)
parent92b6b8e6dd0ba578b9091f7826568fccab6d2cf9 (diff)
downloadexternal_chromium-3e233ada0c8478e05c8a262eb2d4a7939e3d0aeb.zip
external_chromium-3e233ada0c8478e05c8a262eb2d4a7939e3d0aeb.tar.gz
external_chromium-3e233ada0c8478e05c8a262eb2d4a7939e3d0aeb.tar.bz2
am 92b6b8e6: Merge "fix for bug 5454586, fix up getDbThread()"
* commit '92b6b8e6dd0ba578b9091f7826568fccab6d2cf9': fix for bug 5454586, fix up getDbThread()
-rw-r--r--chrome/browser/net/sqlite_persistent_cookie_store.cc55
1 files changed, 14 insertions, 41 deletions
diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.cc b/chrome/browser/net/sqlite_persistent_cookie_store.cc
index 57f646e..525b2ad 100644
--- a/chrome/browser/net/sqlite_persistent_cookie_store.cc
+++ b/chrome/browser/net/sqlite_persistent_cookie_store.cc
@@ -31,33 +31,17 @@
#ifdef ANDROID
namespace {
+class DbThread : public base::Thread {
+ public:
+ DbThread() : base::Thread("android-db") {
+ bool started = Start();
+ CHECK(started);
+ }
+};
+
// This class is used by CookieMonster, which is threadsafe, so this class must
// be threadsafe too.
-base::LazyInstance<base::Lock> db_thread_lock(base::LINKER_INITIALIZED);
-
-base::Thread* getDbThread() {
- base::AutoLock lock(*db_thread_lock.Pointer());
-
- // FIXME: We should probably be using LazyInstance here.
- static base::Thread* db_thread = NULL;
-
- if (db_thread && db_thread->IsRunning())
- return db_thread;
-
- if (!db_thread)
- db_thread = new base::Thread("db");
-
- if (!db_thread)
- return NULL;
-
- base::Thread::Options options;
- options.message_loop_type = MessageLoop::TYPE_DEFAULT;
- if (!db_thread->StartWithOptions(options)) {
- delete db_thread;
- db_thread = NULL;
- }
- return db_thread;
-}
+base::LazyInstance<DbThread> g_db_thread(base::LINKER_INITIALIZED);
} // namespace
#endif
@@ -409,9 +393,7 @@ void SQLitePersistentCookieStore::Backend::BatchOperation(
}
#ifdef ANDROID
- if (!getDbThread())
- return;
- MessageLoop* loop = getDbThread()->message_loop();
+ MessageLoop* loop = g_db_thread.Get().message_loop();
#endif
if (num_pending == 1) {
@@ -552,15 +534,9 @@ void SQLitePersistentCookieStore::Backend::Commit() {
void SQLitePersistentCookieStore::Backend::Flush(Task* completion_task) {
#if defined(ANDROID)
- if (!getDbThread()) {
- if (completion_task)
- MessageLoop::current()->PostTask(FROM_HERE, completion_task);
- return;
- }
-
- MessageLoop* loop = getDbThread()->message_loop();
- loop->PostTask(FROM_HERE, NewRunnableMethod(
- this, &Backend::Commit, completion_task));
+ MessageLoop* loop = g_db_thread.Get().message_loop();
+ loop->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &Backend::Commit, completion_task));
#else
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB));
BrowserThread::PostTask(
@@ -583,10 +559,7 @@ void SQLitePersistentCookieStore::Backend::Close() {
#endif
#ifdef ANDROID
- if (!getDbThread())
- return;
-
- MessageLoop* loop = getDbThread()->message_loop();
+ MessageLoop* loop = g_db_thread.Get().message_loop();
loop->PostTask(FROM_HERE,
NewRunnableMethod(this, &Backend::InternalBackgroundClose));
#else