OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/strict_transport_security_persister.h" | 5 #include "chrome/browser/strict_transport_security_persister.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
13 #include "net/base/strict_transport_security_state.h" | 13 #include "net/base/strict_transport_security_state.h" |
14 | 14 |
15 StrictTransportSecurityPersister::StrictTransportSecurityPersister( | 15 StrictTransportSecurityPersister::StrictTransportSecurityPersister() |
16 net::StrictTransportSecurityState* state, | 16 : state_is_dirty_(false) { |
17 const FilePath& profile_path) | 17 } |
18 : state_is_dirty_(false), | 18 |
19 strict_transport_security_state_(state), | 19 StrictTransportSecurityPersister::~StrictTransportSecurityPersister() { |
20 state_file_(profile_path.Append( | 20 strict_transport_security_state_->SetDelegate(NULL); |
21 FILE_PATH_LITERAL("StrictTransportSecurity"))) { | 21 } |
| 22 |
| 23 void StrictTransportSecurityPersister::Initialize( |
| 24 net::StrictTransportSecurityState* state, const FilePath& profile_path) { |
| 25 strict_transport_security_state_ = state; |
| 26 state_file_ = |
| 27 profile_path.Append(FILE_PATH_LITERAL("StrictTransportSecurity")); |
22 state->SetDelegate(this); | 28 state->SetDelegate(this); |
23 | 29 |
24 Task* task = NewRunnableMethod(this, | 30 Task* task = NewRunnableMethod(this, |
25 &StrictTransportSecurityPersister::LoadState); | 31 &StrictTransportSecurityPersister::LoadState); |
26 ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE, task, 1000); | 32 ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE, task, 1000); |
27 } | 33 } |
28 | 34 |
29 StrictTransportSecurityPersister::~StrictTransportSecurityPersister() { | |
30 strict_transport_security_state_->SetDelegate(NULL); | |
31 } | |
32 | |
33 void StrictTransportSecurityPersister::LoadState() { | 35 void StrictTransportSecurityPersister::LoadState() { |
34 AutoLock locked_(lock_); | 36 AutoLock locked_(lock_); |
35 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 37 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
36 | 38 |
37 std::string state; | 39 std::string state; |
38 if (!file_util::ReadFileToString(state_file_, &state)) | 40 if (!file_util::ReadFileToString(state_file_, &state)) |
39 return; | 41 return; |
40 | 42 |
41 strict_transport_security_state_->Deserialise(state); | 43 strict_transport_security_state_->Deserialise(state); |
42 } | 44 } |
(...skipping 20 matching lines...) Expand all Loading... |
63 | 65 |
64 DCHECK(state_is_dirty_); | 66 DCHECK(state_is_dirty_); |
65 state_is_dirty_ = false; | 67 state_is_dirty_ = false; |
66 | 68 |
67 std::string state; | 69 std::string state; |
68 if (!strict_transport_security_state_->Serialise(&state)) | 70 if (!strict_transport_security_state_->Serialise(&state)) |
69 return; | 71 return; |
70 | 72 |
71 file_util::WriteFile(state_file_, state.data(), state.size()); | 73 file_util::WriteFile(state_file_, state.data(), state.size()); |
72 } | 74 } |
OLD | NEW |