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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 namespace key = ::policy::key; | 46 namespace key = ::policy::key; |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 // Copies all policy values from one dictionary to another, using values from | 50 // Copies all policy values from one dictionary to another, using values from |
51 // |default_values| if they are not set in |from|. | 51 // |default_values| if they are not set in |from|. |
52 std::unique_ptr<base::DictionaryValue> CopyValuesAndAddDefaults( | 52 std::unique_ptr<base::DictionaryValue> CopyValuesAndAddDefaults( |
53 const base::DictionaryValue& from, | 53 const base::DictionaryValue& from, |
54 const base::DictionaryValue& default_values) { | 54 const base::DictionaryValue& default_values) { |
55 std::unique_ptr<base::DictionaryValue> to(default_values.DeepCopy()); | 55 std::unique_ptr<base::DictionaryValue> to(default_values.CreateDeepCopy()); |
56 for (base::DictionaryValue::Iterator i(default_values); !i.IsAtEnd(); | 56 for (base::DictionaryValue::Iterator i(default_values); !i.IsAtEnd(); |
57 i.Advance()) { | 57 i.Advance()) { |
58 const base::Value* value = nullptr; | 58 const base::Value* value = nullptr; |
59 | 59 |
60 // If the policy isn't in |from|, use the default. | 60 // If the policy isn't in |from|, use the default. |
61 if (!from.Get(i.key(), &value)) { | 61 if (!from.Get(i.key(), &value)) { |
62 continue; | 62 continue; |
63 } | 63 } |
64 | 64 |
65 CHECK(value->IsType(i.value().GetType())); | 65 CHECK(value->IsType(i.value().GetType())); |
66 to->Set(i.key(), value->DeepCopy()); | 66 to->Set(i.key(), value->CreateDeepCopy()); |
67 } | 67 } |
68 | 68 |
69 return to; | 69 return to; |
70 } | 70 } |
71 | 71 |
72 policy::PolicyNamespace GetPolicyNamespace() { | 72 policy::PolicyNamespace GetPolicyNamespace() { |
73 return policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string()); | 73 return policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string()); |
74 } | 74 } |
75 | 75 |
76 std::unique_ptr<policy::SchemaRegistry> CreateSchemaRegistry() { | 76 std::unique_ptr<policy::SchemaRegistry> CreateSchemaRegistry() { |
(...skipping 15 matching lines...) Expand all Loading... |
92 new base::DictionaryValue()); | 92 new base::DictionaryValue()); |
93 for (auto it = current.begin(); it != current.end(); ++it) { | 93 for (auto it = current.begin(); it != current.end(); ++it) { |
94 const std::string& key = it->first; | 94 const std::string& key = it->first; |
95 const base::Value* value = it->second.value; | 95 const base::Value* value = it->second.value; |
96 | 96 |
97 // Copying only Chromoting-specific policies helps avoid false alarms | 97 // Copying only Chromoting-specific policies helps avoid false alarms |
98 // raised by NormalizePolicies below (such alarms shutdown the host). | 98 // raised by NormalizePolicies below (such alarms shutdown the host). |
99 // TODO(lukasza): Removing this somewhat brittle filtering will be possible | 99 // TODO(lukasza): Removing this somewhat brittle filtering will be possible |
100 // after having separate, Chromoting-specific schema. | 100 // after having separate, Chromoting-specific schema. |
101 if (key.find(kPolicyNameSubstring) != std::string::npos) { | 101 if (key.find(kPolicyNameSubstring) != std::string::npos) { |
102 policy_dict->Set(key, value->DeepCopy()); | 102 policy_dict->Set(key, value->CreateDeepCopy()); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 return policy_dict; | 106 return policy_dict; |
107 } | 107 } |
108 | 108 |
109 // Takes a dictionary containing only 1) recognized policy names and 2) | 109 // Takes a dictionary containing only 1) recognized policy names and 2) |
110 // well-typed policy values and further verifies policy contents. | 110 // well-typed policy values and further verifies policy contents. |
111 bool VerifyWellformedness(const base::DictionaryValue& changed_policies) { | 111 bool VerifyWellformedness(const base::DictionaryValue& changed_policies) { |
112 // Verify ThirdPartyAuthConfig policy. | 112 // Verify ThirdPartyAuthConfig policy. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return false; | 236 return false; |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 namespace { | 240 namespace { |
241 void CopyDictionaryValue(const base::DictionaryValue& from, | 241 void CopyDictionaryValue(const base::DictionaryValue& from, |
242 base::DictionaryValue& to, | 242 base::DictionaryValue& to, |
243 std::string key) { | 243 std::string key) { |
244 const base::Value* value; | 244 const base::Value* value; |
245 if (from.Get(key, &value)) { | 245 if (from.Get(key, &value)) { |
246 to.Set(key, value->DeepCopy()); | 246 to.Set(key, value->CreateDeepCopy()); |
247 } | 247 } |
248 } | 248 } |
249 } // namespace | 249 } // namespace |
250 | 250 |
251 std::unique_ptr<base::DictionaryValue> | 251 std::unique_ptr<base::DictionaryValue> |
252 PolicyWatcher::StoreNewAndReturnChangedPolicies( | 252 PolicyWatcher::StoreNewAndReturnChangedPolicies( |
253 std::unique_ptr<base::DictionaryValue> new_policies) { | 253 std::unique_ptr<base::DictionaryValue> new_policies) { |
254 // Find the changed policies. | 254 // Find the changed policies. |
255 std::unique_ptr<base::DictionaryValue> changed_policies( | 255 std::unique_ptr<base::DictionaryValue> changed_policies( |
256 new base::DictionaryValue()); | 256 new base::DictionaryValue()); |
257 base::DictionaryValue::Iterator iter(*new_policies); | 257 base::DictionaryValue::Iterator iter(*new_policies); |
258 while (!iter.IsAtEnd()) { | 258 while (!iter.IsAtEnd()) { |
259 base::Value* old_policy; | 259 base::Value* old_policy; |
260 if (!(old_policies_->Get(iter.key(), &old_policy) && | 260 if (!(old_policies_->Get(iter.key(), &old_policy) && |
261 old_policy->Equals(&iter.value()))) { | 261 old_policy->Equals(&iter.value()))) { |
262 changed_policies->Set(iter.key(), iter.value().DeepCopy()); | 262 changed_policies->Set(iter.key(), iter.value().CreateDeepCopy()); |
263 } | 263 } |
264 iter.Advance(); | 264 iter.Advance(); |
265 } | 265 } |
266 | 266 |
267 // If one of ThirdPartyAuthConfig policies changed, we need to include all. | 267 // If one of ThirdPartyAuthConfig policies changed, we need to include all. |
268 if (changed_policies->HasKey(key::kRemoteAccessHostTokenUrl) || | 268 if (changed_policies->HasKey(key::kRemoteAccessHostTokenUrl) || |
269 changed_policies->HasKey(key::kRemoteAccessHostTokenValidationUrl) || | 269 changed_policies->HasKey(key::kRemoteAccessHostTokenValidationUrl) || |
270 changed_policies->HasKey( | 270 changed_policies->HasKey( |
271 key::kRemoteAccessHostTokenValidationCertificateIssuer)) { | 271 key::kRemoteAccessHostTokenValidationCertificateIssuer)) { |
272 CopyDictionaryValue(*new_policies, *changed_policies, | 272 CopyDictionaryValue(*new_policies, *changed_policies, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 CreateSchemaRegistry())); | 382 CreateSchemaRegistry())); |
383 #else | 383 #else |
384 #error OS that is not yet supported by PolicyWatcher code. | 384 #error OS that is not yet supported by PolicyWatcher code. |
385 #endif | 385 #endif |
386 | 386 |
387 return PolicyWatcher::CreateFromPolicyLoader(std::move(policy_loader)); | 387 return PolicyWatcher::CreateFromPolicyLoader(std::move(policy_loader)); |
388 #endif // !(OS_CHROMEOS) | 388 #endif // !(OS_CHROMEOS) |
389 } | 389 } |
390 | 390 |
391 } // namespace remoting | 391 } // namespace remoting |
OLD | NEW |