1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/message_loop.h"
#include "base/thread.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/ssl_config_service_manager.h"
#include "chrome/browser/profile.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_member.h"
#include "chrome/common/pref_names.h"
#include "net/base/ssl_config_service.h"
////////////////////////////////////////////////////////////////////////////////
// SSLConfigServicePref
// An SSLConfigService which stores a cached version of the current SSLConfig
// prefs, which are updated by SSLConfigServiceManagerPref when the prefs
// change.
class SSLConfigServicePref : public net::SSLConfigService {
public:
SSLConfigServicePref() {}
virtual ~SSLConfigServicePref() {}
// Store SSL config settings in |config|. Must only be called from IO thread.
virtual void GetSSLConfig(net::SSLConfig* config);
private:
// Allow the pref watcher to update our internal state.
friend class SSLConfigServiceManagerPref;
// This method is posted to the IO thread from the browser thread to carry the
// new config information.
void SetNewSSLConfig(const net::SSLConfig& new_config);
// Cached value of prefs, should only be accessed from IO thread.
net::SSLConfig cached_config_;
DISALLOW_COPY_AND_ASSIGN(SSLConfigServicePref);
};
void SSLConfigServicePref::GetSSLConfig(net::SSLConfig* config) {
*config = cached_config_;
}
void SSLConfigServicePref::SetNewSSLConfig(
const net::SSLConfig& new_config) {
cached_config_ = new_config;
}
////////////////////////////////////////////////////////////////////////////////
// SSLConfigServiceManagerPref
// The manager for holding and updating an SSLConfigServicePref instance.
class SSLConfigServiceManagerPref
: public SSLConfigServiceManager,
public NotificationObserver {
public:
explicit SSLConfigServiceManagerPref(Profile* profile);
virtual ~SSLConfigServiceManagerPref() {}
virtual net::SSLConfigService* Get();
private:
static void RegisterUserPrefs(PrefService* user_prefs);
// Callback for preference changes. This will post the changes to the IO
// thread with SetNewSSLConfig.
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
// Store SSL config settings in |config|, directly from the preferences. Must
// only be called from UI thread.
void GetSSLConfigFromPrefs(net::SSLConfig* config);
// The prefs (should only be accessed from UI thread)
BooleanPrefMember rev_checking_enabled_;
BooleanPrefMember ssl2_enabled_;
BooleanPrefMember ssl3_enabled_;
BooleanPrefMember tls1_enabled_;
scoped_refptr<SSLConfigServicePref> ssl_config_service_;
DISALLOW_COPY_AND_ASSIGN(SSLConfigServiceManagerPref);
};
SSLConfigServiceManagerPref::SSLConfigServiceManagerPref(Profile* profile)
: ssl_config_service_(new SSLConfigServicePref()) {
RegisterUserPrefs(profile->GetPrefs());
rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled,
profile->GetPrefs(), this);
ssl2_enabled_.Init(prefs::kSSL2Enabled, profile->GetPrefs(), this);
ssl3_enabled_.Init(prefs::kSSL3Enabled, profile->GetPrefs(), this);
tls1_enabled_.Init(prefs::kTLS1Enabled, profile->GetPrefs(), this);
// Initialize from UI thread. This is okay as there shouldn't be anything on
// the IO thread trying to access it yet.
GetSSLConfigFromPrefs(&ssl_config_service_->cached_config_);
}
// static
void SSLConfigServiceManagerPref::RegisterUserPrefs(PrefService* user_prefs) {
net::SSLConfig default_config;
user_prefs->RegisterBooleanPref(prefs::kCertRevocationCheckingEnabled,
default_config.rev_checking_enabled);
user_prefs->RegisterBooleanPref(prefs::kSSL2Enabled,
default_config.ssl2_enabled);
user_prefs->RegisterBooleanPref(prefs::kSSL3Enabled,
default_config.ssl3_enabled);
user_prefs->RegisterBooleanPref(prefs::kTLS1Enabled,
default_config.tls1_enabled);
}
net::SSLConfigService* SSLConfigServiceManagerPref::Get() {
return ssl_config_service_;
}
void SSLConfigServiceManagerPref::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
base::Thread* io_thread = g_browser_process->io_thread();
if (io_thread) {
net::SSLConfig new_config;
GetSSLConfigFromPrefs(&new_config);
// Post a task to |io_loop| with the new configuration, so it can
// update |cached_config_|.
io_thread->message_loop()->PostTask(
FROM_HERE,
NewRunnableMethod(
ssl_config_service_.get(),
&SSLConfigServicePref::SetNewSSLConfig,
new_config));
}
}
void SSLConfigServiceManagerPref::GetSSLConfigFromPrefs(
net::SSLConfig* config) {
config->rev_checking_enabled = rev_checking_enabled_.GetValue();
config->ssl2_enabled = ssl2_enabled_.GetValue();
config->ssl3_enabled = ssl3_enabled_.GetValue();
config->tls1_enabled = tls1_enabled_.GetValue();
}
////////////////////////////////////////////////////////////////////////////////
// SSLConfigServiceManager
// static
SSLConfigServiceManager* SSLConfigServiceManager::CreateDefaultManager(
Profile* profile) {
return new SSLConfigServiceManagerPref(profile);
}
|