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
3 // found in the LICENSE file.
5 #ifndef REMOTING_HOST_IT2ME_IT2ME_HOST_H_
6 #define REMOTING_HOST_IT2ME_IT2ME_HOST_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/single_thread_task_runner.h"
11 #include "remoting/host/log_to_server.h"
12 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
16 class RegisterSupportHostRequest;
17 class HostNPScriptObject;
18 class DesktopEnvironmentFactory;
19 class HostEventLogger;
21 class ChromotingHostContext;
23 namespace policy_hack {
27 } // namespace policy_hack
29 // These state values are duplicated in host_session.js. Remember to update
30 // both copies when making changes.
42 // Internal implementation of the plugin's It2Me host function.
44 : public base::RefCountedThreadSafe<It2MeHost>,
45 public HostStatusObserver {
50 virtual void OnClientAuthenticated(const std::string& client_username) = 0;
51 virtual void OnStoreAccessCode(const std::string& access_code,
52 base::TimeDelta access_code_lifetime) = 0;
53 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) = 0;
54 virtual void OnStateChanged(It2MeHostState state) = 0;
58 scoped_ptr<ChromotingHostContext> context,
59 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner,
60 base::WeakPtr<It2MeHost::Observer> observer,
61 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
62 const std::string& directory_bot_jid);
64 // Methods called by the script object, from the plugin thread.
66 // Creates It2Me host structures and starts the host.
69 // Disconnects the host, ready for tear-down.
70 // Also called internally, from the network thread.
73 // Request a NAT policy notification.
74 void RequestNatPolicy();
76 // remoting::HostStatusObserver implementation.
77 virtual void OnAccessDenied(const std::string& jid) OVERRIDE;
78 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE;
79 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE;
82 friend class base::RefCountedThreadSafe<It2MeHost>;
86 // Updates state of the host. Can be called only on the network thread.
87 void SetState(It2MeHostState state);
89 // Returns true if the host is connected.
90 bool IsConnected() const;
92 // Called by Connect() to check for policies and start connection process.
93 void ReadPolicyAndConnect();
95 // Called by ReadPolicyAndConnect once policies have been read.
98 // Called when the support host registration completes.
99 void OnReceivedSupportID(bool success,
100 const std::string& support_id,
101 const base::TimeDelta& lifetime);
103 // Shuts down |host_| on the network thread and posts ShutdownOnUiThread()
104 // to shut down UI thread resources.
105 void ShutdownOnNetworkThread();
107 // Shuts down |desktop_environment_factory_| and |policy_watcher_| on
109 void ShutdownOnUiThread();
111 // Called when initial policies are read, and when they change.
112 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies);
114 // Handlers for NAT traversal and host domain policies.
115 void UpdateNatPolicy(bool nat_traversal_enabled);
116 void UpdateHostDomainPolicy(const std::string& host_domain);
118 // Caller supplied fields.
119 scoped_ptr<ChromotingHostContext> host_context_;
120 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_;
121 base::WeakPtr<It2MeHost::Observer> observer_;
122 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
123 std::string directory_bot_jid_;
125 It2MeHostState state_;
127 scoped_refptr<RsaKeyPair> host_key_pair_;
128 scoped_ptr<SignalStrategy> signal_strategy_;
129 scoped_ptr<RegisterSupportHostRequest> register_request_;
130 scoped_ptr<LogToServer> log_to_server_;
131 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
132 scoped_ptr<HostEventLogger> host_event_logger_;
134 scoped_ptr<ChromotingHost> host_;
135 int failed_login_attempts_;
137 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_;
139 // Host the current nat traversal policy setting.
140 bool nat_traversal_enabled_;
142 // The host domain policy setting.
143 std::string required_host_domain_;
145 // Indicates whether or not a policy has ever been read. This is to ensure
146 // that on startup, we do not accidentally start a connection before we have
147 // queried our policy restrictions.
148 bool policy_received_;
150 // On startup, it is possible to have Connect() called before the policy read
151 // is completed. Rather than just failing, we thunk the connection call so
152 // it can be executed after at least one successful policy read. This
153 // variable contains the thunk if it is necessary.
154 base::Closure pending_connect_;
156 DISALLOW_COPY_AND_ASSIGN(It2MeHost);
159 } // namespace remoting
161 #endif // REMOTING_HOST_IT2ME_IT2ME_HOST_H_