Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/chromeos/policy/network_configuration_updater.cc

Issue 148183013: Use per-user nssdb in onc certificate importer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/chromeos/policy/network_configuration_updater.h" 5 #include "chrome/browser/chromeos/policy/network_configuration_updater.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 19 matching lines...) Expand all
30 if (domain != POLICY_DOMAIN_CHROME) 30 if (domain != POLICY_DOMAIN_CHROME)
31 return; 31 return;
32 32
33 if (policy_service_->IsInitializationComplete(POLICY_DOMAIN_CHROME)) { 33 if (policy_service_->IsInitializationComplete(POLICY_DOMAIN_CHROME)) {
34 VLOG(1) << LogHeader() << " initialized."; 34 VLOG(1) << LogHeader() << " initialized.";
35 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, this); 35 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, this);
36 ApplyPolicy(); 36 ApplyPolicy();
37 } 37 }
38 } 38 }
39 39
40 void NetworkConfigurationUpdater::SetCertDatabase(
41 net::NSSCertDatabase* cert_database) {
42 DCHECK(!cert_database_);
43 cert_database_ = cert_database;
44
45 // If the policy service is ready, the policy has to be reapplied to ensure
46 // certificates are imported.
47 if (policy_service_->IsInitializationComplete(POLICY_DOMAIN_CHROME))
48 ApplyPolicy();
49 }
50
40 NetworkConfigurationUpdater::NetworkConfigurationUpdater( 51 NetworkConfigurationUpdater::NetworkConfigurationUpdater(
41 onc::ONCSource onc_source, 52 onc::ONCSource onc_source,
42 std::string policy_key, 53 std::string policy_key,
43 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer, 54 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer,
44 PolicyService* policy_service, 55 PolicyService* policy_service,
45 chromeos::ManagedNetworkConfigurationHandler* network_config_handler) 56 chromeos::ManagedNetworkConfigurationHandler* network_config_handler)
46 : onc_source_(onc_source), 57 : onc_source_(onc_source),
47 network_config_handler_(network_config_handler), 58 network_config_handler_(network_config_handler),
48 certificate_importer_(certificate_importer.Pass()), 59 certificate_importer_(certificate_importer.Pass()),
49 policy_key_(policy_key), 60 policy_key_(policy_key),
50 policy_change_registrar_(policy_service, 61 policy_change_registrar_(policy_service,
51 PolicyNamespace(POLICY_DOMAIN_CHROME, 62 PolicyNamespace(POLICY_DOMAIN_CHROME,
52 std::string())), 63 std::string())),
53 policy_service_(policy_service) { 64 policy_service_(policy_service),
65 cert_database_(NULL) {
54 } 66 }
55 67
56 void NetworkConfigurationUpdater::Init() { 68 void NetworkConfigurationUpdater::Init() {
57 policy_change_registrar_.Observe( 69 policy_change_registrar_.Observe(
58 policy_key_, 70 policy_key_,
59 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, 71 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged,
60 base::Unretained(this))); 72 base::Unretained(this)));
61 73
62 if (policy_service_->IsInitializationComplete(POLICY_DOMAIN_CHROME)) { 74 if (policy_service_->IsInitializationComplete(POLICY_DOMAIN_CHROME)) {
63 VLOG(1) << LogHeader() << " is already initialized."; 75 VLOG(1) << LogHeader() << " is already initialized.";
64 ApplyPolicy(); 76 ApplyPolicy();
65 } else { 77 } else {
66 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, this); 78 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, this);
67 } 79 }
68 } 80 }
69 81
70 void NetworkConfigurationUpdater::OnPolicyChanged( 82 void NetworkConfigurationUpdater::OnPolicyChanged(
71 const base::Value* previous, 83 const base::Value* previous,
72 const base::Value* current) { 84 const base::Value* current) {
73 VLOG(1) << LogHeader() << " changed."; 85 VLOG(1) << LogHeader() << " changed.";
74 ApplyPolicy(); 86 ApplyPolicy();
75 } 87 }
76 88
77 void NetworkConfigurationUpdater::ApplyPolicy() { 89 void NetworkConfigurationUpdater::ApplyPolicy() {
tbarzic 2014/02/04 23:44:56 We could also bail out here if database_ is not se
pneubeck (no reviews) 2014/02/05 11:03:27 In case of Device*Updater, we cannot wait for cert
tbarzic 2014/02/06 01:19:42 yes it does. I had a similar idea, but I didn't go
78 const PolicyMap& policies = policy_service_->GetPolicies( 90 const PolicyMap& policies = policy_service_->GetPolicies(
79 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); 91 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
80 const base::Value* policy_value = policies.GetValue(policy_key_); 92 const base::Value* policy_value = policies.GetValue(policy_key_);
81 93
82 std::string onc_blob; 94 std::string onc_blob;
83 if (!policy_value) 95 if (!policy_value)
84 VLOG(2) << LogHeader() << " is not set."; 96 VLOG(2) << LogHeader() << " is not set.";
85 else if (!policy_value->GetAsString(&onc_blob)) 97 else if (!policy_value->GetAsString(&onc_blob))
86 LOG(ERROR) << LogHeader() << " is not a string value."; 98 LOG(ERROR) << LogHeader() << " is not a string value.";
87 99
88 base::ListValue network_configs; 100 base::ListValue network_configs;
89 base::DictionaryValue global_network_config; 101 base::DictionaryValue global_network_config;
90 base::ListValue certificates; 102 base::ListValue certificates;
91 chromeos::onc::ParseAndValidateOncForImport(onc_blob, 103 chromeos::onc::ParseAndValidateOncForImport(onc_blob,
92 onc_source_, 104 onc_source_,
93 "" /* no passphrase */, 105 "" /* no passphrase */,
94 &network_configs, 106 &network_configs,
95 &global_network_config, 107 &global_network_config,
96 &certificates); 108 &certificates);
97 109
98 ImportCertificates(certificates); 110 if (cert_database_)
111 ImportCertificates(certificates, cert_database_);
99 ApplyNetworkPolicy(&network_configs, &global_network_config); 112 ApplyNetworkPolicy(&network_configs, &global_network_config);
100 } 113 }
101 114
102 std::string NetworkConfigurationUpdater::LogHeader() const { 115 std::string NetworkConfigurationUpdater::LogHeader() const {
103 return chromeos::onc::GetSourceAsString(onc_source_); 116 return chromeos::onc::GetSourceAsString(onc_source_);
104 } 117 }
105 118
106 } // namespace policy 119 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698