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 "chrome/browser/net/transport_security_persister.h" | 5 #include "chrome/browser/net/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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 197 |
198 toplevel.Set(HashedDomainToExternalString(hostname), serialized); | 198 toplevel.Set(HashedDomainToExternalString(hostname), serialized); |
199 } | 199 } |
200 | 200 |
201 base::JSONWriter::WriteWithOptions(&toplevel, | 201 base::JSONWriter::WriteWithOptions(&toplevel, |
202 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 202 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
203 output); | 203 output); |
204 return true; | 204 return true; |
205 } | 205 } |
206 | 206 |
207 bool TransportSecurityPersister::DeserializeFromCommandLine( | |
208 const std::string& serialized) { | |
209 // Purposefully ignore |dirty| because we do not want to persist entries | |
210 // deserialized in this way. | |
211 bool dirty; | |
212 return Deserialize(serialized, true, &dirty, transport_security_state_); | |
213 } | |
214 | |
215 bool TransportSecurityPersister::LoadEntries(const std::string& serialized, | 207 bool TransportSecurityPersister::LoadEntries(const std::string& serialized, |
216 bool* dirty) { | 208 bool* dirty) { |
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
218 | 210 |
219 transport_security_state_->ClearDynamicData(); | 211 transport_security_state_->ClearDynamicData(); |
220 return Deserialize(serialized, false, dirty, transport_security_state_); | 212 return Deserialize(serialized, dirty, transport_security_state_); |
221 } | 213 } |
222 | 214 |
223 // static | 215 // static |
224 bool TransportSecurityPersister::Deserialize(const std::string& serialized, | 216 bool TransportSecurityPersister::Deserialize(const std::string& serialized, |
225 bool forced, | |
226 bool* dirty, | 217 bool* dirty, |
227 TransportSecurityState* state) { | 218 TransportSecurityState* state) { |
228 scoped_ptr<Value> value(base::JSONReader::Read(serialized)); | 219 scoped_ptr<Value> value(base::JSONReader::Read(serialized)); |
229 DictionaryValue* dict_value = NULL; | 220 DictionaryValue* dict_value = NULL; |
230 if (!value.get() || !value->GetAsDictionary(&dict_value)) | 221 if (!value.get() || !value->GetAsDictionary(&dict_value)) |
231 return false; | 222 return false; |
232 | 223 |
233 const base::Time current_time(base::Time::Now()); | 224 const base::Time current_time(base::Time::Now()); |
234 bool dirtied = false; | 225 bool dirtied = false; |
235 | 226 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 dirtied = true; | 291 dirtied = true; |
301 continue; | 292 continue; |
302 } | 293 } |
303 | 294 |
304 std::string hashed = ExternalStringToHashedDomain(i.key()); | 295 std::string hashed = ExternalStringToHashedDomain(i.key()); |
305 if (hashed.empty()) { | 296 if (hashed.empty()) { |
306 dirtied = true; | 297 dirtied = true; |
307 continue; | 298 continue; |
308 } | 299 } |
309 | 300 |
310 if (forced) | 301 state->AddOrUpdateEnabledHosts(hashed, domain_state); |
311 state->AddOrUpdateForcedHosts(hashed, domain_state); | |
312 else | |
313 state->AddOrUpdateEnabledHosts(hashed, domain_state); | |
314 } | 302 } |
315 | 303 |
316 *dirty = dirtied; | 304 *dirty = dirtied; |
317 return true; | 305 return true; |
318 } | 306 } |
319 | 307 |
320 void TransportSecurityPersister::CompleteLoad(const std::string& state) { | 308 void TransportSecurityPersister::CompleteLoad(const std::string& state) { |
321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
322 | 310 |
323 bool dirty = false; | 311 bool dirty = false; |
324 if (!LoadEntries(state, &dirty)) { | 312 if (!LoadEntries(state, &dirty)) { |
325 LOG(ERROR) << "Failed to deserialize state: " << state; | 313 LOG(ERROR) << "Failed to deserialize state: " << state; |
326 return; | 314 return; |
327 } | 315 } |
328 if (dirty) | 316 if (dirty) |
329 StateIsDirty(transport_security_state_); | 317 StateIsDirty(transport_security_state_); |
330 } | 318 } |
OLD | NEW |