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 ImportantFileWriter::DataSerializer, |
48 public net::TransportSecurityState::Delegate, | 49 public base::SupportsWeakPtr<TransportSecurityPersister> { |
willchan no longer on Chromium
2011/09/20 19:09:04
Can you use base::WeakPtrFactory as a private memb
Paweł Hajdan Jr.
2011/09/21 17:59:19
Good idea, done.
| |
49 public ImportantFileWriter::DataSerializer { | |
50 public: | 50 public: |
51 TransportSecurityPersister(net::TransportSecurityState* state, | 51 TransportSecurityPersister(net::TransportSecurityState* state, |
52 const FilePath& profile_path, | 52 const FilePath& profile_path, |
53 bool readonly); | 53 bool readonly); |
54 | 54 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 | 55 |
59 // Called by the TransportSecurityState when it changes its state. | 56 // Called by the TransportSecurityState when it changes its state. |
60 virtual void StateIsDirty(net::TransportSecurityState*); | 57 virtual void StateIsDirty(net::TransportSecurityState*); |
61 | 58 |
62 // ImportantFileWriter::DataSerializer: | 59 // ImportantFileWriter::DataSerializer: |
63 virtual bool SerializeData(std::string* data); | 60 virtual bool SerializeData(std::string* data); |
64 | 61 |
65 private: | 62 private: |
66 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 63 class Loader; |
67 friend class DeleteTask<TransportSecurityPersister>; | |
68 | 64 |
69 virtual ~TransportSecurityPersister(); | |
70 | |
71 void Load(); | |
72 void CompleteLoad(const std::string& state); | 65 void CompleteLoad(const std::string& state); |
73 | 66 |
74 // IO thread only. | |
75 scoped_refptr<net::TransportSecurityState> transport_security_state_; | 67 scoped_refptr<net::TransportSecurityState> transport_security_state_; |
76 | 68 |
77 // Helper for safely writing the data. | 69 // Helper for safely writing the data. |
78 ImportantFileWriter writer_; | 70 ImportantFileWriter writer_; |
79 | 71 |
80 // Whether or not we're in read-only mode. | 72 // Whether or not we're in read-only mode. |
81 const bool readonly_; | 73 const bool readonly_; |
82 | 74 |
83 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); | 75 DISALLOW_COPY_AND_ASSIGN(TransportSecurityPersister); |
84 }; | 76 }; |
85 | 77 |
86 #endif // CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ | 78 #endif // CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_ |
OLD | NEW |