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

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

Issue 830193002: Using PolicyServiceWatcher instead of PolicyWatcherLinux/Win/Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed building for Chrome OS. Created 5 years, 11 months 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"
12 11
13 namespace base { 12 namespace base {
14 class SingleThreadTaskRunner; 13 class SingleThreadTaskRunner;
15 class TimeDelta; 14 class TimeDelta;
16 class WaitableEvent; 15 class WaitableEvent;
17 } // namespace base 16 } // namespace base
18 17
18 namespace policy {
19 class PolicyService;
20 } // namespace policy
21
19 namespace remoting { 22 namespace remoting {
20 namespace policy_hack { 23 namespace policy_hack {
21 24
22 // Watches for changes to the managed remote access host policies. 25 // Watches for changes to the managed remote access host policies.
23 // If StartWatching() has been called, then before this object can be deleted, 26 // If StartWatching() has been called, then before this object can be deleted,
24 // StopWatching() have completed (the provided |done| event must be signaled). 27 // StopWatching() have completed (the provided |done| event must be signaled).
25 class PolicyWatcher { 28 class PolicyWatcher {
26 public: 29 public:
27 // Called first with all policies, and subsequently with any changed policies. 30 // Called first with all policies, and subsequently with any changed policies.
28 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> 31 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)>
29 PolicyUpdatedCallback; 32 PolicyUpdatedCallback;
30 33
34 // TODO(lukasza): PolicyErrorCallback never gets called by
35 // PolicyServiceWatcher. Need to either 1) remove error-handling from
36 // PolicyWatcher or 2) add error-handling around PolicyService
37 // 2a) Add policy name/type validation via policy::Schema::Normalize.
38 // 2b) Consider exposing parsing errors from policy::ConfigDirPolicyLoader.
39
31 // Called after detecting malformed policies. 40 // Called after detecting malformed policies.
32 typedef base::Callback<void()> PolicyErrorCallback; 41 typedef base::Callback<void()> PolicyErrorCallback;
33 42
34 explicit PolicyWatcher( 43 explicit PolicyWatcher(
35 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 44 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
Mattias Nissler (ping if slow) 2015/01/06 09:06:12 Again, it would make sense to document and/or rena
Łukasz Anforowicz 2015/01/07 17:54:15 I tried to document this via comments. I renamed
36 virtual ~PolicyWatcher(); 45 virtual ~PolicyWatcher();
37 46
38 // This guarantees that the |policy_updated_callback| is called at least once 47 // This guarantees that the |policy_updated_callback| is called at least once
39 // with the current policies. After that, |policy_updated_callback| will be 48 // with the current policies. After that, |policy_updated_callback| will be
40 // called whenever a change to any policy is detected. It will then be called 49 // called whenever a change to any policy is detected. It will then be called
41 // only with the changed policies. 50 // only with the changed policies.
42 // 51 //
43 // |policy_error_callback| will be called when malformed policies are detected 52 // |policy_error_callback| will be called when malformed policies are detected
44 // (i.e. wrong type of policy value, or unparseable files under 53 // (i.e. wrong type of policy value, or unparseable files under
45 // /etc/opt/chrome/policies/managed). 54 // /etc/opt/chrome/policies/managed).
46 // When called, the |policy_error_callback| is responsible for mitigating the 55 // When called, the |policy_error_callback| is responsible for mitigating the
47 // security risk of running with incorrectly formulated policies (by either 56 // security risk of running with incorrectly formulated policies (by either
48 // shutting down or locking down the host). 57 // shutting down or locking down the host).
49 // After calling |policy_error_callback| PolicyWatcher will continue watching 58 // After calling |policy_error_callback| PolicyWatcher will continue watching
50 // for policy changes and will call |policy_updated_callback| when the error 59 // 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 60 // is recovered from and may call |policy_error_callback| when new errors are
52 // found. 61 // found.
53 virtual void StartWatching( 62 virtual void StartWatching(
54 const PolicyUpdatedCallback& policy_updated_callback, 63 const PolicyUpdatedCallback& policy_updated_callback,
55 const PolicyErrorCallback& policy_error_callback); 64 const PolicyErrorCallback& policy_error_callback);
56 65
57 // Should be called after StartWatching() before the object is deleted. Calls 66 // Should be called after StartWatching() before the object is deleted. Calls
58 // should wait for |stopped_callback| to be called before deleting it. 67 // should wait for |stopped_callback| to be called before deleting it.
59 virtual void StopWatching(const base::Closure& stopped_callback); 68 virtual void StopWatching(const base::Closure& stopped_callback);
60 69
61 // Implemented by each platform. |task_runner| should be an IO message loop. 70 // Implemented by each platform. |task_runner| should be an IO message loop.
62 // |policy_service| is currently only used on ChromeOS. The caller must
63 // ensure that |policy_service| remains valid for the lifetime of
64 // PolicyWatcher.
65 static scoped_ptr<PolicyWatcher> Create( 71 static scoped_ptr<PolicyWatcher> Create(
66 policy::PolicyService* policy_service, 72 policy::PolicyService* policy_service,
67 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 73 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
68 74
69 // The name of the NAT traversal policy. 75 // The name of the NAT traversal policy.
70 static const char kNatPolicyName[]; 76 static const char kNatPolicyName[];
71 77
72 // The name of the policy for requiring 2-factor authentication. 78 // The name of the policy for requiring 2-factor authentication.
73 static const char kHostRequireTwoFactorPolicyName[]; 79 static const char kHostRequireTwoFactorPolicyName[];
74 80
75 // The name of the host domain policy. 81 // The name of the host domain policy.
76 static const char kHostDomainPolicyName[]; 82 static const char kHostDomainPolicyName[];
77 83
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 126
121 // Signals policy error to the registered |PolicyErrorCallback|. 127 // Signals policy error to the registered |PolicyErrorCallback|.
122 void SignalPolicyError(); 128 void SignalPolicyError();
123 129
124 // Called whenever a transient error occurs during reading of policy files. 130 // Called whenever a transient error occurs during reading of policy files.
125 // This will increment a counter, and will trigger a call to 131 // This will increment a counter, and will trigger a call to
126 // SignalPolicyError() only after a threshold count is reached. 132 // SignalPolicyError() only after a threshold count is reached.
127 // The counter is reset whenever policy has been successfully read. 133 // The counter is reset whenever policy has been successfully read.
128 void SignalTransientPolicyError(); 134 void SignalTransientPolicyError();
129 135
130 // Used for time-based reloads in case something goes wrong with the
131 // notification system.
132 void ScheduleFallbackReloadTask();
133 void ScheduleReloadTask(const base::TimeDelta& delay);
134
135 // Returns a DictionaryValue containing the default values for each policy. 136 // Returns a DictionaryValue containing the default values for each policy.
136 const base::DictionaryValue& Defaults() const; 137 const base::DictionaryValue& Defaults() const;
137 138
138 private: 139 private:
139 void StopWatchingOnPolicyWatcherThread(); 140 void StopWatchingOnPolicyWatcherThread();
140 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 141 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
141 142
142 PolicyUpdatedCallback policy_updated_callback_; 143 PolicyUpdatedCallback policy_updated_callback_;
143 PolicyErrorCallback policy_error_callback_; 144 PolicyErrorCallback policy_error_callback_;
144 int transient_policy_error_retry_counter_; 145 int transient_policy_error_retry_counter_;
145 146
146 scoped_ptr<base::DictionaryValue> old_policies_; 147 scoped_ptr<base::DictionaryValue> old_policies_;
147 scoped_ptr<base::DictionaryValue> default_values_; 148 scoped_ptr<base::DictionaryValue> default_values_;
148 scoped_ptr<base::DictionaryValue> bad_type_values_; 149 scoped_ptr<base::DictionaryValue> bad_type_values_;
149 150
150 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. 151 // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
151 base::WeakPtrFactory<PolicyWatcher> weak_factory_; 152 base::WeakPtrFactory<PolicyWatcher> weak_factory_;
152 }; 153 };
153 154
154 } // namespace policy_hack 155 } // namespace policy_hack
155 } // namespace remoting 156 } // namespace remoting
156 157
157 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ 158 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698