| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Most of this code is copied from: | 5 // Most of this code is copied from: |
| 6 // src/chrome/browser/policy/asynchronous_policy_loader.{h,cc} | 6 // src/chrome/browser/policy/asynchronous_policy_loader.{h,cc} |
| 7 | 7 |
| 8 #include "remoting/host/policy_watcher.h" | 8 #include "remoting/host/policy_watcher.h" |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // policies (expecting perf and maintanability improvement, but no functional | 78 // policies (expecting perf and maintanability improvement, but no functional |
| 79 // impact). | 79 // impact). |
| 80 policy::Schema schema = policy::Schema::Wrap(policy::GetChromeSchemaData()); | 80 policy::Schema schema = policy::Schema::Wrap(policy::GetChromeSchemaData()); |
| 81 | 81 |
| 82 std::unique_ptr<policy::SchemaRegistry> schema_registry( | 82 std::unique_ptr<policy::SchemaRegistry> schema_registry( |
| 83 new policy::SchemaRegistry()); | 83 new policy::SchemaRegistry()); |
| 84 schema_registry->RegisterComponent(GetPolicyNamespace(), schema); | 84 schema_registry->RegisterComponent(GetPolicyNamespace(), schema); |
| 85 return schema_registry; | 85 return schema_registry; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void RetrievePoliciesByNamePrefix(const policy::PolicyMap& current_policies, |
| 89 const std::string& policy_name_prefix, |
| 90 base::DictionaryValue* policy_dict) { |
| 91 for (const auto& policy_entry : current_policies) { |
| 92 const std::string& key = policy_entry.first; |
| 93 const base::Value* value = policy_entry.second.value.get(); |
| 94 |
| 95 if (key.find(policy_name_prefix) != std::string::npos) { |
| 96 policy_dict->Set(key, value->CreateDeepCopy()); |
| 97 } |
| 98 } |
| 99 } |
| 100 |
| 88 std::unique_ptr<base::DictionaryValue> CopyChromotingPoliciesIntoDictionary( | 101 std::unique_ptr<base::DictionaryValue> CopyChromotingPoliciesIntoDictionary( |
| 89 const policy::PolicyMap& current) { | 102 const policy::PolicyMap& current) { |
| 90 const char kPolicyNameSubstring[] = "RemoteAccessHost"; | 103 const char kRemoteAccessHostPolicyNamePrefix[] = "RemoteAccessHost"; |
| 104 const char kRemoteAssistanceHostPolicyNamePrefix[] = "RemoteAssistanceHost"; |
| 91 std::unique_ptr<base::DictionaryValue> policy_dict( | 105 std::unique_ptr<base::DictionaryValue> policy_dict( |
| 92 new base::DictionaryValue()); | 106 new base::DictionaryValue()); |
| 93 for (const auto& entry : current) { | |
| 94 const std::string& key = entry.first; | |
| 95 const base::Value* value = entry.second.value.get(); | |
| 96 | 107 |
| 97 // Copying only Chromoting-specific policies helps avoid false alarms | 108 // Copying only Chromoting-specific policies helps avoid false alarms raised |
| 98 // raised by NormalizePolicies below (such alarms shutdown the host). | 109 // by NormalizePolicies below (such alarms shutdown the host). |
| 99 // TODO(lukasza): Removing this somewhat brittle filtering will be possible | 110 // TODO(lukasza): Removing this somewhat brittle filtering will be possible |
| 100 // after having separate, Chromoting-specific schema. | 111 // after having separate, Chromoting-specific schema. |
| 101 if (key.find(kPolicyNameSubstring) != std::string::npos) { | 112 RetrievePoliciesByNamePrefix(current, kRemoteAccessHostPolicyNamePrefix, |
| 102 policy_dict->Set(key, value->CreateDeepCopy()); | 113 policy_dict.get()); |
| 103 } | 114 RetrievePoliciesByNamePrefix(current, kRemoteAssistanceHostPolicyNamePrefix, |
| 104 } | 115 policy_dict.get()); |
| 105 | 116 |
| 106 return policy_dict; | 117 return policy_dict; |
| 107 } | 118 } |
| 108 | 119 |
| 109 // Takes a dictionary containing only 1) recognized policy names and 2) | 120 // Takes a dictionary containing only 1) recognized policy names and 2) |
| 110 // well-typed policy values and further verifies policy contents. | 121 // well-typed policy values and further verifies policy contents. |
| 111 bool VerifyWellformedness(const base::DictionaryValue& changed_policies) { | 122 bool VerifyWellformedness(const base::DictionaryValue& changed_policies) { |
| 112 // Verify ThirdPartyAuthConfig policy. | 123 // Verify ThirdPartyAuthConfig policy. |
| 113 ThirdPartyAuthConfig not_used; | 124 ThirdPartyAuthConfig not_used; |
| 114 switch (ThirdPartyAuthConfig::Parse(changed_policies, ¬_used)) { | 125 switch (ThirdPartyAuthConfig::Parse(changed_policies, ¬_used)) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 default_values_->SetString(key::kRemoteAccessHostTokenUrl, std::string()); | 199 default_values_->SetString(key::kRemoteAccessHostTokenUrl, std::string()); |
| 189 default_values_->SetString(key::kRemoteAccessHostTokenValidationUrl, | 200 default_values_->SetString(key::kRemoteAccessHostTokenValidationUrl, |
| 190 std::string()); | 201 std::string()); |
| 191 default_values_->SetString( | 202 default_values_->SetString( |
| 192 key::kRemoteAccessHostTokenValidationCertificateIssuer, std::string()); | 203 key::kRemoteAccessHostTokenValidationCertificateIssuer, std::string()); |
| 193 default_values_->SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); | 204 default_values_->SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); |
| 194 default_values_->SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); | 205 default_values_->SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); |
| 195 default_values_->SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, | 206 default_values_->SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, |
| 196 true); | 207 true); |
| 197 default_values_->SetString(key::kRemoteAccessHostUdpPortRange, ""); | 208 default_values_->SetString(key::kRemoteAccessHostUdpPortRange, ""); |
| 209 default_values_->SetBoolean(key::kRemoteAssistanceHostAllowUiAccess, false); |
| 198 } | 210 } |
| 199 | 211 |
| 200 PolicyWatcher::~PolicyWatcher() { | 212 PolicyWatcher::~PolicyWatcher() { |
| 201 // Stop observing |policy_service_| if StartWatching() has been called. | 213 // Stop observing |policy_service_| if StartWatching() has been called. |
| 202 if (!policy_updated_callback_.is_null()) { | 214 if (!policy_updated_callback_.is_null()) { |
| 203 policy_service_->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this); | 215 policy_service_->RemoveObserver(policy::POLICY_DOMAIN_CHROME, this); |
| 204 } | 216 } |
| 205 | 217 |
| 206 if (owned_policy_provider_) { | 218 if (owned_policy_provider_) { |
| 207 owned_policy_provider_->Shutdown(); | 219 owned_policy_provider_->Shutdown(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 CreateSchemaRegistry())); | 394 CreateSchemaRegistry())); |
| 383 #else | 395 #else |
| 384 #error OS that is not yet supported by PolicyWatcher code. | 396 #error OS that is not yet supported by PolicyWatcher code. |
| 385 #endif | 397 #endif |
| 386 | 398 |
| 387 return PolicyWatcher::CreateFromPolicyLoader(std::move(policy_loader)); | 399 return PolicyWatcher::CreateFromPolicyLoader(std::move(policy_loader)); |
| 388 #endif // !(OS_CHROMEOS) | 400 #endif // !(OS_CHROMEOS) |
| 389 } | 401 } |
| 390 | 402 |
| 391 } // namespace remoting | 403 } // namespace remoting |
| OLD | NEW |