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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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_NAT_POLICY_H_ 5 #ifndef REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_
6 #define REMOTING_HOST_POLICY_HACK_NAT_POLICY_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 11
11 namespace base { 12 namespace base {
12 class DictionaryValue;
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 NAT 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 NatPolicy { 24 class PolicyWatcher {
25 public: 25 public:
26 // Called with the current status of whether or not NAT traversal is enabled. 26 // Called first with all policies, and subsequently with any changed policies.
27 typedef base::Callback<void(bool)> NatEnabledCallback; 27 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)>
28 PolicyCallback;
28 29
29 explicit NatPolicy(scoped_refptr<base::SingleThreadTaskRunner> task_runner); 30 explicit PolicyWatcher(
30 virtual ~NatPolicy(); 31 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
32 virtual ~PolicyWatcher();
31 33
32 // This guarantees that the |nat_enabled_cb| is called at least once with 34 // This guarantees that the |policy_callback| is called at least once with
33 // the current policy. After that, |nat_enabled_cb| will be called whenever 35 // the current policies. After that, |policy_callback| will be called
34 // a change to the nat policy is detected. 36 // whenever a change to any policy is detected. It will then be called only
35 virtual void StartWatching(const NatEnabledCallback& nat_enabled_cb); 37 // with the changed policies.
38 virtual void StartWatching(const PolicyCallback& policy_callback);
36 39
37 // Should be called after StartWatching() before the object is deleted. Calls 40 // Should be called after StartWatching() before the object is deleted. Calls
38 // just wait for |done| to be signaled before deleting the object. 41 // just wait for |done| to be signaled before deleting the object.
39 virtual void StopWatching(base::WaitableEvent* done); 42 virtual void StopWatching(base::WaitableEvent* done);
40 43
41 // Implemented by each platform. This message loop should be an IO message 44 // Implemented by each platform. This message loop should be an IO message
42 // loop. 45 // loop.
43 static NatPolicy* Create( 46 static PolicyWatcher* Create(
44 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 47 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
45 48
49 // The name of the NAT traversal policy.
50 static const char kNatPolicyName[];
51
46 protected: 52 protected:
47 virtual void StartWatchingInternal() = 0; 53 virtual void StartWatchingInternal() = 0;
48 virtual void StopWatchingInternal() = 0; 54 virtual void StopWatchingInternal() = 0;
49 virtual void Reload() = 0; 55 virtual void Reload() = 0;
50 56
51 // Used to check if the class is on the right thread. 57 // Used to check if the class is on the right thread.
52 bool OnPolicyThread() const; 58 bool OnPolicyWatcherThread() const;
53 59
54 // Takes the policy dictionary from the OS specific store and extracts the 60 // Takes the policy dictionary from the OS specific store and extracts the
55 // NAT traversal setting. 61 // relevant policies.
56 void UpdateNatPolicy(base::DictionaryValue* new_policy); 62 void UpdatePolicies(const base::DictionaryValue* new_policy);
57 63
58 // Used for time-based reloads in case something goes wrong with the 64 // Used for time-based reloads in case something goes wrong with the
59 // notification system. 65 // notification system.
60 void ScheduleFallbackReloadTask(); 66 void ScheduleFallbackReloadTask();
61 void ScheduleReloadTask(const base::TimeDelta& delay); 67 void ScheduleReloadTask(const base::TimeDelta& delay);
62 68
63 static const char kNatPolicyName[]; 69 // The names of policies with boolean values.
70 static const char* const kBooleanPolicyNames[];
71 static const int kBooleanPolicyNamesNum;
64 72
65 private: 73 private:
66 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 74 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
67 75
68 NatEnabledCallback nat_enabled_cb_; 76 PolicyCallback policy_callback_;
69 bool current_nat_enabled_state_; 77
70 bool first_state_published_; 78 scoped_ptr<base::DictionaryValue> old_policies_;
71 79
72 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. 80 // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
73 base::WeakPtrFactory<NatPolicy> weak_factory_; 81 base::WeakPtrFactory<PolicyWatcher> weak_factory_;
74 }; 82 };
75 83
76 } // namespace policy_hack 84 } // namespace policy_hack
77 } // namespace remoting 85 } // namespace remoting
78 86
79 #endif // REMOTING_HOST_POLICY_HACK_NAT_POLICY_H_ 87 #endif // REMOTING_HOST_POLICY_HACK_POLICY_WATCHER_H_
OLDNEW
« 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