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 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/threading/thread.h" | |
7 #include "chrome/browser/browser_process.h" | |
8 #include "chrome/browser/io_thread.h" | |
9 #include "chrome/browser/net/ssl_config_service_manager.h" | 6 #include "chrome/browser/net/ssl_config_service_manager.h" |
10 #include "chrome/browser/prefs/pref_member.h" | 7 #include "chrome/browser/prefs/pref_member.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/common/chrome_notification_types.h" |
12 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
13 #include "content/common/content_notification_types.h" | 11 #include "content/browser/browser_thread.h" |
14 #include "content/common/notification_details.h" | |
15 #include "content/common/notification_source.h" | |
16 #include "net/base/ssl_config_service.h" | 12 #include "net/base/ssl_config_service.h" |
17 | 13 |
18 //////////////////////////////////////////////////////////////////////////////// | 14 //////////////////////////////////////////////////////////////////////////////// |
19 // SSLConfigServicePref | 15 // SSLConfigServicePref |
20 | 16 |
21 // An SSLConfigService which stores a cached version of the current SSLConfig | 17 // An SSLConfigService which stores a cached version of the current SSLConfig |
22 // prefs, which are updated by SSLConfigServiceManagerPref when the prefs | 18 // prefs, which are updated by SSLConfigServiceManagerPref when the prefs |
23 // change. | 19 // change. |
24 class SSLConfigServicePref : public net::SSLConfigService { | 20 class SSLConfigServicePref : public net::SSLConfigService { |
25 public: | 21 public: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // SSLConfigServiceManagerPref | 54 // SSLConfigServiceManagerPref |
59 | 55 |
60 // The manager for holding and updating an SSLConfigServicePref instance. | 56 // The manager for holding and updating an SSLConfigServicePref instance. |
61 class SSLConfigServiceManagerPref | 57 class SSLConfigServiceManagerPref |
62 : public SSLConfigServiceManager, | 58 : public SSLConfigServiceManager, |
63 public NotificationObserver { | 59 public NotificationObserver { |
64 public: | 60 public: |
65 explicit SSLConfigServiceManagerPref(PrefService* local_state); | 61 explicit SSLConfigServiceManagerPref(PrefService* local_state); |
66 virtual ~SSLConfigServiceManagerPref() {} | 62 virtual ~SSLConfigServiceManagerPref() {} |
67 | 63 |
| 64 // Register local_state SSL preferences. |
| 65 static void RegisterPrefs(PrefService* prefs); |
| 66 |
68 virtual net::SSLConfigService* Get(); | 67 virtual net::SSLConfigService* Get(); |
69 | 68 |
70 private: | 69 private: |
71 // Register local_state SSL preferences. | |
72 static void RegisterPrefs(PrefService* prefs); | |
73 | |
74 // Callback for preference changes. This will post the changes to the IO | 70 // Callback for preference changes. This will post the changes to the IO |
75 // thread with SetNewSSLConfig. | 71 // thread with SetNewSSLConfig. |
76 virtual void Observe(int type, | 72 virtual void Observe(int type, |
77 const NotificationSource& source, | 73 const NotificationSource& source, |
78 const NotificationDetails& details); | 74 const NotificationDetails& details); |
79 | 75 |
80 // Store SSL config settings in |config|, directly from the preferences. Must | 76 // Store SSL config settings in |config|, directly from the preferences. Must |
81 // only be called from UI thread. | 77 // only be called from UI thread. |
82 void GetSSLConfigFromPrefs(net::SSLConfig* config); | 78 void GetSSLConfigFromPrefs(net::SSLConfig* config); |
83 | 79 |
84 // The prefs (should only be accessed from UI thread) | 80 // The prefs (should only be accessed from UI thread) |
85 BooleanPrefMember rev_checking_enabled_; | 81 BooleanPrefMember rev_checking_enabled_; |
86 BooleanPrefMember ssl3_enabled_; | 82 BooleanPrefMember ssl3_enabled_; |
87 BooleanPrefMember tls1_enabled_; | 83 BooleanPrefMember tls1_enabled_; |
88 | 84 |
89 scoped_refptr<SSLConfigServicePref> ssl_config_service_; | 85 scoped_refptr<SSLConfigServicePref> ssl_config_service_; |
90 | 86 |
91 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref); | 87 DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref); |
92 }; | 88 }; |
93 | 89 |
94 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref( | 90 SSLConfigServiceManagerPref::SSLConfigServiceManagerPref( |
95 PrefService* local_state) | 91 PrefService* local_state) |
96 : ssl_config_service_(new SSLConfigServicePref()) { | 92 : ssl_config_service_(new SSLConfigServicePref()) { |
97 DCHECK(local_state); | 93 DCHECK(local_state); |
98 | 94 |
99 RegisterPrefs(local_state); | |
100 | |
101 rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled, | 95 rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled, |
102 local_state, this); | 96 local_state, this); |
103 ssl3_enabled_.Init(prefs::kSSL3Enabled, local_state, this); | 97 ssl3_enabled_.Init(prefs::kSSL3Enabled, local_state, this); |
104 tls1_enabled_.Init(prefs::kTLS1Enabled, local_state, this); | 98 tls1_enabled_.Init(prefs::kTLS1Enabled, local_state, this); |
105 | 99 |
106 // Initialize from UI thread. This is okay as there shouldn't be anything on | 100 // Initialize from UI thread. This is okay as there shouldn't be anything on |
107 // the IO thread trying to access it yet. | 101 // the IO thread trying to access it yet. |
108 GetSSLConfigFromPrefs(&ssl_config_service_->cached_config_); | 102 GetSSLConfigFromPrefs(&ssl_config_service_->cached_config_); |
109 } | 103 } |
110 | 104 |
111 // static | 105 // static |
112 void SSLConfigServiceManagerPref::RegisterPrefs(PrefService* prefs) { | 106 void SSLConfigServiceManagerPref::RegisterPrefs(PrefService* prefs) { |
113 net::SSLConfig default_config; | 107 net::SSLConfig default_config; |
114 if (!prefs->FindPreference(prefs::kCertRevocationCheckingEnabled)) { | 108 prefs->RegisterBooleanPref(prefs::kCertRevocationCheckingEnabled, |
115 prefs->RegisterBooleanPref(prefs::kCertRevocationCheckingEnabled, | 109 default_config.rev_checking_enabled); |
116 default_config.rev_checking_enabled); | 110 prefs->RegisterBooleanPref(prefs::kSSL3Enabled, |
117 } | 111 default_config.ssl3_enabled); |
118 if (!prefs->FindPreference(prefs::kSSL3Enabled)) { | 112 prefs->RegisterBooleanPref(prefs::kTLS1Enabled, |
119 prefs->RegisterBooleanPref(prefs::kSSL3Enabled, | 113 default_config.tls1_enabled); |
120 default_config.ssl3_enabled); | |
121 } | |
122 if (!prefs->FindPreference(prefs::kTLS1Enabled)) { | |
123 prefs->RegisterBooleanPref(prefs::kTLS1Enabled, | |
124 default_config.tls1_enabled); | |
125 } | |
126 } | 114 } |
127 | 115 |
128 net::SSLConfigService* SSLConfigServiceManagerPref::Get() { | 116 net::SSLConfigService* SSLConfigServiceManagerPref::Get() { |
129 return ssl_config_service_; | 117 return ssl_config_service_; |
130 } | 118 } |
131 | 119 |
132 void SSLConfigServiceManagerPref::Observe(int type, | 120 void SSLConfigServiceManagerPref::Observe(int type, |
133 const NotificationSource& source, | 121 const NotificationSource& source, |
134 const NotificationDetails& details) { | 122 const NotificationDetails& details) { |
135 base::Thread* io_thread = g_browser_process->io_thread(); | 123 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
136 if (io_thread) { | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
137 net::SSLConfig new_config; | 125 net::SSLConfig new_config; |
138 GetSSLConfigFromPrefs(&new_config); | 126 GetSSLConfigFromPrefs(&new_config); |
139 | 127 |
140 // Post a task to |io_loop| with the new configuration, so it can | 128 // Post a task to |io_loop| with the new configuration, so it can |
141 // update |cached_config_|. | 129 // update |cached_config_|. |
142 io_thread->message_loop()->PostTask( | 130 BrowserThread::PostTask( |
| 131 BrowserThread::IO, |
143 FROM_HERE, | 132 FROM_HERE, |
144 NewRunnableMethod( | 133 NewRunnableMethod( |
145 ssl_config_service_.get(), | 134 ssl_config_service_.get(), |
146 &SSLConfigServicePref::SetNewSSLConfig, | 135 &SSLConfigServicePref::SetNewSSLConfig, |
147 new_config)); | 136 new_config)); |
148 } | 137 } |
149 } | 138 } |
150 | 139 |
151 void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs( | 140 void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs( |
152 net::SSLConfig* config) { | 141 net::SSLConfig* config) { |
153 config->rev_checking_enabled = rev_checking_enabled_.GetValue(); | 142 config->rev_checking_enabled = rev_checking_enabled_.GetValue(); |
154 config->ssl3_enabled = ssl3_enabled_.GetValue(); | 143 config->ssl3_enabled = ssl3_enabled_.GetValue(); |
155 config->tls1_enabled = tls1_enabled_.GetValue(); | 144 config->tls1_enabled = tls1_enabled_.GetValue(); |
156 SSLConfigServicePref::SetSSLConfigFlags(config); | 145 SSLConfigServicePref::SetSSLConfigFlags(config); |
157 } | 146 } |
158 | 147 |
159 //////////////////////////////////////////////////////////////////////////////// | 148 //////////////////////////////////////////////////////////////////////////////// |
160 // SSLConfigServiceManager | 149 // SSLConfigServiceManager |
161 | 150 |
162 // static | 151 // static |
163 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager( | 152 SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager( |
164 PrefService* local_state) { | 153 PrefService* local_state) { |
165 return new SSLConfigServiceManagerPref(local_state); | 154 return new SSLConfigServiceManagerPref(local_state); |
166 } | 155 } |
| 156 |
| 157 // static |
| 158 void SSLConfigServiceManager::RegisterPrefs(PrefService* prefs) { |
| 159 SSLConfigServiceManagerPref::RegisterPrefs(prefs); |
| 160 } |
OLD | NEW |