Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: remoting/host/policy_hack/policy_watcher.cc

Issue 722743003: Reporting of policy errors via host-offline-reason: part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and reopened to try memory trybots. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 const char PolicyWatcher::kUdpPortRangePolicyName[] = 112 const char PolicyWatcher::kUdpPortRangePolicyName[] =
113 "RemoteAccessHostUdpPortRange"; 113 "RemoteAccessHostUdpPortRange";
114 114
115 const char PolicyWatcher::kHostDebugOverridePoliciesName[] = 115 const char PolicyWatcher::kHostDebugOverridePoliciesName[] =
116 "RemoteAccessHostDebugOverridePolicies"; 116 "RemoteAccessHostDebugOverridePolicies";
117 117
118 PolicyWatcher::PolicyWatcher( 118 PolicyWatcher::PolicyWatcher(
119 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 119 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
120 : task_runner_(task_runner), 120 : task_runner_(task_runner),
121 transient_policy_error_retry_counter_(0),
121 old_policies_(new base::DictionaryValue()), 122 old_policies_(new base::DictionaryValue()),
122 default_values_(new base::DictionaryValue()), 123 default_values_(new base::DictionaryValue()),
123 weak_factory_(this) { 124 weak_factory_(this) {
124 // Initialize the default values for each policy. 125 // Initialize the default values for each policy.
125 default_values_->SetBoolean(kNatPolicyName, true); 126 default_values_->SetBoolean(kNatPolicyName, true);
126 default_values_->SetBoolean(kHostRequireTwoFactorPolicyName, false); 127 default_values_->SetBoolean(kHostRequireTwoFactorPolicyName, false);
127 default_values_->SetBoolean(kHostRequireCurtainPolicyName, false); 128 default_values_->SetBoolean(kHostRequireCurtainPolicyName, false);
128 default_values_->SetBoolean(kHostMatchUsernamePolicyName, false); 129 default_values_->SetBoolean(kHostMatchUsernamePolicyName, false);
129 default_values_->SetString(kHostDomainPolicyName, std::string()); 130 default_values_->SetString(kHostDomainPolicyName, std::string());
130 default_values_->SetString(kHostTalkGadgetPrefixPolicyName, 131 default_values_->SetString(kHostTalkGadgetPrefixPolicyName,
(...skipping 13 matching lines...) Expand all
144 // Initialize the fall-back values to use for unreadable policies. 145 // Initialize the fall-back values to use for unreadable policies.
145 // For most policies these match the defaults. 146 // For most policies these match the defaults.
146 bad_type_values_.reset(default_values_->DeepCopy()); 147 bad_type_values_.reset(default_values_->DeepCopy());
147 bad_type_values_->SetBoolean(kNatPolicyName, false); 148 bad_type_values_->SetBoolean(kNatPolicyName, false);
148 bad_type_values_->SetBoolean(kRelayPolicyName, false); 149 bad_type_values_->SetBoolean(kRelayPolicyName, false);
149 } 150 }
150 151
151 PolicyWatcher::~PolicyWatcher() { 152 PolicyWatcher::~PolicyWatcher() {
152 } 153 }
153 154
154 void PolicyWatcher::StartWatching(const PolicyCallback& policy_callback) { 155 void PolicyWatcher::StartWatching(
156 const PolicyUpdatedCallback& policy_updated_callback,
157 const PolicyErrorCallback& policy_error_callback) {
155 if (!OnPolicyWatcherThread()) { 158 if (!OnPolicyWatcherThread()) {
156 task_runner_->PostTask(FROM_HERE, 159 task_runner_->PostTask(FROM_HERE,
157 base::Bind(&PolicyWatcher::StartWatching, 160 base::Bind(&PolicyWatcher::StartWatching,
158 base::Unretained(this), 161 base::Unretained(this),
159 policy_callback)); 162 policy_updated_callback,
163 policy_error_callback));
160 return; 164 return;
161 } 165 }
162 166
163 policy_callback_ = policy_callback; 167 policy_updated_callback_ = policy_updated_callback;
168 policy_error_callback_ = policy_error_callback;
164 StartWatchingInternal(); 169 StartWatchingInternal();
165 } 170 }
166 171
167 void PolicyWatcher::StopWatching(const base::Closure& stopped_callback) { 172 void PolicyWatcher::StopWatching(const base::Closure& stopped_callback) {
168 task_runner_->PostTaskAndReply( 173 task_runner_->PostTaskAndReply(
169 FROM_HERE, base::Bind(&PolicyWatcher::StopWatchingOnPolicyWatcherThread, 174 FROM_HERE, base::Bind(&PolicyWatcher::StopWatchingOnPolicyWatcherThread,
170 base::Unretained(this)), 175 base::Unretained(this)),
171 stopped_callback); 176 stopped_callback);
172 } 177 }
173 178
174 void PolicyWatcher::StopWatchingOnPolicyWatcherThread() { 179 void PolicyWatcher::StopWatchingOnPolicyWatcherThread() {
175 StopWatchingInternal(); 180 StopWatchingInternal();
176 weak_factory_.InvalidateWeakPtrs(); 181 weak_factory_.InvalidateWeakPtrs();
177 policy_callback_.Reset(); 182 policy_updated_callback_.Reset();
183 policy_error_callback_.Reset();
178 } 184 }
179 185
180 void PolicyWatcher::ScheduleFallbackReloadTask() { 186 void PolicyWatcher::ScheduleFallbackReloadTask() {
181 DCHECK(OnPolicyWatcherThread()); 187 DCHECK(OnPolicyWatcherThread());
182 ScheduleReloadTask( 188 ScheduleReloadTask(
183 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes)); 189 base::TimeDelta::FromMinutes(kFallbackReloadDelayMinutes));
184 } 190 }
185 191
186 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) { 192 void PolicyWatcher::ScheduleReloadTask(const base::TimeDelta& delay) {
187 DCHECK(OnPolicyWatcherThread()); 193 DCHECK(OnPolicyWatcherThread());
188 task_runner_->PostDelayedTask( 194 task_runner_->PostDelayedTask(
189 FROM_HERE, 195 FROM_HERE,
190 base::Bind(&PolicyWatcher::Reload, weak_factory_.GetWeakPtr()), 196 base::Bind(&PolicyWatcher::Reload, weak_factory_.GetWeakPtr()),
191 delay); 197 delay);
192 } 198 }
193 199
194 const base::DictionaryValue& PolicyWatcher::Defaults() const { 200 const base::DictionaryValue& PolicyWatcher::Defaults() const {
195 return *default_values_; 201 return *default_values_;
196 } 202 }
197 203
198 bool PolicyWatcher::OnPolicyWatcherThread() const { 204 bool PolicyWatcher::OnPolicyWatcherThread() const {
199 return task_runner_->BelongsToCurrentThread(); 205 return task_runner_->BelongsToCurrentThread();
200 } 206 }
201 207
202 void PolicyWatcher::UpdatePolicies( 208 void PolicyWatcher::UpdatePolicies(
203 const base::DictionaryValue* new_policies_raw) { 209 const base::DictionaryValue* new_policies_raw) {
204 DCHECK(OnPolicyWatcherThread()); 210 DCHECK(OnPolicyWatcherThread());
205 211
212 transient_policy_error_retry_counter_ = 0;
213
206 // Use default values for any missing policies. 214 // Use default values for any missing policies.
207 scoped_ptr<base::DictionaryValue> new_policies = 215 scoped_ptr<base::DictionaryValue> new_policies =
208 CopyGoodValuesAndAddDefaults( 216 CopyGoodValuesAndAddDefaults(
209 new_policies_raw, default_values_.get(), bad_type_values_.get()); 217 new_policies_raw, default_values_.get(), bad_type_values_.get());
210 218
211 // Find the changed policies. 219 // Find the changed policies.
212 scoped_ptr<base::DictionaryValue> changed_policies( 220 scoped_ptr<base::DictionaryValue> changed_policies(
213 new base::DictionaryValue()); 221 new base::DictionaryValue());
214 base::DictionaryValue::Iterator iter(*new_policies); 222 base::DictionaryValue::Iterator iter(*new_policies);
215 while (!iter.IsAtEnd()) { 223 while (!iter.IsAtEnd()) {
216 base::Value* old_policy; 224 base::Value* old_policy;
217 if (!(old_policies_->Get(iter.key(), &old_policy) && 225 if (!(old_policies_->Get(iter.key(), &old_policy) &&
218 old_policy->Equals(&iter.value()))) { 226 old_policy->Equals(&iter.value()))) {
219 changed_policies->Set(iter.key(), iter.value().DeepCopy()); 227 changed_policies->Set(iter.key(), iter.value().DeepCopy());
220 } 228 }
221 iter.Advance(); 229 iter.Advance();
222 } 230 }
223 231
224 // Save the new policies. 232 // Save the new policies.
225 old_policies_.swap(new_policies); 233 old_policies_.swap(new_policies);
226 234
227 // Notify our client of the changed policies. 235 // Notify our client of the changed policies.
228 if (!changed_policies->empty()) { 236 if (!changed_policies->empty()) {
229 policy_callback_.Run(changed_policies.Pass()); 237 policy_updated_callback_.Run(changed_policies.Pass());
230 } 238 }
231 } 239 }
232 240
241 void PolicyWatcher::SignalPolicyError() {
242 transient_policy_error_retry_counter_ = 0;
243 policy_error_callback_.Run();
244 }
245
246 void PolicyWatcher::SignalTransientPolicyError() {
247 const int kMaxRetryCount = 5;
248 transient_policy_error_retry_counter_ += 1;
249 if (transient_policy_error_retry_counter_ >= kMaxRetryCount) {
250 SignalPolicyError();
251 }
252 }
253
233 } // namespace policy_hack 254 } // namespace policy_hack
234 } // namespace remoting 255 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_hack/policy_watcher.h ('k') | remoting/host/policy_hack/policy_watcher_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698