diff options
author | Steve Block <steveblock@google.com> | 2011-10-14 09:26:56 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-10-14 09:26:56 -0700 |
commit | 9914abdf90c42a1729fcf3113a1150a928945f37 (patch) | |
tree | cba16b98cea0298f720d5730bc0c465765f85d91 | |
parent | 68b7deaf18571a90d1abfe7e1247e16cfa72df48 (diff) | |
parent | 8d1e40fa83064d70b192f1b5aed95b8fc24e4cac (diff) | |
download | external_chromium-9914abdf90c42a1729fcf3113a1150a928945f37.zip external_chromium-9914abdf90c42a1729fcf3113a1150a928945f37.tar.gz external_chromium-9914abdf90c42a1729fcf3113a1150a928945f37.tar.bz2 |
am 8d1e40fa: am c0c5e0fc: Fix SQLitePersistentCookieStore\'s getDbThread() to be threadsafe
* commit '8d1e40fa83064d70b192f1b5aed95b8fc24e4cac':
Fix SQLitePersistentCookieStore's getDbThread() to be threadsafe
-rw-r--r-- | chrome/browser/net/sqlite_persistent_cookie_store.cc | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.cc b/chrome/browser/net/sqlite_persistent_cookie_store.cc index af9e753..57f646e 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store.cc +++ b/chrome/browser/net/sqlite_persistent_cookie_store.cc @@ -12,6 +12,9 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/file_util.h" +#ifdef ANDROID +#include "base/lazy_instance.h" +#endif #include "base/logging.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -26,26 +29,37 @@ #include "googleurl/src/gurl.h" #ifdef ANDROID -base::Thread* getDbThread() -{ - static base::Thread* dbThread = NULL; - if (dbThread && dbThread->IsRunning()) - return dbThread; +namespace { + +// 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()); - if (!dbThread) - dbThread = new base::Thread("db"); + // FIXME: We should probably be using LazyInstance here. + static base::Thread* db_thread = NULL; - if (!dbThread) + 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 (!dbThread->StartWithOptions(options)) { - delete dbThread; - dbThread = NULL; + if (!db_thread->StartWithOptions(options)) { + delete db_thread; + db_thread = NULL; } - return dbThread; + return db_thread; } + +} // namespace #endif using base::Time; |