OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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, serialises | 30 // copies the current state of the TransportSecurityState, serialises |
31 // and writes to disk. | 31 // and writes to disk. |
32 | 32 |
33 #ifndef CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ | 33 #ifndef CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ |
34 #define CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ | 34 #define CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ |
35 #pragma once | 35 #pragma once |
36 | 36 |
37 #include <string> | 37 #include <string> |
38 | 38 |
39 #include "base/file_path.h" | 39 #include "base/file_path.h" |
40 #include "base/memory/ref_counted.h" | 40 #include "base/memory/weak_ptr.h" |
41 #include "chrome/common/important_file_writer.h" | 41 #include "chrome/common/important_file_writer.h" |
42 #include "content/browser/browser_thread.h" | |
43 #include "net/base/transport_security_state.h" | 42 #include "net/base/transport_security_state.h" |
44 | 43 |
| 44 // Reads and updates on-disk TransportSecurity state. |
| 45 // Must be created, used and destroyed only on the IO thread. |
45 class TransportSecurityPersister | 46 class TransportSecurityPersister |
46 : public base::RefCountedThreadSafe<TransportSecurityPersister, | 47 : public net::TransportSecurityState::Delegate, |
47 BrowserThread::DeleteOnUIThread>, | |
48 public net::TransportSecurityState::Delegate, | |
49 public ImportantFileWriter::DataSerializer { | 48 public ImportantFileWriter::DataSerializer { |
50 public: | 49 public: |
51 TransportSecurityPersister(net::TransportSecurityState* state, | 50 TransportSecurityPersister(net::TransportSecurityState* state, |
52 const FilePath& profile_path, | 51 const FilePath& profile_path, |
53 bool readonly); | 52 bool readonly); |
54 | 53 virtual ~TransportSecurityPersister(); |
55 // Starts transport security data load on a background thread. | |
56 // Must be called on the UI thread right after construction. | |
57 void Init(); | |
58 | 54 |
59 // Called by the TransportSecurityState when it changes its state. | 55 // Called by the TransportSecurityState when it changes its state. |
60 virtual void StateIsDirty(net::TransportSecurityState*); | 56 virtual void StateIsDirty(net::TransportSecurityState*); |
61 | 57 |
62 // ImportantFileWriter::DataSerializer: | 58 // ImportantFileWriter::DataSerializer: |
63 virtual bool SerializeData(std::string* data); | 59 virtual bool SerializeData(std::string* data); |
64 | 60 |
65 private: | 61 private: |
66 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 62 class Loader; |
67 friend class DeleteTask<TransportSecurityPersister>; | |
68 | 63 |
69 virtual ~TransportSecurityPersister(); | |
70 | |
71 void Load(); | |
72 void CompleteLoad(const std::string& state); | 64 void CompleteLoad(const std::string& state); |
73 | 65 |
74 // IO thread only. | |
75 scoped_refptr<net::TransportSecurityState> transport_security_state_; | 66 scoped_refptr<net::TransportSecurityState> transport_security_state_; |
76 | 67 |
77 // Helper for safely writing the data. | 68 // Helper for safely writing the data. |
78 ImportantFileWriter writer_; | 69 ImportantFileWriter writer_; |
79 | 70 |
80 // Whether or not we're in read-only mode. | 71 // Whether or not we're in read-only mode. |
81 const bool readonly_; | 72 const bool readonly_; |
82 | 73 |
| 74 base::WeakPtrFactory<TransportSecurityPersister> weak_ptr_factory_; |
| 75 |
83 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); | 76 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); |
84 }; | 77 }; |
85 | 78 |
86 #endif // CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ | 79 #endif // CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ |
OLD | NEW |