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

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

Issue 11742037: Make ServerBoundCertStore interface async, move SQLiteServerBoundCertStore load onto DB thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix login_utils_browsertest Created 7 years, 11 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_server_bound_cert_store.cc
diff --git a/chrome/browser/net/sqlite_server_bound_cert_store.cc b/chrome/browser/net/sqlite_server_bound_cert_store.cc
index b85e939e7c66890a790421e2cfb5a33c6099b3f1..c4a004c3030cda10598390f93d2d05bf59790540 100644
--- a/chrome/browser/net/sqlite_server_bound_cert_store.cc
+++ b/chrome/browser/net/sqlite_server_bound_cert_store.cc
@@ -41,9 +41,8 @@ class SQLiteServerBoundCertStore::Backend
clear_on_exit_policy_(clear_on_exit_policy) {
}
- // Creates or load the SQLite database.
- bool Load(
- std::vector<net::DefaultServerBoundCertStore::ServerBoundCert*>* certs);
+ // Creates or loads the SQLite database.
+ void Load(const LoadedCallback& loaded_callback);
// Batch a server bound cert addition.
void AddServerBoundCert(
@@ -63,6 +62,10 @@ class SQLiteServerBoundCertStore::Backend
void SetForceKeepSessionState();
private:
+ void LoadOnDBThreadAndNotify(const LoadedCallback& loaded_callback);
+ void LoadOnDBThread(
+ std::vector<net::DefaultServerBoundCertStore::ServerBoundCert*>* certs);
+
friend class base::RefCountedThreadSafe<SQLiteServerBoundCertStore::Backend>;
// You should call Close() before destructing this object.
@@ -155,15 +158,36 @@ bool InitTable(sql::Connection* db) {
} // namespace
-bool SQLiteServerBoundCertStore::Backend::Load(
- std::vector<net::DefaultServerBoundCertStore::ServerBoundCert*>* certs) {
+void SQLiteServerBoundCertStore::Backend::Load(
+ const LoadedCallback& loaded_callback) {
// This function should be called only once per instance.
DCHECK(!db_.get());
- // TODO(paivanof@gmail.com): We do a lot of disk access in this function,
- // thus we do an exception to allow IO on the UI thread. This code will be
- // moved to the DB thread as part of http://crbug.com/89665.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
+ BrowserThread::PostTask(
+ BrowserThread::DB, FROM_HERE,
+ base::Bind(&Backend::LoadOnDBThreadAndNotify, this, loaded_callback));
+}
+
+void SQLiteServerBoundCertStore::Backend::LoadOnDBThreadAndNotify(
+ const LoadedCallback& loaded_callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ scoped_ptr<ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> >
+ certs(new ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert>(
+ ));
+
+ LoadOnDBThread(&certs->get());
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(loaded_callback, base::Passed(&certs)));
+}
+
+void SQLiteServerBoundCertStore::Backend::LoadOnDBThread(
+ std::vector<net::DefaultServerBoundCertStore::ServerBoundCert*>* certs) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+
+ // This method should be called only once per instance.
+ DCHECK(!db_.get());
base::TimeTicks start = base::TimeTicks::Now();
@@ -171,7 +195,7 @@ bool SQLiteServerBoundCertStore::Backend::Load(
// from it.
const FilePath dir = path_.DirName();
if (!file_util::PathExists(dir) && !file_util::CreateDirectory(dir))
- return false;
+ return;
int64 db_size = 0;
if (file_util::GetFileSize(path_, &db_size))
@@ -181,13 +205,13 @@ bool SQLiteServerBoundCertStore::Backend::Load(
if (!db_->Open(path_)) {
NOTREACHED() << "Unable to open cert DB.";
db_.reset();
- return false;
+ return;
}
if (!EnsureDatabaseVersion() || !InitTable(db_.get())) {
NOTREACHED() << "Unable to open cert DB.";
db_.reset();
- return false;
+ return;
}
db_->Preload();
@@ -198,7 +222,7 @@ bool SQLiteServerBoundCertStore::Backend::Load(
"creation_time FROM origin_bound_certs"));
if (!smt.is_valid()) {
db_.reset();
- return false;
+ return;
}
while (smt.Step()) {
@@ -218,12 +242,14 @@ bool SQLiteServerBoundCertStore::Backend::Load(
}
UMA_HISTOGRAM_COUNTS_10000("DomainBoundCerts.DBLoadedCount", certs->size());
+ base::TimeDelta load_time = base::TimeTicks::Now() - start;
UMA_HISTOGRAM_CUSTOM_TIMES("DomainBoundCerts.DBLoadTime",
- base::TimeTicks::Now() - start,
+ load_time,
base::TimeDelta::FromMilliseconds(1),
base::TimeDelta::FromMinutes(1),
50);
- return true;
+ DVLOG(1) << "loaded " << certs->size() << " in " << load_time.InMilliseconds()
+ << " ms";
}
bool SQLiteServerBoundCertStore::Backend::EnsureDatabaseVersion() {
@@ -544,9 +570,9 @@ SQLiteServerBoundCertStore::SQLiteServerBoundCertStore(
: backend_(new Backend(path, clear_on_exit_policy)) {
}
-bool SQLiteServerBoundCertStore::Load(
- std::vector<net::DefaultServerBoundCertStore::ServerBoundCert*>* certs) {
- return backend_->Load(certs);
+void SQLiteServerBoundCertStore::Load(
+ const LoadedCallback& loaded_callback) {
+ backend_->Load(loaded_callback);
}
void SQLiteServerBoundCertStore::AddServerBoundCert(
« no previous file with comments | « chrome/browser/net/sqlite_server_bound_cert_store.h ('k') | chrome/browser/net/sqlite_server_bound_cert_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698