Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/browser/net/transport_security_persister.h

Issue 57993004: Remove content dependency from TransportSecurityPersister. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: asdf Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/net/transport_security_persister.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // disk. For the moment, we don't want to delay startup for this load, so we 11 // disk. For the moment, we don't want to delay startup for this load, so we
12 // let the TransportSecurityState run for a while without being loaded. 12 // let the TransportSecurityState run for a while without being loaded.
13 // This means that it's possible for pages opened very quickly not to get the 13 // This means that it's possible for pages opened very quickly not to get the
14 // correct transport security information. 14 // correct transport security information.
15 // 15 //
16 // To load the state, we schedule a Task on the file thread which loads, 16 // To load the state, we schedule a Task on file_task_runner, which
17 // deserializes and configures the TransportSecurityState. 17 // deserializes and configures the TransportSecurityState.
18 // 18 //
19 // The TransportSecurityState object supports running a callback function 19 // The TransportSecurityState object supports running a callback function
20 // when it changes. This object registers the callback, pointing at itself. 20 // when it changes. This object registers the callback, pointing at itself.
21 // 21 //
22 // TransportSecurityState calls... 22 // TransportSecurityState calls...
23 // TransportSecurityPersister::StateIsDirty 23 // TransportSecurityPersister::StateIsDirty
24 // since the callback isn't allowed to block or reenter, we schedule a Task 24 // since the callback isn't allowed to block or reenter, we schedule a Task
25 // on the file thread after some small amount of time 25 // on the file task runner after some small amount of time
26 // 26 //
27 // ... 27 // ...
28 // 28 //
29 // TransportSecurityPersister::SerializeState 29 // TransportSecurityPersister::SerializeState
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
43 // Reads and updates on-disk TransportSecurity state. 44 namespace base {
44 // Must be created, used and destroyed only on the IO thread. 45 class SequencedTaskRunner;
46 }
47
48 // Reads and updates on-disk TransportSecurity state. Clients of this class
49 // should create, destroy, and call into it from one thread.
50 //
51 // file_task_runner is the task runner this class should use internally to
52 // perform file IO, and can optionally be associated with a different thread.
45 class TransportSecurityPersister 53 class TransportSecurityPersister
46 : public net::TransportSecurityState::Delegate, 54 : public net::TransportSecurityState::Delegate,
47 public base::ImportantFileWriter::DataSerializer { 55 public base::ImportantFileWriter::DataSerializer {
48 public: 56 public:
49 TransportSecurityPersister(net::TransportSecurityState* state, 57 TransportSecurityPersister(net::TransportSecurityState* state,
50 const base::FilePath& profile_path, 58 const base::FilePath& profile_path,
59 base::SequencedTaskRunner* file_task_runner,
51 bool readonly); 60 bool readonly);
52 virtual ~TransportSecurityPersister(); 61 virtual ~TransportSecurityPersister();
53 62
54 // Called by the TransportSecurityState when it changes its state. 63 // Called by the TransportSecurityState when it changes its state.
55 virtual void StateIsDirty(net::TransportSecurityState*) OVERRIDE; 64 virtual void StateIsDirty(net::TransportSecurityState*) OVERRIDE;
56 65
57 // ImportantFileWriter::DataSerializer: 66 // ImportantFileWriter::DataSerializer:
58 // 67 //
59 // Serializes |transport_security_state_| into |*output|. Returns true if 68 // Serializes |transport_security_state_| into |*output|. Returns true if
60 // all DomainStates were serialized correctly. 69 // all DomainStates were serialized correctly.
(...skipping 26 matching lines...) Expand all
87 virtual bool SerializeData(std::string* data) OVERRIDE; 96 virtual bool SerializeData(std::string* data) OVERRIDE;
88 97
89 // Clears any existing non-static entries, and then re-populates 98 // Clears any existing non-static entries, and then re-populates
90 // |transport_security_state_|. 99 // |transport_security_state_|.
91 // 100 //
92 // Sets |*dirty| to true if the new state differs from the persisted 101 // Sets |*dirty| to true if the new state differs from the persisted
93 // state; false otherwise. 102 // state; false otherwise.
94 bool LoadEntries(const std::string& serialized, bool* dirty); 103 bool LoadEntries(const std::string& serialized, bool* dirty);
95 104
96 private: 105 private:
97 class Loader;
98
99 // Populates |state| from the JSON string |serialized|. Returns true if 106 // Populates |state| from the JSON string |serialized|. Returns true if
100 // all entries were parsed and deserialized correctly. 107 // all entries were parsed and deserialized correctly.
101 // 108 //
102 // Sets |*dirty| to true if the new state differs from the persisted 109 // Sets |*dirty| to true if the new state differs from the persisted
103 // state; false otherwise. 110 // state; false otherwise.
104 static bool Deserialize(const std::string& serialized, 111 static bool Deserialize(const std::string& serialized,
105 bool* dirty, 112 bool* dirty,
106 net::TransportSecurityState* state); 113 net::TransportSecurityState* state);
107 114
108 void CompleteLoad(const std::string& state); 115 void CompleteLoad(const std::string& state);
109 116
110 net::TransportSecurityState* transport_security_state_; 117 net::TransportSecurityState* transport_security_state_;
111 118
112 // Helper for safely writing the data. 119 // Helper for safely writing the data.
113 base::ImportantFileWriter writer_; 120 base::ImportantFileWriter writer_;
114 121
122 scoped_refptr<base::SequencedTaskRunner> foreground_runner_;
123 scoped_refptr<base::SequencedTaskRunner> background_runner_;
124
115 // Whether or not we're in read-only mode. 125 // Whether or not we're in read-only mode.
116 const bool readonly_; 126 const bool readonly_;
117 127
118 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; 128 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_;
119 129
120 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); 130 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister);
121 }; 131 };
122 132
123 #endif // CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_ 133 #endif // CHROME_BROWSER_NET_TRANSPORT_SECURITY_PERSISTER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/transport_security_persister.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698