summaryrefslogtreecommitdiffstats
path: root/remoting/host/plugin/policy_hack/nat_policy.h
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/host/plugin/policy_hack/nat_policy.h')
-rw-r--r--remoting/host/plugin/policy_hack/nat_policy.h45
1 files changed, 37 insertions, 8 deletions
diff --git a/remoting/host/plugin/policy_hack/nat_policy.h b/remoting/host/plugin/policy_hack/nat_policy.h
index 2ac2530..edf9569 100644
--- a/remoting/host/plugin/policy_hack/nat_policy.h
+++ b/remoting/host/plugin/policy_hack/nat_policy.h
@@ -6,10 +6,12 @@
#define REMOTING_HOST_PLUGIN_POLICY_HACK_NAT_POLICY_H_
#include "base/callback.h"
-#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
namespace base {
+class DictionaryValue;
class MessageLoopProxy;
+class TimeDelta;
class WaitableEvent;
} // namespace base
@@ -24,23 +26,50 @@ class NatPolicy {
// Called with the current status of whether or not NAT traversal is enabled.
typedef base::Callback<void(bool)> NatEnabledCallback;
- NatPolicy() {}
- virtual ~NatPolicy() {}
+ explicit NatPolicy(base::MessageLoopProxy* message_loop_proxy);
+ virtual ~NatPolicy();
// 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) = 0;
+ virtual void StartWatching(const NatEnabledCallback& nat_enabled_cb);
// Should be called after StartWatching() before the object is deleted. Calls
// just wait for |done| to be signaled before deleting the object.
- virtual void StopWatching(base::WaitableEvent* done) = 0;
+ virtual void StopWatching(base::WaitableEvent* done);
// Implemented by each platform. This message loop should be an IO message
- // loop on linux.
- //
- // TODO(ajwong): figure out the right message loop for win/mac.
+ // loop.
static NatPolicy* Create(base::MessageLoopProxy* message_loop_proxy);
+
+ 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;
+
+ // Takes the policy dictionary from the OS specific store and extracts the
+ // NAT traversal setting.
+ void UpdateNatPolicy(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[];
+
+ private:
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
+
+ NatEnabledCallback nat_enabled_cb_;
+ bool current_nat_enabled_state_;
+ bool first_state_published_;
+
+ // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
+ base::WeakPtrFactory<NatPolicy> weak_factory_;
};
} // namespace policy_hack