summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-10-21 17:48:24 +0100
committerKristian Monsen <kristianm@google.com>2011-10-24 12:17:24 +0100
commit7d2c383403f05ced9ca2ac2389b4c3747688d335 (patch)
tree35b37451e352cb766bc3dd33865a29034a72d058 /chrome
parent9fb7297dd54aca7ba646ee27608529f33634a7b2 (diff)
downloadexternal_chromium-7d2c383403f05ced9ca2ac2389b4c3747688d335.zip
external_chromium-7d2c383403f05ced9ca2ac2389b4c3747688d335.tar.gz
external_chromium-7d2c383403f05ced9ca2ac2389b4c3747688d335.tar.bz2
fix for bug 5454586, fix up getDbThread()
Creating a LazyInstance and removing getter function, just using the object that should now be thread safe. Minor indenting change. Change-Id: I9deca3f10d96fdaf655a28b8f4d8db8efdc1803a
Diffstat (limited to 'chrome')
-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