diff options
author | Steve Block <steveblock@google.com> | 2011-10-13 11:41:07 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-10-13 13:42:07 +0100 |
commit | 47f5154a4217fb3626326224fc1c7d3c9918dd09 (patch) | |
tree | d52aeb521fceb736f884ea3bc4c724e15dca3d30 /chrome | |
parent | d0a07ba49f88f1e331ac5fd80f30c81d975ebd12 (diff) | |
download | external_chromium-47f5154a4217fb3626326224fc1c7d3c9918dd09.zip external_chromium-47f5154a4217fb3626326224fc1c7d3c9918dd09.tar.gz external_chromium-47f5154a4217fb3626326224fc1c7d3c9918dd09.tar.bz2 |
Fix SQLitePersistentCookieStore's getDbThread() to be threadsafe
Bug: 5244039
Change-Id: I2d4f66b2f5e64c2cab247574cdfd8fa2d707cad8
Diffstat (limited to 'chrome')
-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 |