Chromium Code Reviews| 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 #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. | |
| 31 typedef base::Callback<void()> PolicyErrorCallback; | |
| 29 | 32 |
| 30 explicit PolicyWatcher( | 33 explicit PolicyWatcher( |
| 31 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 34 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 32 virtual ~PolicyWatcher(); | 35 virtual ~PolicyWatcher(); |
| 33 | 36 |
| 34 // This guarantees that the |policy_callback| is called at least once with | 37 // This guarantees that the |policy_updated_callback| is called at least once |
| 35 // the current policies. After that, |policy_callback| will be called | 38 // 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 | 39 // called whenever a change to any policy is detected. It will then be called |
| 37 // with the changed policies. | 40 // only with the changed policies. |
| 38 virtual void StartWatching(const PolicyCallback& policy_callback); | 41 // |
| 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). | |
| 45 // When called, the |policy_error_callback| is responsible for mitigating the | |
| 46 // security risk of running with incorrectly formulated policies (by either | |
| 47 // shutting down or locking down the host). | |
| 48 // After calling |policy_error_callback| PolicyWatcher will continue watching | |
|
Łukasz Anforowicz
2014/11/13 17:51:15
"will continue watching" is not technically true f
| |
| 49 // for policy changes and will call |policy_updated_callback| when the error | |
| 50 // is recovered from and may call |policy_error_callback| when new errors are | |
| 51 // found. | |
| 52 virtual void StartWatching( | |
| 53 const PolicyUpdatedCallback& policy_updated_callback, | |
| 54 const PolicyErrorCallback& policy_error_callback); | |
| 39 | 55 |
| 40 // Should be called after StartWatching() before the object is deleted. Calls | 56 // Should be called after StartWatching() before the object is deleted. Calls |
| 41 // just wait for |done| to be signaled before deleting the object. | 57 // just wait for |done| to be signaled before deleting the object. |
| 42 virtual void StopWatching(base::WaitableEvent* done); | 58 virtual void StopWatching(base::WaitableEvent* done); |
| 43 | 59 |
| 44 // Implemented by each platform. This message loop should be an IO message | 60 // Implemented by each platform. This message loop should be an IO message |
| 45 // loop. | 61 // loop. |
| 46 static PolicyWatcher* Create( | 62 static PolicyWatcher* Create( |
| 47 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 48 | 64 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 virtual void StopWatchingInternal() = 0; | 107 virtual void StopWatchingInternal() = 0; |
| 92 virtual void Reload() = 0; | 108 virtual void Reload() = 0; |
| 93 | 109 |
| 94 // Used to check if the class is on the right thread. | 110 // Used to check if the class is on the right thread. |
| 95 bool OnPolicyWatcherThread() const; | 111 bool OnPolicyWatcherThread() const; |
| 96 | 112 |
| 97 // Takes the policy dictionary from the OS specific store and extracts the | 113 // Takes the policy dictionary from the OS specific store and extracts the |
| 98 // relevant policies. | 114 // relevant policies. |
| 99 void UpdatePolicies(const base::DictionaryValue* new_policy); | 115 void UpdatePolicies(const base::DictionaryValue* new_policy); |
| 100 | 116 |
| 117 // Signals policy error to the registered |PolicyErrorCallback|. | |
| 118 void SignalPolicyError(); | |
| 119 | |
| 120 // Called whenever a transient error occurs during reading of policy files. | |
| 121 // This will increment a counter, and will trigger a call to | |
| 122 // SignalPolicyError() only after a threshold count is reached. | |
| 123 // The counter is reset whenever policy has been successfully read. | |
| 124 void SignalTransientPolicyError(); | |
| 125 | |
| 101 // Used for time-based reloads in case something goes wrong with the | 126 // Used for time-based reloads in case something goes wrong with the |
| 102 // notification system. | 127 // notification system. |
| 103 void ScheduleFallbackReloadTask(); | 128 void ScheduleFallbackReloadTask(); |
| 104 void ScheduleReloadTask(const base::TimeDelta& delay); | 129 void ScheduleReloadTask(const base::TimeDelta& delay); |
| 105 | 130 |
| 106 // Returns a DictionaryValue containing the default values for each policy. | 131 // Returns a DictionaryValue containing the default values for each policy. |
| 107 const base::DictionaryValue& Defaults() const; | 132 const base::DictionaryValue& Defaults() const; |
| 108 | 133 |
| 109 private: | 134 private: |
| 110 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 135 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 111 | 136 |
| 112 PolicyCallback policy_callback_; | 137 PolicyUpdatedCallback policy_updated_callback_; |
| 138 PolicyErrorCallback policy_error_callback_; | |
| 139 int transient_policy_error_retry_counter_; | |
| 113 | 140 |
| 114 scoped_ptr<base::DictionaryValue> old_policies_; | 141 scoped_ptr<base::DictionaryValue> old_policies_; |
| 115 scoped_ptr<base::DictionaryValue> default_values_; | 142 scoped_ptr<base::DictionaryValue> default_values_; |
| 116 scoped_ptr<base::DictionaryValue> bad_type_values_; | 143 scoped_ptr<base::DictionaryValue> bad_type_values_; |
| 117 | 144 |
| 118 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. | 145 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. |
| 119 base::WeakPtrFactory<PolicyWatcher> weak_factory_; | 146 base::WeakPtrFactory<PolicyWatcher> weak_factory_; |
| 120 }; | 147 }; |
| 121 | 148 |
| 122 } // namespace policy_hack | 149 } // namespace policy_hack |
| 123 } // namespace remoting | 150 } // namespace remoting |
| 124 | 151 |
| 125 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ | 152 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ |
| OLD | NEW |