Index: remoting/host/policy_hack/nat_policy.h |
diff --git a/remoting/host/policy_hack/nat_policy.h b/remoting/host/policy_hack/nat_policy.h |
index 93f1c41c6eb56b7f0aca65f2135ddb0519a3d1b3..ac0a567aa0f64c221919c6b79f4a8f519ca9d6dc 100644 |
--- a/remoting/host/policy_hack/nat_policy.h |
+++ b/remoting/host/policy_hack/nat_policy.h |
@@ -2,14 +2,14 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef REMOTING_HOST_POLICY_HACK_NAT_POLICY_H_ |
-#define REMOTING_HOST_POLICY_HACK_NAT_POLICY_H_ |
+#ifndef REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ |
+#define REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ |
#include "base/callback.h" |
#include "base/memory/weak_ptr.h" |
+#include "base/values.h" |
namespace base { |
-class DictionaryValue; |
class SingleThreadTaskRunner; |
class TimeDelta; |
class WaitableEvent; |
@@ -18,21 +18,24 @@ class WaitableEvent; |
namespace remoting { |
namespace policy_hack { |
-// Watches for changes to the managed remote access host NAT policies. |
+// Watches for changes to the managed remote access host policies. |
// If StartWatching() has been called, then before this object can be deleted, |
// StopWatching() have completed (the provided |done| event must be signaled). |
-class NatPolicy { |
+class PolicyWatcher { |
garykac
2012/07/23 17:29:26
Can you rename these files to be policy_watcher in
simonmorris
2012/07/23 19:34:55
Done.
|
public: |
- // Called with the current status of whether or not NAT traversal is enabled. |
- typedef base::Callback<void(bool)> NatEnabledCallback; |
+ // Called first with all policies, and subsequently with any changed policies. |
+ typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> |
+ PolicyCallback; |
- explicit NatPolicy(scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
- virtual ~NatPolicy(); |
+ explicit PolicyWatcher( |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
+ virtual ~PolicyWatcher(); |
- // This guarantees that the |nat_enabled_cb| is called at least once with |
- // the current policy. After that, |nat_enabled_cb| will be called whenever |
- // a change to the nat policy is detected. |
- virtual void StartWatching(const NatEnabledCallback& nat_enabled_cb); |
+ // This guarantees that the |policy_callback| is called at least once with |
+ // the current policies. After that, |policy_callback| will be called |
+ // whenever a change to any policy is detected. It will then be called only |
+ // with the changed policies. |
+ virtual void StartWatching(const PolicyCallback& policy_callback); |
// Should be called after StartWatching() before the object is deleted. Calls |
// just wait for |done| to be signaled before deleting the object. |
@@ -40,40 +43,45 @@ class NatPolicy { |
// Implemented by each platform. This message loop should be an IO message |
// loop. |
- static NatPolicy* Create( |
+ static PolicyWatcher* Create( |
scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
+ // The name of the NAT traversal policy. |
+ static const char kNatPolicyName[]; |
+ |
protected: |
virtual void StartWatchingInternal() = 0; |
virtual void StopWatchingInternal() = 0; |
virtual void Reload() = 0; |
// Used to check if the class is on the right thread. |
- bool OnPolicyThread() const; |
+ bool OnPolicyWatcherThread() const; |
// Takes the policy dictionary from the OS specific store and extracts the |
- // NAT traversal setting. |
- void UpdateNatPolicy(base::DictionaryValue* new_policy); |
+ // relevant policies. |
+ void UpdatePolicies(const base::DictionaryValue* new_policy); |
// Used for time-based reloads in case something goes wrong with the |
// notification system. |
void ScheduleFallbackReloadTask(); |
void ScheduleReloadTask(const base::TimeDelta& delay); |
- static const char kNatPolicyName[]; |
+ // The names of policies with boolean values. |
+ static const char* const kBooleanPolicyNames[]; |
+ static const int kBooleanPolicyNamesNum; |
private: |
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
- NatEnabledCallback nat_enabled_cb_; |
- bool current_nat_enabled_state_; |
- bool first_state_published_; |
+ PolicyCallback policy_callback_; |
+ |
+ scoped_ptr<base::DictionaryValue> old_policies_; |
// Allows us to cancel any inflight FileWatcher events or scheduled reloads. |
- base::WeakPtrFactory<NatPolicy> weak_factory_; |
+ base::WeakPtrFactory<PolicyWatcher> weak_factory_; |
}; |
} // namespace policy_hack |
} // namespace remoting |
-#endif // REMOTING_HOST_POLICY_HACK_NAT_POLICY_H_ |
+#endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_ |