diff options
author | Steve Block <steveblock@google.com> | 2011-10-13 09:34:28 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-10-13 09:34:28 -0700 |
commit | 81e9d96faf52d54bbf90b3430e62576fc4fd89a2 (patch) | |
tree | d52aeb521fceb736f884ea3bc4c724e15dca3d30 | |
parent | 0d0bee23814d315ec074562514831106c5259e6b (diff) | |
parent | 47f5154a4217fb3626326224fc1c7d3c9918dd09 (diff) | |
download | external_chromium-81e9d96faf52d54bbf90b3430e62576fc4fd89a2.zip external_chromium-81e9d96faf52d54bbf90b3430e62576fc4fd89a2.tar.gz external_chromium-81e9d96faf52d54bbf90b3430e62576fc4fd89a2.tar.bz2 |
am 47f5154a: Fix SQLitePersistentCookieStore\'s getDbThread() to be threadsafe
* commit '47f5154a4217fb3626326224fc1c7d3c9918dd09':
Fix SQLitePersistentCookieStore's getDbThread() to be threadsafe
-rw-r--r-- | chrome/browser/net/sqlite_persistent_cookie_store.cc | 33 |
1 files changed, 21 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..35948ca 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,25 +29,31 @@ #include "googleurl/src/gurl.h" #ifdef ANDROID -base::Thread* getDbThread() -{ - static base::Thread* dbThread = NULL; - if (dbThread && dbThread->IsRunning()) - return dbThread; +// This class is used by CookieMonster, which is threadsafe, so this class must +// be threadsafe too. +base::Thread* getDbThread() { + base::LazyInstance<base::Lock> db_thread_lock(base::LINKER_INITIALIZED); + 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 (!dbThread) - dbThread = new base::Thread("db"); + if (!db_thread) + db_thread = new base::Thread("db"); - if (!dbThread) + 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; } #endif |