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

Unified Diff: chrome/browser/transport_security_persister.cc

Issue 7966005: Move TransportSecurityPersister completely to IO thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 9 years, 3 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/transport_security_persister.cc
diff --git a/chrome/browser/transport_security_persister.cc b/chrome/browser/transport_security_persister.cc
index 59f093a31451cf0f10885359808bde497721f94e..f7a49128dfaae5897119d94c7ebcf473015d7590 100644
--- a/chrome/browser/transport_security_persister.cc
+++ b/chrome/browser/transport_security_persister.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/transport_security_persister.h"
+#include "base/bind.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/message_loop.h"
@@ -12,6 +13,41 @@
#include "content/browser/browser_thread.h"
#include "net/base/transport_security_state.h"
+class TransportSecurityPersister::Loader {
+ public:
+ Loader(TransportSecurityPersister* persister, const FilePath& path)
+ : persister_(persister->AsWeakPtr()),
+ path_(path),
+ state_valid_(false) {
+ }
+
+ void Load() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ state_valid_ = file_util::ReadFileToString(path_, &state_);
+ }
+
+ void CompleteLoad() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ // Make sure we're deleted.
+ scoped_ptr<Loader> deleter(this);
+
+ if (!persister_ || !state_valid_)
+ return;
+ persister_->CompleteLoad(state_);
+ }
+
+ private:
+ base::WeakPtr<TransportSecurityPersister> persister_;
+
+ FilePath path_;
+
+ std::string state_;
+ bool state_valid_;
+
+ DISALLOW_COPY_AND_ASSIGN(Loader);
+};
+
TransportSecurityPersister::TransportSecurityPersister(
net::TransportSecurityState* state,
const FilePath& profile_path,
@@ -20,39 +56,26 @@ TransportSecurityPersister::TransportSecurityPersister(
writer_(profile_path.AppendASCII("TransportSecurity"),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)),
readonly_(readonly) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
transport_security_state_->SetDelegate(this);
+
+ Loader* loader = new Loader(this, writer_.path());
+ BrowserThread::PostTaskAndReply(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&Loader::Load, base::Unretained(loader)),
+ base::Bind(&Loader::CompleteLoad, base::Unretained(loader)));
}
TransportSecurityPersister::~TransportSecurityPersister() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
if (writer_.HasPendingWrite())
writer_.DoScheduledWrite();
transport_security_state_->SetDelegate(NULL);
}
-void TransportSecurityPersister::Init() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(this, &TransportSecurityPersister::Load));
-}
-
-void TransportSecurityPersister::Load() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-
- std::string state;
- if (!file_util::ReadFileToString(writer_.path(), &state))
- return;
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this,
- &TransportSecurityPersister::CompleteLoad,
- state));
-}
-
void TransportSecurityPersister::CompleteLoad(const std::string& state) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
@@ -75,5 +98,6 @@ void TransportSecurityPersister::StateIsDirty(
}
bool TransportSecurityPersister::SerializeData(std::string* data) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
return transport_security_state_->Serialise(data);
}

Powered by Google App Engine
This is Rietveld 408576698