summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-10-13 11:41:07 +0100
committerSteve Block <steveblock@google.com>2011-10-14 16:46:23 +0100
commitc0c5e0fca18f5a0912fdba1bd5c5ca2ad0c2693c (patch)
tree914c88c1e5c17dce631969dd4d427f0188bd7801 /chrome
parentdf5ec85c1f7d3b444e458a4652302aca23624cc1 (diff)
downloadexternal_chromium-c0c5e0fca18f5a0912fdba1bd5c5ca2ad0c2693c.zip
external_chromium-c0c5e0fca18f5a0912fdba1bd5c5ca2ad0c2693c.tar.gz
external_chromium-c0c5e0fca18f5a0912fdba1bd5c5ca2ad0c2693c.tar.bz2
Fix SQLitePersistentCookieStore's getDbThread() to be threadsafe
This is an updated version of https://android-git.corp.google.com/g/#/c/141899, which was rolled out, with the lock now static and moved to file scope to match Chromium style. Bug: 5244039 Change-Id: Ic6a6e949b2adc8cf433e6468c1f84ed449af09bc
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/net/sqlite_persistent_cookie_store.cc38
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;