xref: /aosp_15_r20/external/cronet/net/ssl/ssl_config_service.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/ssl/ssl_config_service.h"
6 
7 #include <tuple>
8 
9 #include "base/feature_list.h"
10 #include "base/observer_list.h"
11 #include "net/base/features.h"
12 #include "net/ssl/ssl_config_service_defaults.h"
13 
14 namespace net {
15 
16 SSLContextConfig::SSLContextConfig() = default;
17 SSLContextConfig::SSLContextConfig(const SSLContextConfig&) = default;
18 SSLContextConfig::SSLContextConfig(SSLContextConfig&&) = default;
19 SSLContextConfig::~SSLContextConfig() = default;
20 SSLContextConfig& SSLContextConfig::operator=(const SSLContextConfig&) =
21     default;
22 SSLContextConfig& SSLContextConfig::operator=(SSLContextConfig&&) = default;
23 bool SSLContextConfig::operator==(const SSLContextConfig&) const = default;
24 
PostQuantumKeyAgreementEnabled() const25 bool SSLContextConfig::PostQuantumKeyAgreementEnabled() const {
26   return post_quantum_override.value_or(
27       base::FeatureList::IsEnabled(features::kPostQuantumKyber));
28 }
29 
SSLConfigService()30 SSLConfigService::SSLConfigService()
31     : observer_list_(base::ObserverListPolicy::EXISTING_ONLY) {}
32 
33 SSLConfigService::~SSLConfigService() = default;
34 
AddObserver(Observer * observer)35 void SSLConfigService::AddObserver(Observer* observer) {
36   observer_list_.AddObserver(observer);
37 }
38 
RemoveObserver(Observer * observer)39 void SSLConfigService::RemoveObserver(Observer* observer) {
40   observer_list_.RemoveObserver(observer);
41 }
42 
NotifySSLContextConfigChange()43 void SSLConfigService::NotifySSLContextConfigChange() {
44   for (auto& observer : observer_list_)
45     observer.OnSSLContextConfigChanged();
46 }
47 
ProcessConfigUpdate(const SSLContextConfig & old_config,const SSLContextConfig & new_config,bool force_notification)48 void SSLConfigService::ProcessConfigUpdate(const SSLContextConfig& old_config,
49                                            const SSLContextConfig& new_config,
50                                            bool force_notification) {
51   // Do nothing if the configuration hasn't changed.
52   if (old_config != new_config || force_notification) {
53     NotifySSLContextConfigChange();
54   }
55 }
56 
57 }  // namespace net
58