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
3 // found in the LICENSE file.
5 // TransportSecurityState maintains an in memory database containing the
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
8 // loading it at startup.
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
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
14 // correct transport security information.
16 // To load the state, we schedule a Task on the file thread which loads,
17 // deserialises and configures the TransportSecurityState.
19 // The TransportSecurityState object supports running a callback function
20 // when it changes. This object registers the callback, pointing at itself.
22 // TransportSecurityState calls...
23 // TransportSecurityPersister::StateIsDirty
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
29 // TransportSecurityPersister::SerialiseState
30 // copies the current state of the TransportSecurityState, serialises
31 // and writes to disk.
33 #ifndef CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_
34 #define CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_
37 #include "base/file_path.h"
38 #include "base/memory/ref_counted.h"
39 #include "base/task.h"
40 #include "net/base/transport_security_state.h"
42 class TransportSecurityPersister
43 : public base::RefCountedThreadSafe
<TransportSecurityPersister
>,
44 public net::TransportSecurityState::Delegate
{
46 explicit TransportSecurityPersister(bool readonly
);
47 void Initialize(net::TransportSecurityState
* state
,
48 const FilePath
& profile_path
);
50 // Called by the TransportSecurityState when it changes its state.
51 virtual void StateIsDirty(net::TransportSecurityState
*);
54 friend class base::RefCountedThreadSafe
<TransportSecurityPersister
>;
56 virtual ~TransportSecurityPersister();
59 void CompleteLoad(const std::string
& state
);
62 void CompleteSave(const std::string
& state
);
64 // Used on the IO thread to coalesce writes to disk.
65 ScopedRunnableMethodFactory
<TransportSecurityPersister
> save_coalescer_
;
67 scoped_refptr
<net::TransportSecurityState
>
68 transport_security_state_
; // IO thread only.
70 // The path to the file in which we store the serialised state.
73 // Whether or not we're in read-only mode.
77 #endif // CHROME_BROWSER_TRANSPORT_SECURITY_PERSISTER_H_