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

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: . Created 7 years, 12 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 fb6ab57c3d61c8791ab7fc75de3cd50ec3719f72..2d7822df67241f294b08297dc08bd29c22795f83 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,9 @@ class SQLiteServerBoundCertStore::Backend
void SetForceKeepSessionState();
private:
+ bool LoadOnDBThread(
+ std::vector<net::DefaultServerBoundCertStore::ServerBoundCert*>* certs);
+
friend class base::RefCountedThreadSafe<SQLiteServerBoundCertStore::Backend>;
// You should call Close() before destructing this object.
@@ -155,15 +157,27 @@ 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;
+ scoped_ptr<ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert> >
+ certs(new ScopedVector<net::DefaultServerBoundCertStore::ServerBoundCert>(
+ ));
+ BrowserThread::PostTaskAndReply(
+ BrowserThread::DB, FROM_HERE,
+ base::Bind(base::IgnoreResult(&Backend::LoadOnDBThread), this,
+ &certs->get()),
+ base::Bind(loaded_callback, base::Passed(&certs)));
+}
+
+bool SQLiteServerBoundCertStore::Backend::LoadOnDBThread(
erikwright (departed) 2013/01/04 19:20:10 why keep the bool exit code? Also, consider simpl
mattm 2013/01/08 04:53:21 removed.
erikwright (departed) 2013/01/10 22:03:30 I see your point. I don't mind either way.
+ 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();
@@ -218,11 +232,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);
+ DVLOG(1) << "loaded " << certs->size() << " in " << load_time.InMilliseconds()
+ << " ms";
return true;
}
@@ -544,9 +561,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(

Powered by Google App Engine
This is Rietveld 408576698