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 // TransportSecurityState maintains an in memory database containing the | 5 // TransportSecurityState maintains an in memory database containing the |
6 // list of hosts that currently have transport security enabled. This | 6 // list of hosts that currently have transport security enabled. This |
7 // singleton object deals with writing that data out to disk as needed and | 7 // singleton object deals with writing that data out to disk as needed and |
8 // loading it at startup. | 8 // loading it at startup. |
9 | 9 |
10 // At startup we need to load the transport security state from the | 10 // At startup we need to load the transport security state from the |
(...skipping 19 matching lines...) Expand all Loading... | |
30 // copies the current state of the TransportSecurityState, serializes | 30 // copies the current state of the TransportSecurityState, serializes |
31 // and writes to disk. | 31 // and writes to disk. |
32 | 32 |
33 #ifndef CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ | 33 #ifndef CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ |
34 #define CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ | 34 #define CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ |
35 | 35 |
36 #include <string> | 36 #include <string> |
37 | 37 |
38 #include "base/files/file_path.h" | 38 #include "base/files/file_path.h" |
39 #include "base/files/important_file_writer.h" | 39 #include "base/files/important_file_writer.h" |
40 #include "base/memory/ref_counted.h" | |
40 #include "base/memory/weak_ptr.h" | 41 #include "base/memory/weak_ptr.h" |
41 #include "net/http/transport_security_state.h" | 42 #include "net/http/transport_security_state.h" |
42 | 43 |
44 namespace base { | |
45 class SequencedTaskRunner; | |
46 } | |
47 | |
43 // Reads and updates on-disk TransportSecurity state. | 48 // Reads and updates on-disk TransportSecurity state. |
44 // Must be created, used and destroyed only on the IO thread. | 49 // Must be created, used and destroyed only on the IO thread. |
battre
2013/11/05 11:54:36
Here you talk about IO thread while this gets some
Aaron Boodman
2013/11/06 21:57:06
Done.
| |
45 class TransportSecurityPersister | 50 class TransportSecurityPersister |
46 : public net::TransportSecurityState::Delegate, | 51 : public net::TransportSecurityState::Delegate, |
47 public base::ImportantFileWriter::DataSerializer { | 52 public base::ImportantFileWriter::DataSerializer { |
48 public: | 53 public: |
49 TransportSecurityPersister(net::TransportSecurityState* state, | 54 TransportSecurityPersister(net::TransportSecurityState* state, |
50 const base::FilePath& profile_path, | 55 const base::FilePath& profile_path, |
56 base::SequencedTaskRunner* file_task_runner, | |
51 bool readonly); | 57 bool readonly); |
52 virtual ~TransportSecurityPersister(); | 58 virtual ~TransportSecurityPersister(); |
53 | 59 |
54 // Called by the TransportSecurityState when it changes its state. | 60 // Called by the TransportSecurityState when it changes its state. |
55 virtual void StateIsDirty(net::TransportSecurityState*) OVERRIDE; | 61 virtual void StateIsDirty(net::TransportSecurityState*) OVERRIDE; |
56 | 62 |
57 // ImportantFileWriter::DataSerializer: | 63 // ImportantFileWriter::DataSerializer: |
58 // | 64 // |
59 // Serializes |transport_security_state_| into |*output|. Returns true if | 65 // Serializes |transport_security_state_| into |*output|. Returns true if |
60 // all DomainStates were serialized correctly. | 66 // all DomainStates were serialized correctly. |
(...skipping 26 matching lines...) Expand all Loading... | |
87 virtual bool SerializeData(std::string* data) OVERRIDE; | 93 virtual bool SerializeData(std::string* data) OVERRIDE; |
88 | 94 |
89 // Clears any existing non-static entries, and then re-populates | 95 // Clears any existing non-static entries, and then re-populates |
90 // |transport_security_state_|. | 96 // |transport_security_state_|. |
91 // | 97 // |
92 // Sets |*dirty| to true if the new state differs from the persisted | 98 // Sets |*dirty| to true if the new state differs from the persisted |
93 // state; false otherwise. | 99 // state; false otherwise. |
94 bool LoadEntries(const std::string& serialized, bool* dirty); | 100 bool LoadEntries(const std::string& serialized, bool* dirty); |
95 | 101 |
96 private: | 102 private: |
97 class Loader; | |
98 | |
99 // Populates |state| from the JSON string |serialized|. Returns true if | 103 // Populates |state| from the JSON string |serialized|. Returns true if |
100 // all entries were parsed and deserialized correctly. | 104 // all entries were parsed and deserialized correctly. |
101 // | 105 // |
102 // Sets |*dirty| to true if the new state differs from the persisted | 106 // Sets |*dirty| to true if the new state differs from the persisted |
103 // state; false otherwise. | 107 // state; false otherwise. |
104 static bool Deserialize(const std::string& serialized, | 108 static bool Deserialize(const std::string& serialized, |
105 bool* dirty, | 109 bool* dirty, |
106 net::TransportSecurityState* state); | 110 net::TransportSecurityState* state); |
107 | 111 |
108 void CompleteLoad(const std::string& state); | 112 void CompleteLoad(const std::string& state); |
109 | 113 |
110 net::TransportSecurityState* transport_security_state_; | 114 net::TransportSecurityState* transport_security_state_; |
111 | 115 |
112 // Helper for safely writing the data. | 116 // Helper for safely writing the data. |
113 base::ImportantFileWriter writer_; | 117 base::ImportantFileWriter writer_; |
114 | 118 |
119 scoped_refptr<base::SequencedTaskRunner> foreground_runner_; | |
120 scoped_refptr<base::SequencedTaskRunner> background_runner_; | |
battre
2013/11/05 11:54:36
Add comments that foreground is IO thread and back
Aaron Boodman
2013/11/06 21:57:06
In Mojo, this class isn't necessarily created on t
| |
121 | |
115 // Whether or not we're in read-only mode. | 122 // Whether or not we're in read-only mode. |
116 const bool readonly_; | 123 const bool readonly_; |
117 | 124 |
118 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; | 125 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; |
119 | 126 |
120 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); | 127 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); |
121 }; | 128 }; |
122 | 129 |
123 #endif // CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ | 130 #endif // CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ |
OLD | NEW |