1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "chrome/browser/chromeos/policy/network_configuration_updater.h"
16 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
23 class X509Certificate
;
24 typedef std::vector
<scoped_refptr
<X509Certificate
> > CertificateList
;
31 // Implements additional special handling of ONC user policies. Namely string
32 // expansion with the user's name (or email address, etc.) and handling of "Web"
33 // trust of certificates.
34 class UserNetworkConfigurationUpdater
: public NetworkConfigurationUpdater
,
35 public BrowserContextKeyedService
{
37 class WebTrustedCertsObserver
{
39 // Is called everytime the list of imported certificates with Web trust is
41 virtual void OnTrustAnchorsChanged(
42 const net::CertificateList
& trust_anchors
) = 0;
45 virtual ~UserNetworkConfigurationUpdater();
47 // Creates an updater that applies the ONC user policy from |policy_service|
48 // for user |user| once the policy service is completely initialized and on
49 // each policy change. Imported certificates, that request it, are only
50 // granted Web trust if |allow_trusted_certs_from_policy| is true. A reference
51 // to |user| is stored. It must outlive the returned updater.
52 static scoped_ptr
<UserNetworkConfigurationUpdater
> CreateForUserPolicy(
53 bool allow_trusted_certs_from_policy
,
54 const chromeos::User
& user
,
55 scoped_ptr
<chromeos::onc::CertificateImporter
> certificate_importer
,
56 PolicyService
* policy_service
,
57 chromeos::ManagedNetworkConfigurationHandler
* network_config_handler
);
59 void AddTrustedCertsObserver(WebTrustedCertsObserver
* observer
);
60 void RemoveTrustedCertsObserver(WebTrustedCertsObserver
* observer
);
62 // Sets |certs| to the list of Web trusted server and CA certificates from the
63 // last received policy.
64 void GetWebTrustedCertificates(net::CertificateList
* certs
) const;
67 class CrosTrustAnchorProvider
;
69 UserNetworkConfigurationUpdater(
70 bool allow_trusted_certs_from_policy
,
71 const chromeos::User
& user
,
72 scoped_ptr
<chromeos::onc::CertificateImporter
> certificate_importer
,
73 PolicyService
* policy_service
,
74 chromeos::ManagedNetworkConfigurationHandler
* network_config_handler
);
76 virtual void ImportCertificates(
77 const base::ListValue
& certificates_onc
) OVERRIDE
;
79 virtual void ApplyNetworkPolicy(
80 base::ListValue
* network_configs_onc
,
81 base::DictionaryValue
* global_network_config
) OVERRIDE
;
83 void NotifyTrustAnchorsChanged();
85 // Whether Web trust is allowed or not. Only relevant for user policies.
86 bool allow_trusted_certificates_from_policy_
;
88 // The user for whom the user policy will be applied. Is NULL if this Updater
89 // is used for device policy.
90 const chromeos::User
* user_
;
92 ObserverList
<WebTrustedCertsObserver
, true> observer_list_
;
94 // Contains the certificates of the last import that requested web trust. Must
95 // be empty if Web trust from policy is not allowed.
96 net::CertificateList web_trust_certs_
;
98 DISALLOW_COPY_AND_ASSIGN(UserNetworkConfigurationUpdater
);
101 } // namespace policy
103 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_NETWORK_CONFIGURATION_UPDATER_H_