OLD | NEW |
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 #include "net/ssl/ssl_config_service.h" | 5 #include "net/ssl/ssl_config_service.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
9 #include "net/ssl/ssl_config_service_defaults.h" | 9 #include "net/ssl/ssl_config_service_defaults.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 | 12 |
13 SSLConfigService::SSLConfigService() | 13 SSLConfigService::SSLConfigService() |
14 : observer_list_(ObserverList<Observer>::NOTIFY_EXISTING_ONLY) { | 14 : observer_list_(ObserverList<Observer>::NOTIFY_EXISTING_ONLY) { |
15 } | 15 } |
16 | 16 |
17 // GlobalCRLSet holds a reference to the global CRLSet. It simply wraps a lock | 17 // GlobalSSLObject holds a reference to a global SSL object, such as the |
18 // around a scoped_refptr so that getting a reference doesn't race with | 18 // CRLSet or the EVCertsWhitelist. It simply wraps a lock around a |
19 // updating the CRLSet. | 19 // scoped_refptr so that getting a reference doesn't race with |
20 class GlobalCRLSet { | 20 // updating the global object. |
| 21 template <class T> |
| 22 class GlobalSSLObject { |
21 public: | 23 public: |
22 void Set(const scoped_refptr<CRLSet>& new_crl_set) { | 24 void Set(const scoped_refptr<T>& new_ssl_object) { |
23 base::AutoLock locked(lock_); | 25 base::AutoLock locked(lock_); |
24 crl_set_ = new_crl_set; | 26 ssl_object_ = new_ssl_object; |
25 } | 27 } |
26 | 28 |
27 scoped_refptr<CRLSet> Get() const { | 29 scoped_refptr<T> Get() const { |
28 base::AutoLock locked(lock_); | 30 base::AutoLock locked(lock_); |
29 return crl_set_; | 31 return ssl_object_; |
30 } | 32 } |
31 | 33 |
32 private: | 34 private: |
33 scoped_refptr<CRLSet> crl_set_; | 35 scoped_refptr<T> ssl_object_; |
34 mutable base::Lock lock_; | 36 mutable base::Lock lock_; |
35 }; | 37 }; |
36 | 38 |
| 39 typedef GlobalSSLObject<CRLSet> GlobalCRLSet; |
| 40 typedef GlobalSSLObject<ct::EVCertsWhitelist> GlobalEVCertsWhitelist; |
| 41 |
37 base::LazyInstance<GlobalCRLSet>::Leaky g_crl_set = LAZY_INSTANCE_INITIALIZER; | 42 base::LazyInstance<GlobalCRLSet>::Leaky g_crl_set = LAZY_INSTANCE_INITIALIZER; |
| 43 base::LazyInstance<GlobalEVCertsWhitelist>::Leaky g_ev_whitelist = |
| 44 LAZY_INSTANCE_INITIALIZER; |
38 | 45 |
39 // static | 46 // static |
40 void SSLConfigService::SetCRLSet(scoped_refptr<CRLSet> crl_set) { | 47 void SSLConfigService::SetCRLSet(scoped_refptr<CRLSet> crl_set) { |
41 // Note: this can be called concurently with GetCRLSet(). | 48 // Note: this can be called concurently with GetCRLSet(). |
42 g_crl_set.Get().Set(crl_set); | 49 g_crl_set.Get().Set(crl_set); |
43 } | 50 } |
44 | 51 |
45 // static | 52 // static |
46 scoped_refptr<CRLSet> SSLConfigService::GetCRLSet() { | 53 scoped_refptr<CRLSet> SSLConfigService::GetCRLSet() { |
47 return g_crl_set.Get().Get(); | 54 return g_crl_set.Get().Get(); |
48 } | 55 } |
49 | 56 |
| 57 // static |
| 58 void SSLConfigService::SetEVCertsWhitelist( |
| 59 scoped_refptr<ct::EVCertsWhitelist> ev_whitelist) { |
| 60 g_ev_whitelist.Get().Set(ev_whitelist); |
| 61 } |
| 62 |
| 63 // static |
| 64 scoped_refptr<ct::EVCertsWhitelist> SSLConfigService::GetEVCertsWhitelist() { |
| 65 return g_ev_whitelist.Get().Get(); |
| 66 } |
| 67 |
50 void SSLConfigService::AddObserver(Observer* observer) { | 68 void SSLConfigService::AddObserver(Observer* observer) { |
51 observer_list_.AddObserver(observer); | 69 observer_list_.AddObserver(observer); |
52 } | 70 } |
53 | 71 |
54 void SSLConfigService::RemoveObserver(Observer* observer) { | 72 void SSLConfigService::RemoveObserver(Observer* observer) { |
55 observer_list_.RemoveObserver(observer); | 73 observer_list_.RemoveObserver(observer); |
56 } | 74 } |
57 | 75 |
58 void SSLConfigService::NotifySSLConfigChange() { | 76 void SSLConfigService::NotifySSLConfigChange() { |
59 FOR_EACH_OBSERVER(Observer, observer_list_, OnSSLConfigChanged()); | 77 FOR_EACH_OBSERVER(Observer, observer_list_, OnSSLConfigChanged()); |
(...skipping 15 matching lines...) Expand all Loading... |
75 (orig_config.channel_id_enabled != new_config.channel_id_enabled) || | 93 (orig_config.channel_id_enabled != new_config.channel_id_enabled) || |
76 (orig_config.false_start_enabled != new_config.false_start_enabled) || | 94 (orig_config.false_start_enabled != new_config.false_start_enabled) || |
77 (orig_config.require_forward_secrecy != | 95 (orig_config.require_forward_secrecy != |
78 new_config.require_forward_secrecy); | 96 new_config.require_forward_secrecy); |
79 | 97 |
80 if (config_changed) | 98 if (config_changed) |
81 NotifySSLConfigChange(); | 99 NotifySSLConfigChange(); |
82 } | 100 } |
83 | 101 |
84 } // namespace net | 102 } // namespace net |
OLD | NEW |