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 <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "remoting/host/host_status_observer.h" | 15 #include "remoting/host/host_status_observer.h" |
16 #include "remoting/host/it2me/it2me_confirmation_dialog.h" | 16 #include "remoting/host/it2me/it2me_confirmation_dialog.h" |
17 #include "remoting/host/it2me/it2me_confirmation_dialog_proxy.h" | 17 #include "remoting/host/it2me/it2me_confirmation_dialog_proxy.h" |
18 #include "remoting/protocol/validating_authenticator.h" | 18 #include "remoting/protocol/validating_authenticator.h" |
19 #include "remoting/signaling/xmpp_signal_strategy.h" | 19 #include "remoting/signaling/xmpp_signal_strategy.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 class DictionaryValue; | 22 class DictionaryValue; |
23 } | 23 } |
24 | 24 |
25 namespace policy { | |
26 class PolicyService; | |
27 } // namespace policy | |
28 | |
29 namespace remoting { | 25 namespace remoting { |
30 | 26 |
31 class ChromotingHost; | 27 class ChromotingHost; |
32 class ChromotingHostContext; | 28 class ChromotingHostContext; |
33 class DesktopEnvironmentFactory; | 29 class DesktopEnvironmentFactory; |
34 class HostEventLogger; | 30 class HostEventLogger; |
35 class HostStatusLogger; | 31 class HostStatusLogger; |
36 class PolicyWatcher; | |
37 class RegisterSupportHostRequest; | 32 class RegisterSupportHostRequest; |
38 class RsaKeyPair; | 33 class RsaKeyPair; |
39 | 34 |
40 // These state values are duplicated in host_session.js. Remember to update | 35 // These state values are duplicated in host_session.js. Remember to update |
41 // both copies when making changes. | 36 // both copies when making changes. |
42 enum It2MeHostState { | 37 enum It2MeHostState { |
43 kDisconnected, | 38 kDisconnected, |
44 kStarting, | 39 kStarting, |
45 kRequestedAccessCode, | 40 kRequestedAccessCode, |
46 kReceivedAccessCode, | 41 kReceivedAccessCode, |
(...skipping 11 matching lines...) Expand all Loading... |
58 public: | 53 public: |
59 virtual void OnClientAuthenticated(const std::string& client_username) = 0; | 54 virtual void OnClientAuthenticated(const std::string& client_username) = 0; |
60 virtual void OnStoreAccessCode(const std::string& access_code, | 55 virtual void OnStoreAccessCode(const std::string& access_code, |
61 base::TimeDelta access_code_lifetime) = 0; | 56 base::TimeDelta access_code_lifetime) = 0; |
62 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) = 0; | 57 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) = 0; |
63 virtual void OnStateChanged(It2MeHostState state, | 58 virtual void OnStateChanged(It2MeHostState state, |
64 const std::string& error_message) = 0; | 59 const std::string& error_message) = 0; |
65 }; | 60 }; |
66 | 61 |
67 It2MeHost(std::unique_ptr<ChromotingHostContext> context, | 62 It2MeHost(std::unique_ptr<ChromotingHostContext> context, |
68 std::unique_ptr<PolicyWatcher> policy_watcher, | |
69 std::unique_ptr<It2MeConfirmationDialogFactory> dialog_factory_, | 63 std::unique_ptr<It2MeConfirmationDialogFactory> dialog_factory_, |
70 base::WeakPtr<It2MeHost::Observer> observer, | 64 base::WeakPtr<It2MeHost::Observer> observer, |
71 std::unique_ptr<SignalStrategy> signal_strategy, | 65 std::unique_ptr<SignalStrategy> signal_strategy, |
72 const std::string& username, | 66 const std::string& username, |
73 const std::string& directory_bot_jid); | 67 const std::string& directory_bot_jid); |
74 | 68 |
75 // Methods called by the script object, from the plugin thread. | 69 // Methods called by the script object, from the plugin thread. |
76 | 70 |
77 // Creates It2Me host structures and starts the host. | 71 // Creates It2Me host structures and starts the host. |
78 virtual void Connect(); | 72 virtual void Connect(); |
(...skipping 13 matching lines...) Expand all Loading... |
92 void SetStateForTesting(It2MeHostState state, | 86 void SetStateForTesting(It2MeHostState state, |
93 const std::string& error_message) { | 87 const std::string& error_message) { |
94 SetState(state, error_message); | 88 SetState(state, error_message); |
95 } | 89 } |
96 | 90 |
97 // Returns the callback used for validating the connection. Do not run the | 91 // Returns the callback used for validating the connection. Do not run the |
98 // returned callback after this object has been destroyed. | 92 // returned callback after this object has been destroyed. |
99 protocol::ValidatingAuthenticator::ValidationCallback | 93 protocol::ValidatingAuthenticator::ValidationCallback |
100 GetValidationCallbackForTesting(); | 94 GetValidationCallbackForTesting(); |
101 | 95 |
| 96 // Called when initial policies are read and when they change. |
| 97 void OnPolicyUpdate(std::unique_ptr<base::DictionaryValue> policies); |
| 98 |
102 protected: | 99 protected: |
103 friend class base::RefCountedThreadSafe<It2MeHost>; | 100 friend class base::RefCountedThreadSafe<It2MeHost>; |
104 | 101 |
105 ~It2MeHost() override; | 102 ~It2MeHost() override; |
106 | 103 |
107 ChromotingHostContext* host_context() { return host_context_.get(); } | 104 ChromotingHostContext* host_context() { return host_context_.get(); } |
108 base::WeakPtr<It2MeHost::Observer> observer() { return observer_; } | 105 base::WeakPtr<It2MeHost::Observer> observer() { return observer_; } |
109 | 106 |
110 private: | 107 private: |
111 // Updates state of the host. Can be called only on the network thread. | 108 // Updates state of the host. Can be called only on the network thread. |
(...skipping 11 matching lines...) Expand all Loading... |
123 void ReadPolicyAndConnect(); | 120 void ReadPolicyAndConnect(); |
124 | 121 |
125 // Called by ReadPolicyAndConnect once policies have been read. | 122 // Called by ReadPolicyAndConnect once policies have been read. |
126 void FinishConnect(); | 123 void FinishConnect(); |
127 | 124 |
128 // Called when the support host registration completes. | 125 // Called when the support host registration completes. |
129 void OnReceivedSupportID(const std::string& support_id, | 126 void OnReceivedSupportID(const std::string& support_id, |
130 const base::TimeDelta& lifetime, | 127 const base::TimeDelta& lifetime, |
131 const std::string& error_message); | 128 const std::string& error_message); |
132 | 129 |
133 // Called when initial policies are read, and when they change. | |
134 void OnPolicyUpdate(std::unique_ptr<base::DictionaryValue> policies); | |
135 | |
136 // Called when malformed policies are detected. | |
137 void OnPolicyError(); | |
138 | |
139 // Handlers for NAT traversal and domain policies. | 130 // Handlers for NAT traversal and domain policies. |
140 void UpdateNatPolicy(bool nat_traversal_enabled); | 131 void UpdateNatPolicy(bool nat_traversal_enabled); |
141 void UpdateHostDomainListPolicy(std::vector<std::string> host_domain_list); | 132 void UpdateHostDomainListPolicy(std::vector<std::string> host_domain_list); |
142 void UpdateClientDomainListPolicy( | 133 void UpdateClientDomainListPolicy( |
143 std::vector<std::string> client_domain_list); | 134 std::vector<std::string> client_domain_list); |
144 | 135 |
145 void DisconnectOnNetworkThread(); | 136 void DisconnectOnNetworkThread(); |
146 | 137 |
147 // Uses details of the connection and current policies to determine if the | 138 // Uses details of the connection and current policies to determine if the |
148 // connection should be accepted or rejected. | 139 // connection should be accepted or rejected. |
(...skipping 12 matching lines...) Expand all Loading... |
161 | 152 |
162 scoped_refptr<RsaKeyPair> host_key_pair_; | 153 scoped_refptr<RsaKeyPair> host_key_pair_; |
163 std::unique_ptr<RegisterSupportHostRequest> register_request_; | 154 std::unique_ptr<RegisterSupportHostRequest> register_request_; |
164 std::unique_ptr<HostStatusLogger> host_status_logger_; | 155 std::unique_ptr<HostStatusLogger> host_status_logger_; |
165 std::unique_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 156 std::unique_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
166 std::unique_ptr<HostEventLogger> host_event_logger_; | 157 std::unique_ptr<HostEventLogger> host_event_logger_; |
167 | 158 |
168 std::unique_ptr<ChromotingHost> host_; | 159 std::unique_ptr<ChromotingHost> host_; |
169 int failed_login_attempts_ = 0; | 160 int failed_login_attempts_ = 0; |
170 | 161 |
171 std::unique_ptr<PolicyWatcher> policy_watcher_; | |
172 std::unique_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory_; | 162 std::unique_ptr<It2MeConfirmationDialogFactory> confirmation_dialog_factory_; |
173 std::unique_ptr<It2MeConfirmationDialogProxy> confirmation_dialog_proxy_; | 163 std::unique_ptr<It2MeConfirmationDialogProxy> confirmation_dialog_proxy_; |
174 | 164 |
175 // Host the current nat traversal policy setting. | 165 // Host the current nat traversal policy setting. |
176 bool nat_traversal_enabled_ = false; | 166 bool nat_traversal_enabled_ = false; |
177 | 167 |
178 // The client and host domain policy setting. | 168 // The client and host domain policy setting. |
179 std::vector<std::string> required_client_domain_list_; | 169 std::vector<std::string> required_client_domain_list_; |
180 std::vector<std::string> required_host_domain_list_; | 170 std::vector<std::string> required_host_domain_list_; |
181 | 171 |
(...skipping 14 matching lines...) Expand all Loading... |
196 DISALLOW_COPY_AND_ASSIGN(It2MeHost); | 186 DISALLOW_COPY_AND_ASSIGN(It2MeHost); |
197 }; | 187 }; |
198 | 188 |
199 // Having a factory interface makes it possible for the test to provide a mock | 189 // Having a factory interface makes it possible for the test to provide a mock |
200 // implementation of the It2MeHost. | 190 // implementation of the It2MeHost. |
201 class It2MeHostFactory { | 191 class It2MeHostFactory { |
202 public: | 192 public: |
203 It2MeHostFactory(); | 193 It2MeHostFactory(); |
204 virtual ~It2MeHostFactory(); | 194 virtual ~It2MeHostFactory(); |
205 | 195 |
206 // |policy_service| is used for creating the policy watcher for new | |
207 // instances of It2MeHost on ChromeOS. The caller must ensure that | |
208 // |policy_service| is valid throughout the lifetime of each created It2MeHost | |
209 // object. This is currently possible because |policy_service| is a global | |
210 // singleton available from the browser process. | |
211 virtual scoped_refptr<It2MeHost> CreateIt2MeHost( | 196 virtual scoped_refptr<It2MeHost> CreateIt2MeHost( |
212 std::unique_ptr<ChromotingHostContext> context, | 197 std::unique_ptr<ChromotingHostContext> context, |
213 policy::PolicyService* policy_service, | |
214 base::WeakPtr<It2MeHost::Observer> observer, | 198 base::WeakPtr<It2MeHost::Observer> observer, |
215 std::unique_ptr<SignalStrategy> signal_strategy, | 199 std::unique_ptr<SignalStrategy> signal_strategy, |
216 const std::string& username, | 200 const std::string& username, |
217 const std::string& directory_bot_jid); | 201 const std::string& directory_bot_jid); |
218 | 202 |
219 private: | 203 private: |
220 DISALLOW_COPY_AND_ASSIGN(It2MeHostFactory); | 204 DISALLOW_COPY_AND_ASSIGN(It2MeHostFactory); |
221 }; | 205 }; |
222 | 206 |
223 } // namespace remoting | 207 } // namespace remoting |
224 | 208 |
225 #endif // REMOTING_HOST_IT2ME_IT2ME_HOST_H_ | 209 #endif // REMOTING_HOST_IT2ME_IT2ME_HOST_H_ |
OLD | NEW |