OLD | NEW |
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/policy/network_configuration_updater.h" | 5 #include "chrome/browser/policy/network_configuration_updater.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 NetworkConfigurationUpdater::~NetworkConfigurationUpdater() { | 46 NetworkConfigurationUpdater::~NetworkConfigurationUpdater() { |
47 network_library_->RemoveNetworkProfileObserver(this); | 47 network_library_->RemoveNetworkProfileObserver(this); |
48 } | 48 } |
49 | 49 |
50 void NetworkConfigurationUpdater::OnProfileListChanged() { | 50 void NetworkConfigurationUpdater::OnProfileListChanged() { |
51 VLOG(1) << "Network profile list changed, applying policies."; | 51 VLOG(1) << "Network profile list changed, applying policies."; |
52 ApplyNetworkConfigurations(); | 52 ApplyNetworkConfigurations(); |
53 } | 53 } |
54 | 54 |
55 void NetworkConfigurationUpdater::OnUserPolicyInitialized() { | 55 void NetworkConfigurationUpdater::OnUserPolicyInitialized() { |
56 VLOG(1) << "User policy initialized, applying policies. Ignoring."; | 56 VLOG(1) << "User policy initialized, applying policies."; |
57 user_policy_initialized_ = true; | 57 user_policy_initialized_ = true; |
58 ApplyNetworkConfigurations(); | 58 ApplyNetworkConfigurations(); |
59 } | 59 } |
60 | 60 |
61 void NetworkConfigurationUpdater::OnPolicyChanged( | 61 void NetworkConfigurationUpdater::OnPolicyChanged( |
62 chromeos::onc::ONCSource onc_source, | 62 chromeos::onc::ONCSource onc_source, |
63 const base::Value* previous, | 63 const base::Value* previous, |
64 const base::Value* current) { | 64 const base::Value* current) { |
65 VLOG(1) << "Policy for ONC source " << onc_source << " changed."; | 65 VLOG(1) << "Policy for ONC source " |
| 66 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; |
66 ApplyNetworkConfigurations(); | 67 ApplyNetworkConfigurations(); |
67 } | 68 } |
68 | 69 |
69 void NetworkConfigurationUpdater::ApplyNetworkConfigurations() { | 70 void NetworkConfigurationUpdater::ApplyNetworkConfigurations() { |
70 ApplyNetworkConfiguration(key::kDeviceOpenNetworkConfiguration, | 71 ApplyNetworkConfiguration(key::kDeviceOpenNetworkConfiguration, |
71 chromeos::onc::ONC_SOURCE_DEVICE_POLICY); | 72 chromeos::onc::ONC_SOURCE_DEVICE_POLICY); |
72 if (user_policy_initialized_) { | 73 if (user_policy_initialized_) { |
73 ApplyNetworkConfiguration(key::kOpenNetworkConfiguration, | 74 ApplyNetworkConfiguration(key::kOpenNetworkConfiguration, |
74 chromeos::onc::ONC_SOURCE_USER_POLICY); | 75 chromeos::onc::ONC_SOURCE_USER_POLICY); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 void NetworkConfigurationUpdater::ApplyNetworkConfiguration( | 79 void NetworkConfigurationUpdater::ApplyNetworkConfiguration( |
79 const std::string& policy_key, | 80 const std::string& policy_key, |
80 chromeos::onc::ONCSource onc_source) { | 81 chromeos::onc::ONCSource onc_source) { |
81 VLOG(1) << "Apply policy for ONC source " << onc_source; | 82 VLOG(1) << "Apply policy for ONC source " |
| 83 << chromeos::onc::GetSourceAsString(onc_source); |
82 const PolicyMap& policies = policy_service_->GetPolicies(POLICY_DOMAIN_CHROME, | 84 const PolicyMap& policies = policy_service_->GetPolicies(POLICY_DOMAIN_CHROME, |
83 std::string()); | 85 std::string()); |
84 const base::Value* policy_value = policies.GetValue(policy_key); | 86 const base::Value* policy_value = policies.GetValue(policy_key); |
85 | 87 |
86 std::string new_network_config; | 88 std::string new_network_config; |
87 if (policy_value != NULL) { | 89 if (policy_value != NULL) { |
88 // If the policy is not a string, we issue a warning, but still clear the | 90 // If the policy is not a string, we issue a warning, but still clear the |
89 // network configuration. | 91 // network configuration. |
90 if (!policy_value->GetAsString(&new_network_config)) | 92 if (!policy_value->GetAsString(&new_network_config)) { |
91 LOG(WARNING) << "ONC policy is not a string value."; | 93 LOG(WARNING) << "ONC policy for source " |
| 94 << chromeos::onc::GetSourceAsString(onc_source) |
| 95 << " is not a string value."; |
| 96 } |
92 } | 97 } |
93 | 98 |
94 // An empty string is not a valid ONC and generates warnings and | 99 // An empty string is not a valid ONC and generates warnings and |
95 // errors. Replace by a valid empty configuration. | 100 // errors. Replace by a valid empty configuration. |
96 if (new_network_config.empty()) | 101 if (new_network_config.empty()) |
97 new_network_config = chromeos::onc::kEmptyUnencryptedConfiguration; | 102 new_network_config = chromeos::onc::kEmptyUnencryptedConfiguration; |
98 | 103 |
99 network_library_->LoadOncNetworks(new_network_config, "", onc_source, | 104 if (!network_library_->LoadOncNetworks(new_network_config, "", onc_source, |
100 allow_web_trust_); | 105 allow_web_trust_)) { |
| 106 LOG(ERROR) << "Errors occurred during the ONC policy application."; |
| 107 } |
101 } | 108 } |
102 | 109 |
103 } // namespace policy | 110 } // namespace policy |
OLD | NEW |