summaryrefslogtreecommitdiffstats
path: root/chrome/browser/transport_security_persister.cc
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-14 00:16:15 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-14 00:16:15 +0000
commit4cc5a8747adf8327ba0df645237c1d5f52690caf (patch)
tree9b0fbabaa157fd1e8221d12b40451d4eee973d1f /chrome/browser/transport_security_persister.cc
parent3d66e35568b1ed073bbec5dd489997134c6a7d9f (diff)
downloadchromium_src-4cc5a8747adf8327ba0df645237c1d5f52690caf.zip
chromium_src-4cc5a8747adf8327ba0df645237c1d5f52690caf.tar.gz
chromium_src-4cc5a8747adf8327ba0df645237c1d5f52690caf.tar.bz2
Remove locks from StrictTransportSecurityState.
These locks can cause the IO thread to block on the FILE thread writing to disk, which is bad news bears. BUG=21518 TEST=No behavior change. Review URL: http://codereview.chromium.org/904005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41538 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/transport_security_persister.cc')
-rw-r--r--chrome/browser/transport_security_persister.cc65
1 files changed, 37 insertions, 28 deletions
diff --git a/chrome/browser/transport_security_persister.cc b/chrome/browser/transport_security_persister.cc
index a00dfb1..5ffaf80 100644
--- a/chrome/browser/transport_security_persister.cc
+++ b/chrome/browser/transport_security_persister.cc
@@ -13,7 +13,7 @@
#include "net/base/transport_security_state.h"
TransportSecurityPersister::TransportSecurityPersister()
- : state_is_dirty_(false) {
+ : ALLOW_THIS_IN_INITIALIZER_LIST(save_coalescer_(this)) {
}
TransportSecurityPersister::~TransportSecurityPersister() {
@@ -22,30 +22,37 @@ TransportSecurityPersister::~TransportSecurityPersister() {
void TransportSecurityPersister::Initialize(
net::TransportSecurityState* state, const FilePath& profile_path) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
transport_security_state_ = state;
state_file_ =
profile_path.Append(FILE_PATH_LITERAL("TransportSecurity"));
state->SetDelegate(this);
Task* task = NewRunnableMethod(this,
- &TransportSecurityPersister::LoadState);
+ &TransportSecurityPersister::Load);
ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE, task, 1000);
}
-void TransportSecurityPersister::LoadState() {
+void TransportSecurityPersister::Load() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
- bool dirty = false;
- {
- AutoLock locked_(lock_);
- std::string state;
- if (!file_util::ReadFileToString(state_file_, &state))
- return;
+ std::string state;
+ if (!file_util::ReadFileToString(state_file_, &state))
+ return;
+
+ ChromeThread::PostTask(ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this,
+ &TransportSecurityPersister::CompleteLoad,
+ state));
+}
- if (!transport_security_state_->Deserialise(state, &dirty)) {
- LOG(ERROR) << "Failed to deserialize state: " << state;
- return;
- }
+void TransportSecurityPersister::CompleteLoad(const std::string& state) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+
+ bool dirty = false;
+ if (!transport_security_state_->Deserialise(state, &dirty)) {
+ LOG(ERROR) << "Failed to deserialize state: " << state;
+ return;
}
if (dirty)
StateIsDirty(transport_security_state_);
@@ -53,30 +60,32 @@ void TransportSecurityPersister::LoadState() {
void TransportSecurityPersister::StateIsDirty(
net::TransportSecurityState* state) {
- // Runs on arbitary thread, may not block nor reenter
- // |transport_security_state_|.
- AutoLock locked_(lock_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(state == transport_security_state_);
- if (state_is_dirty_)
- return; // we already have a serialisation scheduled
+ if (!save_coalescer_.empty())
+ return;
- Task* task = NewRunnableMethod(this,
- &TransportSecurityPersister::SerialiseState);
- ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE, task, 1000);
- state_is_dirty_ = true;
+ Task* task = save_coalescer_.NewRunnableMethod(
+ &TransportSecurityPersister::Save);
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, task, 1000);
}
-void TransportSecurityPersister::SerialiseState() {
- AutoLock locked_(lock_);
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
-
- DCHECK(state_is_dirty_);
- state_is_dirty_ = false;
+void TransportSecurityPersister::Save() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
std::string state;
if (!transport_security_state_->Serialise(&state))
return;
+ ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,
+ NewRunnableMethod(this,
+ &TransportSecurityPersister::CompleteSave,
+ state));
+}
+
+void TransportSecurityPersister::CompleteSave(const std::string& state) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
+
file_util::WriteFile(state_file_, state.data(), state.size());
}