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 "policy/policy_constants.h" | 16 #include "policy/policy_constants.h" |
18 #include "remoting/host/dns_blackhole_checker.h" | 17 #include "remoting/host/dns_blackhole_checker.h" |
19 | 18 |
20 #if !defined(NDEBUG) | 19 #if !defined(NDEBUG) |
21 #include "base/json/json_reader.h" | 20 #include "base/json/json_reader.h" |
22 #endif | 21 #endif |
23 | 22 |
24 namespace remoting { | 23 namespace remoting { |
25 namespace policy_hack { | 24 namespace policy_hack { |
26 | 25 |
27 namespace { | 26 namespace { |
28 | 27 |
29 // The time interval for rechecking policy. This is our fallback in case the | |
30 // delegate never reports a change to the ReloadObserver. | |
31 const int kFallbackReloadDelayMinutes = 15; | |
32 | |
33 // Copies all policy values from one dictionary to another, using values from | 28 // Copies all policy values from one dictionary to another, using values from |
34 // |default| if they are not set in |from|, or values from |bad_type_values| if | 29 // |default| if they are not set in |from|, or values from |bad_type_values| if |
35 // the value in |from| has the wrong type. | 30 // the value in |from| has the wrong type. |
36 scoped_ptr<base::DictionaryValue> CopyGoodValuesAndAddDefaults( | 31 scoped_ptr<base::DictionaryValue> CopyGoodValuesAndAddDefaults( |
37 const base::DictionaryValue* from, | 32 const base::DictionaryValue* from, |
38 const base::DictionaryValue* default_values, | 33 const base::DictionaryValue* default_values, |
39 const base::DictionaryValue* bad_type_values) { | 34 const base::DictionaryValue* bad_type_values) { |
40 scoped_ptr<base::DictionaryValue> to(default_values->DeepCopy()); | 35 scoped_ptr<base::DictionaryValue> to(default_values->DeepCopy()); |
41 for (base::DictionaryValue::Iterator i(*default_values); | 36 for (base::DictionaryValue::Iterator i(*default_values); |
42 !i.IsAtEnd(); i.Advance()) { | 37 !i.IsAtEnd(); i.Advance()) { |
(...skipping 25 matching lines...) Expand all Loading... |
68 } | 63 } |
69 } | 64 } |
70 #endif // defined(NDEBUG) | 65 #endif // defined(NDEBUG) |
71 | 66 |
72 return to.Pass(); | 67 return to.Pass(); |
73 } | 68 } |
74 | 69 |
75 } // namespace | 70 } // namespace |
76 | 71 |
77 PolicyWatcher::PolicyWatcher( | 72 PolicyWatcher::PolicyWatcher( |
78 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 73 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
79 : task_runner_(task_runner), | 74 : task_runner_(task_runner), |
80 transient_policy_error_retry_counter_(0), | 75 transient_policy_error_retry_counter_(0), |
81 old_policies_(new base::DictionaryValue()), | 76 old_policies_(new base::DictionaryValue()), |
82 default_values_(new base::DictionaryValue()), | 77 default_values_(new base::DictionaryValue()), |
83 weak_factory_(this) { | 78 weak_factory_(this) { |
84 // Initialize the default values for each policy. | 79 // Initialize the default values for each policy. |
85 default_values_->SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, | 80 default_values_->SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, |
86 true); | 81 true); |
87 default_values_->SetBoolean(policy::key::kRemoteAccessHostRequireTwoFactor, | 82 default_values_->SetBoolean(policy::key::kRemoteAccessHostRequireTwoFactor, |
88 false); | 83 false); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 stopped_callback); | 144 stopped_callback); |
150 } | 145 } |
151 | 146 |
152 void PolicyWatcher::StopWatchingOnPolicyWatcherThread() { | 147 void PolicyWatcher::StopWatchingOnPolicyWatcherThread() { |
153 StopWatchingInternal(); | 148 StopWatchingInternal(); |
154 weak_factory_.InvalidateWeakPtrs(); | 149 weak_factory_.InvalidateWeakPtrs(); |
155 policy_updated_callback_.Reset(); | 150 policy_updated_callback_.Reset(); |
156 policy_error_callback_.Reset(); | 151 policy_error_callback_.Reset(); |
157 } | 152 } |
158 | 153 |
159 void PolicyWatcher::ScheduleFallbackReloadTask() { | |
160 DCHECK(OnPolicyWatcherThread()); | |
161 ScheduleReloadTask( | |
162 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes)); | |
163 } | |
164 | |
165 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) { | |
166 DCHECK(OnPolicyWatcherThread()); | |
167 task_runner_->PostDelayedTask( | |
168 FROM_HERE, | |
169 base::Bind(&PolicyWatcher::Reload, weak_factory_.GetWeakPtr()), | |
170 delay); | |
171 } | |
172 | |
173 const base::DictionaryValue& PolicyWatcher::Defaults() const { | 154 const base::DictionaryValue& PolicyWatcher::Defaults() const { |
174 return *default_values_; | 155 return *default_values_; |
175 } | 156 } |
176 | 157 |
177 bool PolicyWatcher::OnPolicyWatcherThread() const { | 158 bool PolicyWatcher::OnPolicyWatcherThread() const { |
178 return task_runner_->BelongsToCurrentThread(); | 159 return task_runner_->BelongsToCurrentThread(); |
179 } | 160 } |
180 | 161 |
181 void PolicyWatcher::UpdatePolicies( | 162 void PolicyWatcher::UpdatePolicies( |
182 const base::DictionaryValue* new_policies_raw) { | 163 const base::DictionaryValue* new_policies_raw) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 void PolicyWatcher::SignalTransientPolicyError() { | 200 void PolicyWatcher::SignalTransientPolicyError() { |
220 const int kMaxRetryCount = 5; | 201 const int kMaxRetryCount = 5; |
221 transient_policy_error_retry_counter_ += 1; | 202 transient_policy_error_retry_counter_ += 1; |
222 if (transient_policy_error_retry_counter_ >= kMaxRetryCount) { | 203 if (transient_policy_error_retry_counter_ >= kMaxRetryCount) { |
223 SignalPolicyError(); | 204 SignalPolicyError(); |
224 } | 205 } |
225 } | 206 } |
226 | 207 |
227 } // namespace policy_hack | 208 } // namespace policy_hack |
228 } // namespace remoting | 209 } // namespace remoting |
OLD | NEW |