| 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 // 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_hack/policy_watcher.h" | 8 #include "remoting/host/policy_hack/policy_watcher.h" |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "remoting/host/constants.h" |
| 18 | 19 |
| 19 namespace remoting { | 20 namespace remoting { |
| 20 namespace policy_hack { | 21 namespace policy_hack { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 // The time interval for rechecking policy. This is our fallback in case the | 24 // The time interval for rechecking policy. This is our fallback in case the |
| 24 // delegate never reports a change to the ReloadObserver. | 25 // delegate never reports a change to the ReloadObserver. |
| 25 const int kFallbackReloadDelayMinutes = 15; | 26 const int kFallbackReloadDelayMinutes = 15; |
| 26 | 27 |
| 27 // Gets a boolean from a dictionary, or returns a default value if the boolean | 28 // Gets a boolean from a dictionary, or returns a default value if the boolean |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 83 } |
| 83 | 84 |
| 84 // Copies all policy values from one dictionary to another, using default values | 85 // Copies all policy values from one dictionary to another, using default values |
| 85 // when necessary. | 86 // when necessary. |
| 86 scoped_ptr<base::DictionaryValue> AddDefaultValuesWhenNecessary( | 87 scoped_ptr<base::DictionaryValue> AddDefaultValuesWhenNecessary( |
| 87 const base::DictionaryValue* from) { | 88 const base::DictionaryValue* from) { |
| 88 scoped_ptr<base::DictionaryValue> to(new base::DictionaryValue()); | 89 scoped_ptr<base::DictionaryValue> to(new base::DictionaryValue()); |
| 89 CopyBooleanOrDefault(to.get(), from, | 90 CopyBooleanOrDefault(to.get(), from, |
| 90 PolicyWatcher::kNatPolicyName, true, false); | 91 PolicyWatcher::kNatPolicyName, true, false); |
| 91 CopyBooleanOrDefault(to.get(), from, | 92 CopyBooleanOrDefault(to.get(), from, |
| 92 PolicyWatcher::kRequireTwoFactorPolicyName, | 93 PolicyWatcher::kHostRequireTwoFactorPolicyName, |
| 93 false, false); | 94 false, false); |
| 94 CopyStringOrDefault(to.get(), from, | 95 CopyStringOrDefault(to.get(), from, |
| 95 PolicyWatcher::kHostDomainPolicyName, "", ""); | 96 PolicyWatcher::kHostDomainPolicyName, "", ""); |
| 96 CopyStringOrDefault(to.get(), from, | 97 CopyStringOrDefault(to.get(), from, |
| 97 PolicyWatcher::kTalkGadgetPolicyName, | 98 PolicyWatcher::kHostTalkGadgetPrefixPolicyName, |
| 98 "chromoting", "chromoting"); | 99 kDefaultTalkGadgetPrefix, kDefaultTalkGadgetPrefix); |
| 99 | 100 |
| 100 return to.Pass(); | 101 return to.Pass(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 } // namespace | 104 } // namespace |
| 104 | 105 |
| 105 const char PolicyWatcher::kNatPolicyName[] = | 106 const char PolicyWatcher::kNatPolicyName[] = |
| 106 "RemoteAccessHostFirewallTraversal"; | 107 "RemoteAccessHostFirewallTraversal"; |
| 107 | 108 |
| 108 const char PolicyWatcher::kRequireTwoFactorPolicyName[] = | 109 const char PolicyWatcher::kHostRequireTwoFactorPolicyName[] = |
| 109 "RemoteAccessHostRequireTwoFactor"; | 110 "RemoteAccessHostRequireTwoFactor"; |
| 110 | 111 |
| 111 const char PolicyWatcher::kHostDomainPolicyName[] = | 112 const char PolicyWatcher::kHostDomainPolicyName[] = |
| 112 "RemoteAccessHostDomain"; | 113 "RemoteAccessHostDomain"; |
| 113 | 114 |
| 114 const char PolicyWatcher::kTalkGadgetPolicyName[] = | 115 const char PolicyWatcher::kHostTalkGadgetPrefixPolicyName[] = |
| 115 "RemoteAccessHostTalkGadget"; | 116 "RemoteAccessHostTalkGadgetPrefix"; |
| 116 | 117 |
| 117 const char* const PolicyWatcher::kBooleanPolicyNames[] = | 118 const char* const PolicyWatcher::kBooleanPolicyNames[] = |
| 118 { PolicyWatcher::kNatPolicyName, | 119 { PolicyWatcher::kNatPolicyName, |
| 119 PolicyWatcher::kRequireTwoFactorPolicyName | 120 PolicyWatcher::kHostRequireTwoFactorPolicyName |
| 120 }; | 121 }; |
| 121 | 122 |
| 122 const int PolicyWatcher::kBooleanPolicyNamesNum = | 123 const int PolicyWatcher::kBooleanPolicyNamesNum = |
| 123 arraysize(kBooleanPolicyNames); | 124 arraysize(kBooleanPolicyNames); |
| 124 | 125 |
| 125 const char* const PolicyWatcher::kStringPolicyNames[] = | 126 const char* const PolicyWatcher::kStringPolicyNames[] = |
| 126 { PolicyWatcher::kHostDomainPolicyName, | 127 { PolicyWatcher::kHostDomainPolicyName, |
| 127 PolicyWatcher::kTalkGadgetPolicyName | 128 PolicyWatcher::kHostTalkGadgetPrefixPolicyName |
| 128 }; | 129 }; |
| 129 | 130 |
| 130 const int PolicyWatcher::kStringPolicyNamesNum = | 131 const int PolicyWatcher::kStringPolicyNamesNum = |
| 131 arraysize(kStringPolicyNames); | 132 arraysize(kStringPolicyNames); |
| 132 | 133 |
| 133 PolicyWatcher::PolicyWatcher( | 134 PolicyWatcher::PolicyWatcher( |
| 134 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 135 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 135 : task_runner_(task_runner), | 136 : task_runner_(task_runner), |
| 136 old_policies_(new base::DictionaryValue()), | 137 old_policies_(new base::DictionaryValue()), |
| 137 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 138 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 old_policies_.swap(new_policies); | 212 old_policies_.swap(new_policies); |
| 212 | 213 |
| 213 // Notify our client of the changed policies. | 214 // Notify our client of the changed policies. |
| 214 if (!changed_policies->empty()) { | 215 if (!changed_policies->empty()) { |
| 215 policy_callback_.Run(changed_policies.Pass()); | 216 policy_callback_.Run(changed_policies.Pass()); |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 | 219 |
| 219 } // namespace policy_hack | 220 } // namespace policy_hack |
| 220 } // namespace remoting | 221 } // namespace remoting |
| OLD | NEW |