From fe1e675b8dc5e6fed7082f23c08fd11fda376825 Mon Sep 17 00:00:00 2001 From: "cjhopman@chromium.org" Date: Wed, 13 Nov 2013 21:11:54 +0000 Subject: Make thread checking in DomDistillerDatabase::LevelDB more flexible This replaces the ThreadChecker with a ThreadCollisionWarner. The LevelDB does not actually need to be run on a single thread, instead it just needs its function calls to be sequenced in some way. Review URL: https://codereview.chromium.org/70643002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234903 0039d316-1c4b-4281-b951-d872f2087c98 --- components/dom_distiller/core/dom_distiller_database.cc | 12 +++++------- components/dom_distiller/core/dom_distiller_database.h | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'components/dom_distiller') diff --git a/components/dom_distiller/core/dom_distiller_database.cc b/components/dom_distiller/core/dom_distiller_database.cc index cda79fb..5cd4c128 100644 --- a/components/dom_distiller/core/dom_distiller_database.cc +++ b/components/dom_distiller/core/dom_distiller_database.cc @@ -23,16 +23,14 @@ using base::SequencedTaskRunner; namespace dom_distiller { -DomDistillerDatabase::LevelDB::LevelDB() { - thread_checker_.DetachFromThread(); -} +DomDistillerDatabase::LevelDB::LevelDB() {} DomDistillerDatabase::LevelDB::~LevelDB() { - DCHECK(thread_checker_.CalledOnValidThread()); + DFAKE_SCOPED_LOCK(thread_checker_); } bool DomDistillerDatabase::LevelDB::Init(const base::FilePath& database_dir) { - DCHECK(thread_checker_.CalledOnValidThread()); + DFAKE_SCOPED_LOCK(thread_checker_); leveldb::Options options; options.create_if_missing = true; @@ -59,7 +57,7 @@ bool DomDistillerDatabase::LevelDB::Init(const base::FilePath& database_dir) { } bool DomDistillerDatabase::LevelDB::Save(const EntryVector& entries) { - DCHECK(thread_checker_.CalledOnValidThread()); + DFAKE_SCOPED_LOCK(thread_checker_); leveldb::WriteBatch updates; for (EntryVector::const_iterator it = entries.begin(); it != entries.end(); @@ -80,7 +78,7 @@ bool DomDistillerDatabase::LevelDB::Save(const EntryVector& entries) { } bool DomDistillerDatabase::LevelDB::Load(EntryVector* entries) { - DCHECK(thread_checker_.CalledOnValidThread()); + DFAKE_SCOPED_LOCK(thread_checker_); leveldb::ReadOptions options; scoped_ptr db_iterator(db_->NewIterator(options)); diff --git a/components/dom_distiller/core/dom_distiller_database.h b/components/dom_distiller/core/dom_distiller_database.h index d50568b..731c2a8 100644 --- a/components/dom_distiller/core/dom_distiller_database.h +++ b/components/dom_distiller/core/dom_distiller_database.h @@ -15,6 +15,7 @@ #include "base/memory/scoped_vector.h" #include "base/memory/weak_ptr.h" #include "base/threading/thread_checker.h" +#include "base/threading/thread_collision_warner.h" #include "components/dom_distiller/core/article_entry.h" namespace base { @@ -81,7 +82,7 @@ class DomDistillerDatabase virtual bool Load(EntryVector* entries) OVERRIDE; private: - base::ThreadChecker thread_checker_; + DFAKE_MUTEX(thread_checker_); scoped_ptr db_; }; -- cgit v1.1