OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/transport_security_persister.h" | 5 #include "net/http/transport_security_persister.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 | 88 |
89 } // namespace | 89 } // namespace |
90 | 90 |
91 TransportSecurityPersister::TransportSecurityPersister( | 91 TransportSecurityPersister::TransportSecurityPersister( |
92 TransportSecurityState* state, | 92 TransportSecurityState* state, |
93 const base::FilePath& profile_path, | 93 const base::FilePath& profile_path, |
94 const scoped_refptr<base::SequencedTaskRunner>& background_runner, | 94 const scoped_refptr<base::SequencedTaskRunner>& background_runner, |
95 bool readonly) | 95 bool readonly) |
96 : transport_security_state_(state), | 96 : transport_security_state_(state), |
97 writer_(profile_path.AppendASCII("TransportSecurity"), background_runner), | 97 writer_(new base::ImportantFileWriterImpl( |
| 98 profile_path.AppendASCII("TransportSecurity"), |
| 99 background_runner)), |
98 foreground_runner_(base::MessageLoop::current()->message_loop_proxy()), | 100 foreground_runner_(base::MessageLoop::current()->message_loop_proxy()), |
99 background_runner_(background_runner), | 101 background_runner_(background_runner), |
100 readonly_(readonly), | 102 readonly_(readonly), |
101 weak_ptr_factory_(this) { | 103 weak_ptr_factory_(this) { |
102 transport_security_state_->SetDelegate(this); | 104 transport_security_state_->SetDelegate(this); |
103 | 105 |
104 base::PostTaskAndReplyWithResult( | 106 base::PostTaskAndReplyWithResult( |
105 background_runner_.get(), FROM_HERE, | 107 background_runner_.get(), FROM_HERE, |
106 base::Bind(&LoadState, writer_.path()), | 108 base::Bind(&LoadState, writer_->path()), |
107 base::Bind(&TransportSecurityPersister::CompleteLoad, | 109 base::Bind(&TransportSecurityPersister::CompleteLoad, |
108 weak_ptr_factory_.GetWeakPtr())); | 110 weak_ptr_factory_.GetWeakPtr())); |
109 } | 111 } |
110 | 112 |
111 TransportSecurityPersister::~TransportSecurityPersister() { | 113 TransportSecurityPersister::~TransportSecurityPersister() { |
112 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); | 114 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); |
113 | 115 |
114 if (writer_.HasPendingWrite()) | 116 if (writer_->HasPendingWrite()) |
115 writer_.DoScheduledWrite(); | 117 writer_->DoScheduledWrite(); |
116 | 118 |
117 transport_security_state_->SetDelegate(NULL); | 119 transport_security_state_->SetDelegate(NULL); |
118 } | 120 } |
119 | 121 |
120 void TransportSecurityPersister::StateIsDirty( | 122 void TransportSecurityPersister::StateIsDirty( |
121 TransportSecurityState* state) { | 123 TransportSecurityState* state) { |
122 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); | 124 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); |
123 DCHECK_EQ(transport_security_state_, state); | 125 DCHECK_EQ(transport_security_state_, state); |
124 | 126 |
125 if (!readonly_) | 127 if (!readonly_) |
126 writer_.ScheduleWrite(this); | 128 writer_->ScheduleWrite(this); |
127 } | 129 } |
128 | 130 |
129 bool TransportSecurityPersister::SerializeData(std::string* output) { | 131 bool TransportSecurityPersister::SerializeData(std::string* output) { |
130 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); | 132 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); |
131 | 133 |
132 base::DictionaryValue toplevel; | 134 base::DictionaryValue toplevel; |
133 base::Time now = base::Time::Now(); | 135 base::Time now = base::Time::Now(); |
134 TransportSecurityState::Iterator state(*transport_security_state_); | 136 TransportSecurityState::Iterator state(*transport_security_state_); |
135 for (; state.HasNext(); state.Advance()) { | 137 for (; state.HasNext(); state.Advance()) { |
136 const std::string& hostname = state.hostname(); | 138 const std::string& hostname = state.hostname(); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 bool dirty = false; | 314 bool dirty = false; |
313 if (!LoadEntries(state, &dirty)) { | 315 if (!LoadEntries(state, &dirty)) { |
314 LOG(ERROR) << "Failed to deserialize state: " << state; | 316 LOG(ERROR) << "Failed to deserialize state: " << state; |
315 return; | 317 return; |
316 } | 318 } |
317 if (dirty) | 319 if (dirty) |
318 StateIsDirty(transport_security_state_); | 320 StateIsDirty(transport_security_state_); |
319 } | 321 } |
320 | 322 |
321 } // namespace net | 323 } // namespace net |
OLD | NEW |