OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_IT2ME_IT2ME_HOST_H_ | 5 #ifndef REMOTING_HOST_IT2ME_IT2ME_HOST_H_ |
6 #define REMOTING_HOST_IT2ME_IT2ME_HOST_H_ | 6 #define REMOTING_HOST_IT2ME_IT2ME_HOST_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "remoting/host/host_status_observer.h" | 12 #include "remoting/host/host_status_observer.h" |
13 #include "remoting/signaling/xmpp_signal_strategy.h" | 13 #include "remoting/signaling/xmpp_signal_strategy.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class DictionaryValue; | 16 class DictionaryValue; |
17 } | 17 } |
18 | 18 |
19 namespace policy { | |
20 class PolicyService; | |
21 } // namespace policy | |
22 | |
23 namespace remoting { | 19 namespace remoting { |
24 | 20 |
25 class ChromotingHost; | 21 class ChromotingHost; |
26 class ChromotingHostContext; | 22 class ChromotingHostContext; |
27 class DesktopEnvironmentFactory; | 23 class DesktopEnvironmentFactory; |
28 class HostEventLogger; | 24 class HostEventLogger; |
29 class HostNPScriptObject; | 25 class HostNPScriptObject; |
30 class HostStatusLogger; | 26 class HostStatusLogger; |
31 class RegisterSupportHostRequest; | 27 class RegisterSupportHostRequest; |
32 class RsaKeyPair; | 28 class RsaKeyPair; |
33 | 29 |
34 namespace policy_hack { | 30 namespace policy_hack { |
| 31 |
35 class PolicyWatcher; | 32 class PolicyWatcher; |
| 33 |
36 } // namespace policy_hack | 34 } // namespace policy_hack |
37 | 35 |
38 // These state values are duplicated in host_session.js. Remember to update | 36 // These state values are duplicated in host_session.js. Remember to update |
39 // both copies when making changes. | 37 // both copies when making changes. |
40 enum It2MeHostState { | 38 enum It2MeHostState { |
41 kDisconnected, | 39 kDisconnected, |
42 kStarting, | 40 kStarting, |
43 kRequestedAccessCode, | 41 kRequestedAccessCode, |
44 kReceivedAccessCode, | 42 kReceivedAccessCode, |
45 kConnected, | 43 kConnected, |
46 kDisconnecting, | 44 kDisconnecting, |
47 kError, | 45 kError, |
48 kInvalidDomainError | 46 kInvalidDomainError |
49 }; | 47 }; |
50 | 48 |
51 // Internal implementation of the plugin's It2Me host function. | 49 // Internal implementation of the plugin's It2Me host function. |
52 class It2MeHost : public base::RefCountedThreadSafe<It2MeHost>, | 50 class It2MeHost : public base::RefCountedThreadSafe<It2MeHost>, |
53 public HostStatusObserver { | 51 public HostStatusObserver { |
54 public: | 52 public: |
55 class Observer { | 53 class Observer { |
56 public: | 54 public: |
57 virtual void OnClientAuthenticated(const std::string& client_username) = 0; | 55 virtual void OnClientAuthenticated(const std::string& client_username) = 0; |
58 virtual void OnStoreAccessCode(const std::string& access_code, | 56 virtual void OnStoreAccessCode(const std::string& access_code, |
59 base::TimeDelta access_code_lifetime) = 0; | 57 base::TimeDelta access_code_lifetime) = 0; |
60 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) = 0; | 58 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) = 0; |
61 virtual void OnStateChanged(It2MeHostState state) = 0; | 59 virtual void OnStateChanged(It2MeHostState state) = 0; |
62 }; | 60 }; |
63 | 61 |
64 It2MeHost( | 62 It2MeHost( |
65 scoped_ptr<ChromotingHostContext> context, | 63 ChromotingHostContext* context, |
66 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher, | 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
67 base::WeakPtr<It2MeHost::Observer> observer, | 65 base::WeakPtr<It2MeHost::Observer> observer, |
68 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 66 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
69 const std::string& directory_bot_jid); | 67 const std::string& directory_bot_jid); |
70 | 68 |
71 // Methods called by the script object, from the plugin thread. | 69 // Methods called by the script object, from the plugin thread. |
72 | 70 |
73 // Creates It2Me host structures and starts the host. | 71 // Creates It2Me host structures and starts the host. |
74 virtual void Connect(); | 72 virtual void Connect(); |
75 | 73 |
76 // Disconnects the host, ready for tear-down. | 74 // Disconnects the host, ready for tear-down. |
77 // Also called internally, from the network thread. | 75 // Also called internally, from the network thread. |
78 virtual void Disconnect(); | 76 virtual void Disconnect(); |
79 | 77 |
80 // TODO (weitaosu): Remove RequestNatPolicy from It2MeHost. | 78 // TODO (weitaosu): Remove RequestNatPolicy from It2MeHost. |
81 // Request a NAT policy notification. | 79 // Request a NAT policy notification. |
82 virtual void RequestNatPolicy(); | 80 virtual void RequestNatPolicy(); |
83 | 81 |
84 // remoting::HostStatusObserver implementation. | 82 // remoting::HostStatusObserver implementation. |
85 void OnAccessDenied(const std::string& jid) override; | 83 void OnAccessDenied(const std::string& jid) override; |
86 void OnClientAuthenticated(const std::string& jid) override; | 84 void OnClientAuthenticated(const std::string& jid) override; |
87 void OnClientDisconnected(const std::string& jid) override; | 85 void OnClientDisconnected(const std::string& jid) override; |
88 | 86 |
89 void SetStateForTesting(It2MeHostState state) { SetState(state); } | 87 void SetStateForTesting(It2MeHostState state) { SetState(state); } |
90 | 88 |
91 protected: | 89 protected: |
92 friend class base::RefCountedThreadSafe<It2MeHost>; | 90 friend class base::RefCountedThreadSafe<It2MeHost>; |
93 | 91 |
94 ~It2MeHost() override; | 92 ~It2MeHost() override; |
95 | 93 |
96 ChromotingHostContext* host_context() { return host_context_.get(); } | 94 ChromotingHostContext* host_context() { return host_context_; } |
97 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { | 95 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { |
98 return task_runner_; | 96 return task_runner_; |
99 } | 97 } |
100 base::WeakPtr<It2MeHost::Observer> observer() { return observer_; } | 98 base::WeakPtr<It2MeHost::Observer> observer() { return observer_; } |
101 | 99 |
102 private: | 100 private: |
103 // Updates state of the host. Can be called only on the network thread. | 101 // Updates state of the host. Can be called only on the network thread. |
104 void SetState(It2MeHostState state); | 102 void SetState(It2MeHostState state); |
105 | 103 |
106 // Returns true if the host is connected. | 104 // Returns true if the host is connected. |
(...skipping 11 matching lines...) Expand all Loading... |
118 const base::TimeDelta& lifetime); | 116 const base::TimeDelta& lifetime); |
119 | 117 |
120 // Shuts down |host_| on the network thread and posts ShutdownOnUiThread() | 118 // Shuts down |host_| on the network thread and posts ShutdownOnUiThread() |
121 // to shut down UI thread resources. | 119 // to shut down UI thread resources. |
122 void ShutdownOnNetworkThread(); | 120 void ShutdownOnNetworkThread(); |
123 | 121 |
124 // Shuts down |desktop_environment_factory_| and |policy_watcher_| on | 122 // Shuts down |desktop_environment_factory_| and |policy_watcher_| on |
125 // the UI thread. | 123 // the UI thread. |
126 void ShutdownOnUiThread(); | 124 void ShutdownOnUiThread(); |
127 | 125 |
128 // Called when |policy_watcher_| has stopped listening for changes and it is | |
129 // safe to delete it. | |
130 void OnPolicyWatcherShutdown(); | |
131 | |
132 // Called when initial policies are read, and when they change. | 126 // Called when initial policies are read, and when they change. |
133 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); | 127 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); |
134 | 128 |
135 // Handlers for NAT traversal and host domain policies. | 129 // Handlers for NAT traversal and host domain policies. |
136 void UpdateNatPolicy(bool nat_traversal_enabled); | 130 void UpdateNatPolicy(bool nat_traversal_enabled); |
137 void UpdateHostDomainPolicy(const std::string& host_domain); | 131 void UpdateHostDomainPolicy(const std::string& host_domain); |
138 | 132 |
139 // Caller supplied fields. | 133 // Caller supplied fields. |
140 scoped_ptr<ChromotingHostContext> host_context_; | 134 |
| 135 // The creator of the It2MeHost object owns the the host context and is |
| 136 // responsible for keeping it alive throughout the liftime of the host. |
| 137 ChromotingHostContext* host_context_; |
141 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 138 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
142 base::WeakPtr<It2MeHost::Observer> observer_; | 139 base::WeakPtr<It2MeHost::Observer> observer_; |
143 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 140 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
144 std::string directory_bot_jid_; | 141 std::string directory_bot_jid_; |
145 | 142 |
146 It2MeHostState state_; | 143 It2MeHostState state_; |
147 | 144 |
148 scoped_refptr<RsaKeyPair> host_key_pair_; | 145 scoped_refptr<RsaKeyPair> host_key_pair_; |
149 scoped_ptr<SignalStrategy> signal_strategy_; | 146 scoped_ptr<SignalStrategy> signal_strategy_; |
150 scoped_ptr<RegisterSupportHostRequest> register_request_; | 147 scoped_ptr<RegisterSupportHostRequest> register_request_; |
(...skipping 26 matching lines...) Expand all Loading... |
177 DISALLOW_COPY_AND_ASSIGN(It2MeHost); | 174 DISALLOW_COPY_AND_ASSIGN(It2MeHost); |
178 }; | 175 }; |
179 | 176 |
180 // Having a factory interface makes it possible for the test to provide a mock | 177 // Having a factory interface makes it possible for the test to provide a mock |
181 // implementation of the It2MeHost. | 178 // implementation of the It2MeHost. |
182 class It2MeHostFactory { | 179 class It2MeHostFactory { |
183 public: | 180 public: |
184 It2MeHostFactory(); | 181 It2MeHostFactory(); |
185 virtual ~It2MeHostFactory(); | 182 virtual ~It2MeHostFactory(); |
186 | 183 |
187 // |policy_service| is used for creating the policy watcher for new | |
188 // instances of It2MeHost on ChromeOS. The caller must ensure that | |
189 // |policy_service| is valid throughout the lifetime of the It2MeHostFactory | |
190 // and each created It2MeHost object. This is currently possible because | |
191 // |policy_service| is a global singleton available from the browser process. | |
192 virtual void set_policy_service(policy::PolicyService* policy_service); | |
193 | |
194 virtual scoped_refptr<It2MeHost> CreateIt2MeHost( | 184 virtual scoped_refptr<It2MeHost> CreateIt2MeHost( |
195 scoped_ptr<ChromotingHostContext> context, | 185 ChromotingHostContext* context, |
| 186 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
196 base::WeakPtr<It2MeHost::Observer> observer, | 187 base::WeakPtr<It2MeHost::Observer> observer, |
197 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | 188 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, |
198 const std::string& directory_bot_jid); | 189 const std::string& directory_bot_jid); |
199 | 190 |
200 private: | 191 private: |
201 policy::PolicyService* policy_service_; | |
202 DISALLOW_COPY_AND_ASSIGN(It2MeHostFactory); | 192 DISALLOW_COPY_AND_ASSIGN(It2MeHostFactory); |
203 }; | 193 }; |
204 | 194 |
205 } // namespace remoting | 195 } // namespace remoting |
206 | 196 |
207 #endif // REMOTING_HOST_IT2ME_IT2ME_HOST_H_ | 197 #endif // REMOTING_HOST_IT2ME_IT2ME_HOST_H_ |
OLD | NEW |