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

Unified Diff: remoting/host/policy_hack/policy_watcher.h

Issue 10804040: [Chromoting] Refactor the host policy watcher so that policies can easily be added. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for Windows. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/policy_hack/nat_policy_win.cc ('k') | remoting/host/policy_hack/policy_watcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/policy_hack/policy_watcher.h
diff --git a/remoting/host/policy_hack/nat_policy.h b/remoting/host/policy_hack/policy_watcher.h
similarity index 54%
rename from remoting/host/policy_hack/nat_policy.h
rename to remoting/host/policy_hack/policy_watcher.h
index 93f1c41c6eb56b7f0aca65f2135ddb0519a3d1b3..ac0a567aa0f64c221919c6b79f4a8f519ca9d6dc 100644
--- a/remoting/host/policy_hack/nat_policy.h
+++ b/remoting/host/policy_hack/policy_watcher.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 {
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_
« no previous file with comments | « remoting/host/policy_hack/nat_policy_win.cc ('k') | remoting/host/policy_hack/policy_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698