Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2176)

Unified Diff: chrome/browser/net/sqlite_persistent_cookie_store.cc

Issue 306032: Simplify threading in browser thread by making only ChromeThread deal with di... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: a few more simplifications Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/sqlite_persistent_cookie_store.cc
===================================================================
--- chrome/browser/net/sqlite_persistent_cookie_store.cc (revision 30037)
+++ chrome/browser/net/sqlite_persistent_cookie_store.cc (working copy)
@@ -14,6 +14,7 @@
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/thread.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/diagnostics/sqlite_diagnostics.h"
using base::Time;
@@ -25,9 +26,8 @@
public:
// The passed database pointer must be already-initialized. This object will
// take ownership.
- explicit Backend(sql::Connection* db, MessageLoop* loop)
+ explicit Backend(sql::Connection* db)
: db_(db),
- background_loop_(loop),
num_pending_(0) {
DCHECK(db_) << "Database must exist.";
}
@@ -87,7 +87,6 @@
void InternalBackgroundClose();
sql::Connection* db_;
- MessageLoop* background_loop_;
typedef std::list<PendingOperation*> PendingOperationsList;
PendingOperationsList pending_;
@@ -121,7 +120,7 @@
static const int kCommitIntervalMs = 30 * 1000;
// Commit right away if we have more than 512 outstanding operations.
static const size_t kCommitAfterBatchSize = 512;
- DCHECK(MessageLoop::current() != background_loop_);
+ DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::DB));
// We do a full copy of the cookie here, and hopefully just here.
scoped_ptr<PendingOperation> po(new PendingOperation(op, key, cc));
@@ -134,20 +133,20 @@
num_pending = ++num_pending_;
}
- // TODO(abarth): What if the DB thread is being destroyed on the UI thread?
if (num_pending == 1) {
// We've gotten our first entry for this batch, fire off the timer.
- background_loop_->PostDelayedTask(FROM_HERE,
+ ChromeThread::PostDelayedTask(
+ ChromeThread::DB, FROM_HERE,
NewRunnableMethod(this, &Backend::Commit), kCommitIntervalMs);
} else if (num_pending == kCommitAfterBatchSize) {
// We've reached a big enough batch, fire off a commit now.
- background_loop_->PostTask(FROM_HERE,
- NewRunnableMethod(this, &Backend::Commit));
+ ChromeThread::PostTask(
+ ChromeThread::DB, FROM_HERE, NewRunnableMethod(this, &Backend::Commit));
}
}
void SQLitePersistentCookieStore::Backend::Commit() {
- DCHECK(MessageLoop::current() == background_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB));
PendingOperationsList ops;
{
AutoLock locked(pending_lock_);
@@ -236,15 +235,15 @@
// pending commit timer that will be holding a reference on us, but if/when
// this fires we will already have been cleaned up and it will be ignored.
void SQLitePersistentCookieStore::Backend::Close() {
- DCHECK(MessageLoop::current() != background_loop_);
+ DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::DB));
// Must close the backend on the background thread.
- // TODO(abarth): What if the DB thread is being destroyed on the UI thread?
- background_loop_->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::DB, FROM_HERE,
NewRunnableMethod(this, &Backend::InternalBackgroundClose));
}
void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() {
- DCHECK(MessageLoop::current() == background_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB));
// Commit any pending operations
Commit();
@@ -252,12 +251,8 @@
db_ = NULL;
}
-SQLitePersistentCookieStore::SQLitePersistentCookieStore(
- const FilePath& path,
- MessageLoop* background_loop)
- : path_(path),
- background_loop_(background_loop) {
- DCHECK(background_loop) << "SQLitePersistentCookieStore needs a MessageLoop";
+SQLitePersistentCookieStore::SQLitePersistentCookieStore(const FilePath& path)
+ : path_(path) {
}
SQLitePersistentCookieStore::~SQLitePersistentCookieStore() {
@@ -353,7 +348,7 @@
}
// Create the backend, this will take ownership of the db pointer.
- backend_ = new Backend(db.release(), background_loop_);
+ backend_ = new Backend(db.release());
return true;
}

Powered by Google App Engine
This is Rietveld 408576698