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

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: 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 #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 #include "components/policy/core/common/policy_service.h" 11 #include "components/policy/core/common/policy_service.h"
12 12
13 namespace base { 13 namespace base {
14 class SingleThreadTaskRunner; 14 class SingleThreadTaskRunner;
15 class TimeDelta; 15 class TimeDelta;
16 class WaitableEvent; 16 class WaitableEvent;
17 } // namespace base 17 } // namespace base
18 18
19 namespace remoting { 19 namespace remoting {
20 namespace policy_hack { 20 namespace policy_hack {
21 21
22 // Watches for changes to the managed remote access host policies. 22 // Watches for changes to the managed remote access host policies.
23 // If StartWatching() has been called, then before this object can be deleted, 23 // If StartWatching() has been called, then before this object can be deleted,
24 // StopWatching() have completed (the provided |done| event must be signaled). 24 // StopWatching() have completed (the provided |done| event must be signaled).
25 class PolicyWatcher { 25 class PolicyWatcher {
26 public: 26 public:
27 // Called first with all policies, and subsequently with any changed policies. 27 // Called first with all policies, and subsequently with any changed policies.
28 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> 28 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)>
29 PolicyCallback; 29 PolicyUpdatedCallback;
30
31 // Called after detecting malformed policies.
32 typedef base::Callback<void()> PolicyErrorCallback;
30 33
31 explicit PolicyWatcher( 34 explicit PolicyWatcher(
32 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 35 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
33 virtual ~PolicyWatcher(); 36 virtual ~PolicyWatcher();
34 37
35 // 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
36 // the current policies. After that, |policy_callback| will be called 39 // with the current policies. After that, |policy_updated_callback| will be
37 // 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
38 // with the changed policies. 41 // only with the changed policies.
39 virtual void StartWatching(const PolicyCallback& policy_callback); 42 //
43 // |policy_error_callback| will be called when malformed policies are detected
44 // (i.e. wrong type of policy value, or unparseable files under
45 // /etc/opt/chrome/policies/managed).
46 // When called, the |policy_error_callback| is responsible for mitigating the
47 // security risk of running with incorrectly formulated policies (by either
48 // shutting down or locking down the host).
49 // After calling |policy_error_callback| PolicyWatcher will continue watching
50 // for policy changes and will call |policy_updated_callback| when the error
51 // is recovered from and may call |policy_error_callback| when new errors are
52 // found.
53 virtual void StartWatching(
54 const PolicyUpdatedCallback& policy_updated_callback,
55 const PolicyErrorCallback& policy_error_callback);
40 56
41 // Should be called after StartWatching() before the object is deleted. Calls 57 // Should be called after StartWatching() before the object is deleted. Calls
42 // should wait for |stopped_callback| to be called before deleting it. 58 // should wait for |stopped_callback| to be called before deleting it.
43 virtual void StopWatching(const base::Closure& stopped_callback); 59 virtual void StopWatching(const base::Closure& stopped_callback);
44 60
45 // Implemented by each platform. |task_runner| should be an IO message loop. 61 // Implemented by each platform. |task_runner| should be an IO message loop.
46 // |policy_service| is currently only used on ChromeOS. The caller must 62 // |policy_service| is currently only used on ChromeOS. The caller must
47 // ensure that |policy_service| remains valid for the lifetime of 63 // ensure that |policy_service| remains valid for the lifetime of
48 // PolicyWatcher. 64 // PolicyWatcher.
49 static scoped_ptr<PolicyWatcher> Create( 65 static scoped_ptr<PolicyWatcher> Create(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 virtual void StopWatchingInternal() = 0; 111 virtual void StopWatchingInternal() = 0;
96 virtual void Reload() = 0; 112 virtual void Reload() = 0;
97 113
98 // Used to check if the class is on the right thread. 114 // Used to check if the class is on the right thread.
99 bool OnPolicyWatcherThread() const; 115 bool OnPolicyWatcherThread() const;
100 116
101 // Takes the policy dictionary from the OS specific store and extracts the 117 // Takes the policy dictionary from the OS specific store and extracts the
102 // relevant policies. 118 // relevant policies.
103 void UpdatePolicies(const base::DictionaryValue* new_policy); 119 void UpdatePolicies(const base::DictionaryValue* new_policy);
104 120
121 // Signals policy error to the registered |PolicyErrorCallback|.
122 void SignalPolicyError();
123
124 // Called whenever a transient error occurs during reading of policy files.
125 // This will increment a counter, and will trigger a call to
126 // SignalPolicyError() only after a threshold count is reached.
127 // The counter is reset whenever policy has been successfully read.
128 void SignalTransientPolicyError();
129
105 // Used for time-based reloads in case something goes wrong with the 130 // Used for time-based reloads in case something goes wrong with the
106 // notification system. 131 // notification system.
107 void ScheduleFallbackReloadTask(); 132 void ScheduleFallbackReloadTask();
108 void ScheduleReloadTask(const base::TimeDelta& delay); 133 void ScheduleReloadTask(const base::TimeDelta& delay);
109 134
110 // Returns a DictionaryValue containing the default values for each policy. 135 // Returns a DictionaryValue containing the default values for each policy.
111 const base::DictionaryValue& Defaults() const; 136 const base::DictionaryValue& Defaults() const;
112 137
113 private: 138 private:
114 void StopWatchingOnPolicyWatcherThread(); 139 void StopWatchingOnPolicyWatcherThread();
115 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 140 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
116 141
117 PolicyCallback policy_callback_; 142 PolicyUpdatedCallback policy_updated_callback_;
143 PolicyErrorCallback policy_error_callback_;
144 int transient_policy_error_retry_counter_;
118 145
119 scoped_ptr<base::DictionaryValue> old_policies_; 146 scoped_ptr<base::DictionaryValue> old_policies_;
120 scoped_ptr<base::DictionaryValue> default_values_; 147 scoped_ptr<base::DictionaryValue> default_values_;
121 scoped_ptr<base::DictionaryValue> bad_type_values_; 148 scoped_ptr<base::DictionaryValue> bad_type_values_;
122 149
123 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. 150 // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
124 base::WeakPtrFactory<PolicyWatcher> weak_factory_; 151 base::WeakPtrFactory<PolicyWatcher> weak_factory_;
125 }; 152 };
126 153
127 } // namespace policy_hack 154 } // namespace policy_hack
128 } // namespace remoting 155 } // namespace remoting
129 156
130 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ 157 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_
OLDNEW
« no previous file with comments | « remoting/host/policy_hack/mock_policy_callback.cc ('k') | remoting/host/policy_hack/policy_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698