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

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
« no previous file with comments | « chrome/browser/transport_security_persister.h ('k') | chrome/test/base/testing_profile.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..21c3e2b6ef7643e1699f738beddd69cdf16404d6 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,42 @@
#include "content/browser/browser_thread.h"
#include "net/base/transport_security_state.h"
+class TransportSecurityPersister::Loader {
+ public:
+ Loader(const base::WeakPtr<TransportSecurityPersister>& persister,
+ const FilePath& path)
+ : persister_(persister),
+ 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,
@@ -19,40 +56,28 @@ TransportSecurityPersister::TransportSecurityPersister(
: transport_security_state_(state),
writer_(profile_path.AppendASCII("TransportSecurity"),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)),
- readonly_(readonly) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ readonly_(readonly),
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
transport_security_state_->SetDelegate(this);
+
+ Loader* loader = new Loader(weak_ptr_factory_.GetWeakPtr(), 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 +100,6 @@ void TransportSecurityPersister::StateIsDirty(
}
bool TransportSecurityPersister::SerializeData(std::string* data) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
return transport_security_state_->Serialise(data);
}
« no previous file with comments | « chrome/browser/transport_security_persister.h ('k') | chrome/test/base/testing_profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698