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

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

Issue 10572005: Use SingleThreadTaskRunner instead of MessageLoopProxy in remoting/host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « remoting/host/plugin/host_script_object.cc ('k') | remoting/host/policy_hack/nat_policy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_NAT_POLICY_H_
6 #define REMOTING_HOST_POLICY_HACK_NAT_POLICY_H_ 6 #define REMOTING_HOST_POLICY_HACK_NAT_POLICY_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 10
11 namespace base { 11 namespace base {
12 class DictionaryValue; 12 class DictionaryValue;
13 class MessageLoopProxy; 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 NAT 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 NatPolicy {
25 public: 25 public:
26 // Called with the current status of whether or not NAT traversal is enabled. 26 // Called with the current status of whether or not NAT traversal is enabled.
27 typedef base::Callback<void(bool)> NatEnabledCallback; 27 typedef base::Callback<void(bool)> NatEnabledCallback;
28 28
29 explicit NatPolicy(base::MessageLoopProxy* message_loop_proxy); 29 explicit NatPolicy(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
30 virtual ~NatPolicy(); 30 virtual ~NatPolicy();
31 31
32 // This guarantees that the |nat_enabled_cb| is called at least once with 32 // This guarantees that the |nat_enabled_cb| is called at least once with
33 // the current policy. After that, |nat_enabled_cb| will be called whenever 33 // the current policy. After that, |nat_enabled_cb| will be called whenever
34 // a change to the nat policy is detected. 34 // a change to the nat policy is detected.
35 virtual void StartWatching(const NatEnabledCallback& nat_enabled_cb); 35 virtual void StartWatching(const NatEnabledCallback& nat_enabled_cb);
36 36
37 // Should be called after StartWatching() before the object is deleted. Calls 37 // Should be called after StartWatching() before the object is deleted. Calls
38 // just wait for |done| to be signaled before deleting the object. 38 // just wait for |done| to be signaled before deleting the object.
39 virtual void StopWatching(base::WaitableEvent* done); 39 virtual void StopWatching(base::WaitableEvent* done);
40 40
41 // Implemented by each platform. This message loop should be an IO message 41 // Implemented by each platform. This message loop should be an IO message
42 // loop. 42 // loop.
43 static NatPolicy* Create(base::MessageLoopProxy* message_loop_proxy); 43 static NatPolicy* Create(
44 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
44 45
45 protected: 46 protected:
46 virtual void StartWatchingInternal() = 0; 47 virtual void StartWatchingInternal() = 0;
47 virtual void StopWatchingInternal() = 0; 48 virtual void StopWatchingInternal() = 0;
48 virtual void Reload() = 0; 49 virtual void Reload() = 0;
49 50
50 // Used to check if the class is on the right thread. 51 // Used to check if the class is on the right thread.
51 bool OnPolicyThread() const; 52 bool OnPolicyThread() const;
52 53
53 // Takes the policy dictionary from the OS specific store and extracts the 54 // Takes the policy dictionary from the OS specific store and extracts the
54 // NAT traversal setting. 55 // NAT traversal setting.
55 void UpdateNatPolicy(base::DictionaryValue* new_policy); 56 void UpdateNatPolicy(base::DictionaryValue* new_policy);
56 57
57 // Used for time-based reloads in case something goes wrong with the 58 // Used for time-based reloads in case something goes wrong with the
58 // notification system. 59 // notification system.
59 void ScheduleFallbackReloadTask(); 60 void ScheduleFallbackReloadTask();
60 void ScheduleReloadTask(const base::TimeDelta& delay); 61 void ScheduleReloadTask(const base::TimeDelta& delay);
61 62
62 static const char kNatPolicyName[]; 63 static const char kNatPolicyName[];
63 64
64 private: 65 private:
65 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 66 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
66 67
67 NatEnabledCallback nat_enabled_cb_; 68 NatEnabledCallback nat_enabled_cb_;
68 bool current_nat_enabled_state_; 69 bool current_nat_enabled_state_;
69 bool first_state_published_; 70 bool first_state_published_;
70 71
71 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. 72 // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
72 base::WeakPtrFactory<NatPolicy> weak_factory_; 73 base::WeakPtrFactory<NatPolicy> weak_factory_;
73 }; 74 };
74 75
75 } // namespace policy_hack 76 } // namespace policy_hack
76 } // namespace remoting 77 } // namespace remoting
77 78
78 #endif // REMOTING_HOST_POLICY_HACK_NAT_POLICY_H_ 79 #endif // REMOTING_HOST_POLICY_HACK_NAT_POLICY_H_
OLDNEW
« no previous file with comments | « remoting/host/plugin/host_script_object.cc ('k') | remoting/host/policy_hack/nat_policy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698