OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2006-2008 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. |
| 4 |
| 5 // ForceTLSState maintains an in memory database containing the list of hosts |
| 6 // that currently have ForceTLS enabled. This singleton object deals with |
| 7 // writing that data out to disk as needed and loading it at startup. |
| 8 |
| 9 // At startup we need to load the ForceTLS state from the disk. For the moment, |
| 10 // we don't want to delay startup for this load, so we let the ForceTLSState |
| 11 // run for a while without being loaded. This means that it's possible for |
| 12 // pages opened very quickly not to get the correct ForceTLS information. |
| 13 // |
| 14 // To load the state, we schedule a Task on the file thread which loads, |
| 15 // deserialises and configures the ForceTLSState. |
| 16 // |
| 17 // The ForceTLSState object supports running a callback function when it |
| 18 // changes. This object registers the callback, pointing at itself. |
| 19 // |
| 20 // ForceTLSState calls... |
| 21 // ForceTLSPersister::StateIsDirty |
| 22 // since the callback isn't allowed to block or reenter, we schedule a Task |
| 23 // on |file_thread_| after some small amount of time |
| 24 // |
| 25 // ... |
| 26 // |
| 27 // ForceTLSPersister::SerialiseState |
| 28 // copies the current state of the ForceTLSState, serialises and writes to |
| 29 // disk. |
| 30 |
| 31 #include "base/lock.h" |
| 32 #include "base/ref_counted.h" |
| 33 #include "net/base/force_tls_state.h" |
| 34 |
| 35 namespace base { |
| 36 class Thread; |
| 37 } |
| 38 |
| 39 class ForceTLSPersister : public base::RefCountedThreadSafe<ForceTLSPersister> { |
| 40 public: |
| 41 ForceTLSPersister(net::ForceTLSState* state, base::Thread* file_thread); |
| 42 |
| 43 // Called by the ForceTLSState when it changes its state. |
| 44 void StateIsDirty(); |
| 45 |
| 46 private: |
| 47 // a Task callback for when the state needs to be written out. |
| 48 void SerialiseState(); |
| 49 |
| 50 // a Task callback for when the state needs to be loaded from disk at startup. |
| 51 void LoadState(); |
| 52 |
| 53 Lock lock_; // protects all the members |
| 54 |
| 55 // true when the state object has signaled that we're dirty and we haven't |
| 56 // serialised the state yet. |
| 57 bool state_is_dirty_; |
| 58 |
| 59 scoped_refptr<net::ForceTLSState> force_tls_state_; |
| 60 |
| 61 // This is a thread which can perform file access. |
| 62 base::Thread* const file_thread_; |
| 63 }; |
OLD | NEW |