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

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

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: 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 #ifndef REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ 5 #ifndef REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_
6 #define REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ 6 #define REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 11
12 namespace base { 12 namespace base {
13 class SingleThreadTaskRunner; 13 class SingleThreadTaskRunner;
14 class TimeDelta; 14 class TimeDelta;
15 class WaitableEvent; 15 class WaitableEvent;
16 } // namespace base 16 } // namespace base
17 17
18 namespace remoting { 18 namespace remoting {
19 namespace policy_hack { 19 namespace policy_hack {
20 20
21 // Watches for changes to the managed remote access host policies. 21 // Watches for changes to the managed remote access host policies.
22 // If StartWatching() has been called, then before this object can be deleted, 22 // If StartWatching() has been called, then before this object can be deleted,
23 // StopWatching() have completed (the provided |done| event must be signaled). 23 // StopWatching() have completed (the provided |done| event must be signaled).
24 class PolicyWatcher { 24 class PolicyWatcher {
25 public: 25 public:
26 // Called first with all policies, and subsequently with any changed policies. 26 // Called first with all policies, and subsequently with any changed policies.
27 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> 27 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)>
28 PolicyCallback; 28 PolicyUpdatedCallback;
29
30 // Called after detecting malformed policies
Lambros 2014/11/13 00:30:27 nit: Period.
Łukasz Anforowicz 2014/11/13 17:48:08 Done.
31 typedef base::Callback<void()>
32 PolicyErrorCallback;
Lambros 2014/11/13 00:30:27 nit: Fits on one line.
Łukasz Anforowicz 2014/11/13 17:48:08 Done.
29 33
30 explicit PolicyWatcher( 34 explicit PolicyWatcher(
31 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 35 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
32 virtual ~PolicyWatcher(); 36 virtual ~PolicyWatcher();
33 37
34 // This guarantees that the |policy_callback| is called at least once with 38 // This guarantees that the |policy_updated_callback| is called at least once
35 // the current policies. After that, |policy_callback| will be called 39 // with the current policies. After that, |policy_updated_callback| will be
36 // whenever a change to any policy is detected. It will then be called only 40 // called whenever a change to any policy is detected. It will then be called
37 // with the changed policies. 41 // only with the changed policies.
38 virtual void StartWatching(const PolicyCallback& policy_callback); 42 // |policy_error_callback| will be called when malformed policies are detected
43 // (i.e. wrong type of policy value, or unparseable files under
44 // /etc/opt/chrome/policies/managed) and indicates that we need to shut down
45 // to avoid the risk of running with incorrectly formulated policies.
46 virtual void StartWatching(
47 const PolicyUpdatedCallback& policy_updated_callback,
48 const PolicyErrorCallback& policy_error_callback);
39 49
40 // Should be called after StartWatching() before the object is deleted. Calls 50 // Should be called after StartWatching() before the object is deleted. Calls
41 // just wait for |done| to be signaled before deleting the object. 51 // just wait for |done| to be signaled before deleting the object.
42 virtual void StopWatching(base::WaitableEvent* done); 52 virtual void StopWatching(base::WaitableEvent* done);
43 53
44 // Implemented by each platform. This message loop should be an IO message 54 // Implemented by each platform. This message loop should be an IO message
45 // loop. 55 // loop.
46 static PolicyWatcher* Create( 56 static PolicyWatcher* Create(
47 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
48 58
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 virtual void StopWatchingInternal() = 0; 101 virtual void StopWatchingInternal() = 0;
92 virtual void Reload() = 0; 102 virtual void Reload() = 0;
93 103
94 // Used to check if the class is on the right thread. 104 // Used to check if the class is on the right thread.
95 bool OnPolicyWatcherThread() const; 105 bool OnPolicyWatcherThread() const;
96 106
97 // Takes the policy dictionary from the OS specific store and extracts the 107 // Takes the policy dictionary from the OS specific store and extracts the
98 // relevant policies. 108 // relevant policies.
99 void UpdatePolicies(const base::DictionaryValue* new_policy); 109 void UpdatePolicies(const base::DictionaryValue* new_policy);
100 110
111 // Signals policy error to whoever is watching this policy watcher
Lambros 2014/11/13 00:30:27 s/whoever is watching this policy watcher/the regi
Łukasz Anforowicz 2014/11/13 17:48:08 Done.
112 void SignalPolicyError();
113
114 // Notes a transient policy error which shouldn't be reported
Lambros 2014/11/13 00:30:27 I think I would document more fully what is going
Łukasz Anforowicz 2014/11/13 17:48:08 Done.
115 // to users of this PolicyWatcher unless
116 // |transient_policy_error_retry_counter_| has reached a threshold.
117 void SignalTransientPolicyError();
118
101 // Used for time-based reloads in case something goes wrong with the 119 // Used for time-based reloads in case something goes wrong with the
102 // notification system. 120 // notification system.
103 void ScheduleFallbackReloadTask(); 121 void ScheduleFallbackReloadTask();
104 void ScheduleReloadTask(const base::TimeDelta& delay); 122 void ScheduleReloadTask(const base::TimeDelta& delay);
105 123
106 // Returns a DictionaryValue containing the default values for each policy. 124 // Returns a DictionaryValue containing the default values for each policy.
107 const base::DictionaryValue& Defaults() const; 125 const base::DictionaryValue& Defaults() const;
108 126
109 private: 127 private:
110 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 128 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
111 129
112 PolicyCallback policy_callback_; 130 PolicyUpdatedCallback policy_updated_callback_;
131 PolicyErrorCallback policy_error_callback_;
132 int transient_policy_error_retry_counter_;
113 133
114 scoped_ptr<base::DictionaryValue> old_policies_; 134 scoped_ptr<base::DictionaryValue> old_policies_;
115 scoped_ptr<base::DictionaryValue> default_values_; 135 scoped_ptr<base::DictionaryValue> default_values_;
116 scoped_ptr<base::DictionaryValue> bad_type_values_; 136 scoped_ptr<base::DictionaryValue> bad_type_values_;
117 137
118 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. 138 // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
119 base::WeakPtrFactory<PolicyWatcher> weak_factory_; 139 base::WeakPtrFactory<PolicyWatcher> weak_factory_;
120 }; 140 };
121 141
122 } // namespace policy_hack 142 } // namespace policy_hack
123 } // namespace remoting 143 } // namespace remoting
124 144
125 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ 145 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698