Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chromeos/network/policy_applicator.h" | 5 #include "chromeos/network/policy_applicator.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 const PolicyApplicator::GuidToPolicyMap& policies, | 36 const PolicyApplicator::GuidToPolicyMap& policies, |
| 37 const std::string& guid) { | 37 const std::string& guid) { |
| 38 PolicyApplicator::GuidToPolicyMap::const_iterator it = policies.find(guid); | 38 PolicyApplicator::GuidToPolicyMap::const_iterator it = policies.find(guid); |
| 39 if (it == policies.end()) | 39 if (it == policies.end()) |
| 40 return NULL; | 40 return NULL; |
| 41 return it->second; | 41 return it->second; |
| 42 } | 42 } |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 PolicyApplicator::PolicyApplicator(base::WeakPtr<ConfigurationHandler> handler, | 46 PolicyApplicator::PolicyApplicator( |
| 47 const NetworkProfile& profile, | 47 base::WeakPtr<ConfigurationHandler> handler, |
| 48 const GuidToPolicyMap& all_policies, | 48 const NetworkProfile& profile, |
| 49 std::set<std::string>* modified_policies) | 49 const GuidToPolicyMap& all_policies, |
| 50 const base::DictionaryValue& global_network_config, | |
| 51 std::set<std::string>* modified_policies) | |
| 50 : handler_(handler), profile_(profile) { | 52 : handler_(handler), profile_(profile) { |
| 53 global_network_config_.MergeDictionary(&global_network_config); | |
| 51 remaining_policies_.swap(*modified_policies); | 54 remaining_policies_.swap(*modified_policies); |
| 52 for (GuidToPolicyMap::const_iterator it = all_policies.begin(); | 55 for (GuidToPolicyMap::const_iterator it = all_policies.begin(); |
| 53 it != all_policies.end(); ++it) { | 56 it != all_policies.end(); ++it) { |
| 54 all_policies_.insert(std::make_pair(it->first, it->second->DeepCopy())); | 57 all_policies_.insert(std::make_pair(it->first, it->second->DeepCopy())); |
| 55 } | 58 } |
| 56 } | 59 } |
| 57 | 60 |
| 58 void PolicyApplicator::Run() { | 61 void PolicyApplicator::Run() { |
| 59 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties( | 62 DBusThreadManager::Get()->GetShillProfileClient()->GetProperties( |
| 60 dbus::ObjectPath(profile_.path), | 63 dbus::ObjectPath(profile_.path), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 } | 187 } |
| 185 } else if (was_managed) { | 188 } else if (was_managed) { |
| 186 VLOG(1) << "Removing configuration previously managed by policy " | 189 VLOG(1) << "Removing configuration previously managed by policy " |
| 187 << old_guid << ", because the policy was removed."; | 190 << old_guid << ", because the policy was removed."; |
| 188 | 191 |
| 189 // Remove the entry, because the network was managed but isn't anymore. | 192 // Remove the entry, because the network was managed but isn't anymore. |
| 190 // Note: An alternative might be to preserve the user settings, but it's | 193 // Note: An alternative might be to preserve the user settings, but it's |
| 191 // unclear which values originating the policy should be removed. | 194 // unclear which values originating the policy should be removed. |
| 192 DeleteEntry(entry); | 195 DeleteEntry(entry); |
| 193 } else { | 196 } else { |
| 194 VLOG(2) << "Ignore unmanaged entry."; | 197 // The entry wasn't managed and doesn't match any current policy. Global |
| 198 // network settings have to be applied. | |
| 195 | 199 |
| 196 // The entry wasn't managed and doesn't match any current policy. Thus | 200 base::DictionaryValue shill_properties_to_update; |
| 197 // leave it as it is. | 201 GetPropertiesForUnmanagedEntry(entry_properties, |
| 202 &shill_properties_to_update); | |
| 203 if (shill_properties_to_update.empty()) { | |
| 204 VLOG(2) << "Ignore unmanaged entry."; | |
| 205 } else { | |
| 206 VLOG(2) << "Apply global network config to unmanaged entry."; | |
| 207 handler_->UpdateExistingConfigurationWithPropertiesFromPolicy( | |
| 208 entry_properties, shill_properties_to_update); | |
| 209 } | |
| 198 } | 210 } |
| 199 } | 211 } |
| 200 | 212 |
| 201 void PolicyApplicator::DeleteEntry(const std::string& entry) { | 213 void PolicyApplicator::DeleteEntry(const std::string& entry) { |
| 202 DBusThreadManager::Get()->GetShillProfileClient()->DeleteEntry( | 214 DBusThreadManager::Get()->GetShillProfileClient()->DeleteEntry( |
| 203 dbus::ObjectPath(profile_.path), | 215 dbus::ObjectPath(profile_.path), |
| 204 entry, | 216 entry, |
| 205 base::Bind(&base::DoNothing), | 217 base::Bind(&base::DoNothing), |
| 206 base::Bind(&LogErrorMessage, FROM_HERE)); | 218 base::Bind(&LogErrorMessage, FROM_HERE)); |
| 207 } | 219 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 225 if (auth == ::onc::ethernet::kNone) | 237 if (auth == ::onc::ethernet::kNone) |
| 226 return; | 238 return; |
| 227 } | 239 } |
| 228 | 240 |
| 229 scoped_ptr<base::DictionaryValue> shill_dictionary = | 241 scoped_ptr<base::DictionaryValue> shill_dictionary = |
| 230 policy_util::CreateShillConfiguration( | 242 policy_util::CreateShillConfiguration( |
| 231 profile_, guid, &policy, user_settings); | 243 profile_, guid, &policy, user_settings); |
| 232 handler_->CreateConfigurationFromPolicy(*shill_dictionary); | 244 handler_->CreateConfigurationFromPolicy(*shill_dictionary); |
| 233 } | 245 } |
| 234 | 246 |
| 247 void PolicyApplicator::GetPropertiesForUnmanagedEntry( | |
|
bartfab (slow)
2013/10/16 12:40:31
Could you comment this method a bit? It was not cl
pneubeck (no reviews)
2013/10/17 10:22:26
Done.
| |
| 248 const base::DictionaryValue& entry_properties, | |
| 249 base::DictionaryValue* properties_to_update) const { | |
| 250 // kAllowAutoconnect is currently the only global config. | |
| 251 | |
| 252 std::string type; | |
| 253 entry_properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); | |
| 254 if (NetworkTypePattern::Ethernet().MatchesType(type)) | |
| 255 return; // Autoconnect for Ethernet cannot be configured. | |
|
bartfab (slow)
2013/10/16 12:40:31
Nit: There should be two spaces before a trailing
pneubeck (no reviews)
2013/10/17 10:22:26
Done.
| |
| 256 | |
| 257 bool autoconnect_allowed = true; | |
| 258 global_network_config_.GetBooleanWithoutPathExpansion( | |
| 259 ::onc::global_network_config::kAllowAutoconnect, &autoconnect_allowed); | |
| 260 if (autoconnect_allowed) | |
| 261 return; | |
| 262 | |
| 263 bool old_autoconnect = false; | |
| 264 entry_properties.GetBooleanWithoutPathExpansion(shill::kAutoConnectProperty, | |
|
pneubeck (no reviews)
2013/10/16 12:38:20
if entry doesn't exist, we have to set to false ex
pneubeck (no reviews)
2013/10/17 10:22:26
Done.
| |
| 265 &old_autoconnect); | |
| 266 if (old_autoconnect) { | |
| 267 properties_to_update->SetBooleanWithoutPathExpansion( | |
| 268 shill::kAutoConnectProperty, false); | |
| 269 } | |
| 270 } | |
| 271 | |
| 235 PolicyApplicator::~PolicyApplicator() { | 272 PolicyApplicator::~PolicyApplicator() { |
| 236 ApplyRemainingPolicies(); | 273 ApplyRemainingPolicies(); |
| 237 STLDeleteValues(&all_policies_); | 274 STLDeleteValues(&all_policies_); |
| 238 } | 275 } |
| 239 | 276 |
| 240 void PolicyApplicator::ApplyRemainingPolicies() { | 277 void PolicyApplicator::ApplyRemainingPolicies() { |
| 241 if (!handler_) { | 278 if (!handler_) { |
| 242 LOG(WARNING) << "Handler destructed during policy application to profile " | 279 LOG(WARNING) << "Handler destructed during policy application to profile " |
| 243 << profile_.ToDebugString(); | 280 << profile_.ToDebugString(); |
| 244 return; | 281 return; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 259 | 296 |
| 260 VLOG(1) << "Creating new configuration managed by policy " << *it | 297 VLOG(1) << "Creating new configuration managed by policy " << *it |
| 261 << " in profile " << profile_.ToDebugString() << "."; | 298 << " in profile " << profile_.ToDebugString() << "."; |
| 262 | 299 |
| 263 CreateAndWriteNewShillConfiguration( | 300 CreateAndWriteNewShillConfiguration( |
| 264 *it, *policy, NULL /* no user settings */); | 301 *it, *policy, NULL /* no user settings */); |
| 265 } | 302 } |
| 266 } | 303 } |
| 267 | 304 |
| 268 } // namespace chromeos | 305 } // namespace chromeos |
| OLD | NEW |