summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-10-25 08:56:23 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-25 08:56:23 -0700
commit92b6b8e6dd0ba578b9091f7826568fccab6d2cf9 (patch)
treeb04233f2e91a2dad7bfe301441f98e37c3f4e544
parentb54fbb0d9cf6451f1683823838b6c0d2b345ed4b (diff)
parent7d2c383403f05ced9ca2ac2389b4c3747688d335 (diff)
downloadexternal_chromium-92b6b8e6dd0ba578b9091f7826568fccab6d2cf9.zip
external_chromium-92b6b8e6dd0ba578b9091f7826568fccab6d2cf9.tar.gz
external_chromium-92b6b8e6dd0ba578b9091f7826568fccab6d2cf9.tar.bz2
Merge "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