| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 transport_security_state_->SetDelegate(this); | 299 transport_security_state_->SetDelegate(this); |
| 300 | 300 |
| 301 base::PostTaskAndReplyWithResult( | 301 base::PostTaskAndReplyWithResult( |
| 302 background_runner_.get(), FROM_HERE, | 302 background_runner_.get(), FROM_HERE, |
| 303 base::Bind(&LoadState, writer_.path()), | 303 base::Bind(&LoadState, writer_.path()), |
| 304 base::Bind(&TransportSecurityPersister::CompleteLoad, | 304 base::Bind(&TransportSecurityPersister::CompleteLoad, |
| 305 weak_ptr_factory_.GetWeakPtr())); | 305 weak_ptr_factory_.GetWeakPtr())); |
| 306 } | 306 } |
| 307 | 307 |
| 308 TransportSecurityPersister::~TransportSecurityPersister() { | 308 TransportSecurityPersister::~TransportSecurityPersister() { |
| 309 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); | 309 DCHECK(foreground_runner_->RunsTasksInCurrentSequence()); |
| 310 | 310 |
| 311 if (writer_.HasPendingWrite()) | 311 if (writer_.HasPendingWrite()) |
| 312 writer_.DoScheduledWrite(); | 312 writer_.DoScheduledWrite(); |
| 313 | 313 |
| 314 transport_security_state_->SetDelegate(NULL); | 314 transport_security_state_->SetDelegate(NULL); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void TransportSecurityPersister::StateIsDirty(TransportSecurityState* state) { | 317 void TransportSecurityPersister::StateIsDirty(TransportSecurityState* state) { |
| 318 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); | 318 DCHECK(foreground_runner_->RunsTasksInCurrentSequence()); |
| 319 DCHECK_EQ(transport_security_state_, state); | 319 DCHECK_EQ(transport_security_state_, state); |
| 320 | 320 |
| 321 if (!readonly_) | 321 if (!readonly_) |
| 322 writer_.ScheduleWrite(this); | 322 writer_.ScheduleWrite(this); |
| 323 } | 323 } |
| 324 | 324 |
| 325 bool TransportSecurityPersister::SerializeData(std::string* output) { | 325 bool TransportSecurityPersister::SerializeData(std::string* output) { |
| 326 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); | 326 DCHECK(foreground_runner_->RunsTasksInCurrentSequence()); |
| 327 | 327 |
| 328 base::DictionaryValue toplevel; | 328 base::DictionaryValue toplevel; |
| 329 | 329 |
| 330 // TODO(davidben): Fix the serialization format by splitting the on-disk | 330 // TODO(davidben): Fix the serialization format by splitting the on-disk |
| 331 // representation of the STS and PKP states. https://crbug.com/470295. | 331 // representation of the STS and PKP states. https://crbug.com/470295. |
| 332 SerializeSTSData(transport_security_state_, &toplevel); | 332 SerializeSTSData(transport_security_state_, &toplevel); |
| 333 SerializePKPData(transport_security_state_, &toplevel); | 333 SerializePKPData(transport_security_state_, &toplevel); |
| 334 SerializeExpectCTData(transport_security_state_, &toplevel); | 334 SerializeExpectCTData(transport_security_state_, &toplevel); |
| 335 | 335 |
| 336 base::JSONWriter::WriteWithOptions( | 336 base::JSONWriter::WriteWithOptions( |
| 337 toplevel, base::JSONWriter::OPTIONS_PRETTY_PRINT, output); | 337 toplevel, base::JSONWriter::OPTIONS_PRETTY_PRINT, output); |
| 338 return true; | 338 return true; |
| 339 } | 339 } |
| 340 | 340 |
| 341 bool TransportSecurityPersister::LoadEntries(const std::string& serialized, | 341 bool TransportSecurityPersister::LoadEntries(const std::string& serialized, |
| 342 bool* dirty) { | 342 bool* dirty) { |
| 343 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); | 343 DCHECK(foreground_runner_->RunsTasksInCurrentSequence()); |
| 344 | 344 |
| 345 transport_security_state_->ClearDynamicData(); | 345 transport_security_state_->ClearDynamicData(); |
| 346 return Deserialize(serialized, dirty, transport_security_state_); | 346 return Deserialize(serialized, dirty, transport_security_state_); |
| 347 } | 347 } |
| 348 | 348 |
| 349 // static | 349 // static |
| 350 bool TransportSecurityPersister::Deserialize(const std::string& serialized, | 350 bool TransportSecurityPersister::Deserialize(const std::string& serialized, |
| 351 bool* dirty, | 351 bool* dirty, |
| 352 TransportSecurityState* state) { | 352 TransportSecurityState* state) { |
| 353 std::unique_ptr<base::Value> value = base::JSONReader::Read(serialized); | 353 std::unique_ptr<base::Value> value = base::JSONReader::Read(serialized); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 state->AddOrUpdateEnabledPKPHosts(hashed, pkp_state); | 484 state->AddOrUpdateEnabledPKPHosts(hashed, pkp_state); |
| 485 if (has_expect_ct) | 485 if (has_expect_ct) |
| 486 state->AddOrUpdateEnabledExpectCTHosts(hashed, expect_ct_state); | 486 state->AddOrUpdateEnabledExpectCTHosts(hashed, expect_ct_state); |
| 487 } | 487 } |
| 488 | 488 |
| 489 *dirty = dirtied; | 489 *dirty = dirtied; |
| 490 return true; | 490 return true; |
| 491 } | 491 } |
| 492 | 492 |
| 493 void TransportSecurityPersister::CompleteLoad(const std::string& state) { | 493 void TransportSecurityPersister::CompleteLoad(const std::string& state) { |
| 494 DCHECK(foreground_runner_->RunsTasksOnCurrentThread()); | 494 DCHECK(foreground_runner_->RunsTasksInCurrentSequence()); |
| 495 | 495 |
| 496 if (state.empty()) | 496 if (state.empty()) |
| 497 return; | 497 return; |
| 498 | 498 |
| 499 bool dirty = false; | 499 bool dirty = false; |
| 500 if (!LoadEntries(state, &dirty)) { | 500 if (!LoadEntries(state, &dirty)) { |
| 501 LOG(ERROR) << "Failed to deserialize state: " << state; | 501 LOG(ERROR) << "Failed to deserialize state: " << state; |
| 502 return; | 502 return; |
| 503 } | 503 } |
| 504 if (dirty) | 504 if (dirty) |
| 505 StateIsDirty(transport_security_state_); | 505 StateIsDirty(transport_security_state_); |
| 506 } | 506 } |
| 507 | 507 |
| 508 } // namespace net | 508 } // namespace net |
| OLD | NEW |