| 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/time/time.h" | |
| 16 #include "base/values.h" | 15 #include "base/values.h" |
| 17 #include "remoting/host/dns_blackhole_checker.h" | 16 #include "remoting/host/dns_blackhole_checker.h" |
| 18 | 17 |
| 19 #if !defined(NDEBUG) | 18 #if !defined(NDEBUG) |
| 20 #include "base/json/json_reader.h" | 19 #include "base/json/json_reader.h" |
| 21 #endif | 20 #endif |
| 22 | 21 |
| 23 namespace remoting { | 22 namespace remoting { |
| 24 namespace policy_hack { | 23 namespace policy_hack { |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 | 26 |
| 28 // The time interval for rechecking policy. This is our fallback in case the | |
| 29 // delegate never reports a change to the ReloadObserver. | |
| 30 const int kFallbackReloadDelayMinutes = 15; | |
| 31 | |
| 32 // Copies all policy values from one dictionary to another, using values from | 27 // Copies all policy values from one dictionary to another, using values from |
| 33 // |default| if they are not set in |from|, or values from |bad_type_values| if | 28 // |default| if they are not set in |from|, or values from |bad_type_values| if |
| 34 // the value in |from| has the wrong type. | 29 // the value in |from| has the wrong type. |
| 35 scoped_ptr<base::DictionaryValue> CopyGoodValuesAndAddDefaults( | 30 scoped_ptr<base::DictionaryValue> CopyGoodValuesAndAddDefaults( |
| 36 const base::DictionaryValue* from, | 31 const base::DictionaryValue* from, |
| 37 const base::DictionaryValue* default_values, | 32 const base::DictionaryValue* default_values, |
| 38 const base::DictionaryValue* bad_type_values) { | 33 const base::DictionaryValue* bad_type_values) { |
| 39 scoped_ptr<base::DictionaryValue> to(default_values->DeepCopy()); | 34 scoped_ptr<base::DictionaryValue> to(default_values->DeepCopy()); |
| 40 for (base::DictionaryValue::Iterator i(*default_values); | 35 for (base::DictionaryValue::Iterator i(*default_values); |
| 41 !i.IsAtEnd(); i.Advance()) { | 36 !i.IsAtEnd(); i.Advance()) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 const char PolicyWatcher::kRelayPolicyName[] = | 104 const char PolicyWatcher::kRelayPolicyName[] = |
| 110 "RemoteAccessHostAllowRelayedConnection"; | 105 "RemoteAccessHostAllowRelayedConnection"; |
| 111 | 106 |
| 112 const char PolicyWatcher::kUdpPortRangePolicyName[] = | 107 const char PolicyWatcher::kUdpPortRangePolicyName[] = |
| 113 "RemoteAccessHostUdpPortRange"; | 108 "RemoteAccessHostUdpPortRange"; |
| 114 | 109 |
| 115 const char PolicyWatcher::kHostDebugOverridePoliciesName[] = | 110 const char PolicyWatcher::kHostDebugOverridePoliciesName[] = |
| 116 "RemoteAccessHostDebugOverridePolicies"; | 111 "RemoteAccessHostDebugOverridePolicies"; |
| 117 | 112 |
| 118 PolicyWatcher::PolicyWatcher( | 113 PolicyWatcher::PolicyWatcher( |
| 119 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 114 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
| 120 : task_runner_(task_runner), | 115 : task_runner_(task_runner), |
| 121 transient_policy_error_retry_counter_(0), | 116 transient_policy_error_retry_counter_(0), |
| 122 old_policies_(new base::DictionaryValue()), | 117 old_policies_(new base::DictionaryValue()), |
| 123 default_values_(new base::DictionaryValue()), | 118 default_values_(new base::DictionaryValue()), |
| 124 weak_factory_(this) { | 119 weak_factory_(this) { |
| 125 // Initialize the default values for each policy. | 120 // Initialize the default values for each policy. |
| 126 default_values_->SetBoolean(kNatPolicyName, true); | 121 default_values_->SetBoolean(kNatPolicyName, true); |
| 127 default_values_->SetBoolean(kHostRequireTwoFactorPolicyName, false); | 122 default_values_->SetBoolean(kHostRequireTwoFactorPolicyName, false); |
| 128 default_values_->SetBoolean(kHostRequireCurtainPolicyName, false); | 123 default_values_->SetBoolean(kHostRequireCurtainPolicyName, false); |
| 129 default_values_->SetBoolean(kHostMatchUsernamePolicyName, false); | 124 default_values_->SetBoolean(kHostMatchUsernamePolicyName, false); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 stopped_callback); | 171 stopped_callback); |
| 177 } | 172 } |
| 178 | 173 |
| 179 void PolicyWatcher::StopWatchingOnPolicyWatcherThread() { | 174 void PolicyWatcher::StopWatchingOnPolicyWatcherThread() { |
| 180 StopWatchingInternal(); | 175 StopWatchingInternal(); |
| 181 weak_factory_.InvalidateWeakPtrs(); | 176 weak_factory_.InvalidateWeakPtrs(); |
| 182 policy_updated_callback_.Reset(); | 177 policy_updated_callback_.Reset(); |
| 183 policy_error_callback_.Reset(); | 178 policy_error_callback_.Reset(); |
| 184 } | 179 } |
| 185 | 180 |
| 186 void PolicyWatcher::ScheduleFallbackReloadTask() { | |
| 187 DCHECK(OnPolicyWatcherThread()); | |
| 188 ScheduleReloadTask( | |
| 189 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes)); | |
| 190 } | |
| 191 | |
| 192 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) { | |
| 193 DCHECK(OnPolicyWatcherThread()); | |
| 194 task_runner_->PostDelayedTask( | |
| 195 FROM_HERE, | |
| 196 base::Bind(&PolicyWatcher::Reload, weak_factory_.GetWeakPtr()), | |
| 197 delay); | |
| 198 } | |
| 199 | |
| 200 const base::DictionaryValue& PolicyWatcher::Defaults() const { | 181 const base::DictionaryValue& PolicyWatcher::Defaults() const { |
| 201 return *default_values_; | 182 return *default_values_; |
| 202 } | 183 } |
| 203 | 184 |
| 204 bool PolicyWatcher::OnPolicyWatcherThread() const { | 185 bool PolicyWatcher::OnPolicyWatcherThread() const { |
| 205 return task_runner_->BelongsToCurrentThread(); | 186 return task_runner_->BelongsToCurrentThread(); |
| 206 } | 187 } |
| 207 | 188 |
| 208 void PolicyWatcher::UpdatePolicies( | 189 void PolicyWatcher::UpdatePolicies( |
| 209 const base::DictionaryValue* new_policies_raw) { | 190 const base::DictionaryValue* new_policies_raw) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 void PolicyWatcher::SignalTransientPolicyError() { | 227 void PolicyWatcher::SignalTransientPolicyError() { |
| 247 const int kMaxRetryCount = 5; | 228 const int kMaxRetryCount = 5; |
| 248 transient_policy_error_retry_counter_ += 1; | 229 transient_policy_error_retry_counter_ += 1; |
| 249 if (transient_policy_error_retry_counter_ >= kMaxRetryCount) { | 230 if (transient_policy_error_retry_counter_ >= kMaxRetryCount) { |
| 250 SignalPolicyError(); | 231 SignalPolicyError(); |
| 251 } | 232 } |
| 252 } | 233 } |
| 253 | 234 |
| 254 } // namespace policy_hack | 235 } // namespace policy_hack |
| 255 } // namespace remoting | 236 } // namespace remoting |
| OLD | NEW |