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

Side by Side Diff: remoting/host/it2me/it2me_host.h

Issue 639233002: Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ChromotingHostContext cleanup Created 6 years, 2 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
OLDNEW
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
19 namespace remoting { 23 namespace remoting {
20 24
21 class ChromotingHost; 25 class ChromotingHost;
22 class ChromotingHostContext; 26 class ChromotingHostContext;
23 class DesktopEnvironmentFactory; 27 class DesktopEnvironmentFactory;
24 class HostEventLogger; 28 class HostEventLogger;
25 class HostNPScriptObject; 29 class HostNPScriptObject;
26 class HostStatusLogger; 30 class HostStatusLogger;
27 class RegisterSupportHostRequest; 31 class RegisterSupportHostRequest;
28 class RsaKeyPair; 32 class RsaKeyPair;
29 33
30 namespace policy_hack { 34 namespace policy_hack {
31
32 class PolicyWatcher; 35 class PolicyWatcher;
33
34 } // namespace policy_hack 36 } // namespace policy_hack
35 37
36 // These state values are duplicated in host_session.js. Remember to update 38 // These state values are duplicated in host_session.js. Remember to update
37 // both copies when making changes. 39 // both copies when making changes.
38 enum It2MeHostState { 40 enum It2MeHostState {
39 kDisconnected, 41 kDisconnected,
40 kStarting, 42 kStarting,
41 kRequestedAccessCode, 43 kRequestedAccessCode,
42 kReceivedAccessCode, 44 kReceivedAccessCode,
43 kConnected, 45 kConnected,
44 kDisconnecting, 46 kDisconnecting,
45 kError, 47 kError,
46 kInvalidDomainError 48 kInvalidDomainError
47 }; 49 };
48 50
49 // Internal implementation of the plugin's It2Me host function. 51 // Internal implementation of the plugin's It2Me host function.
50 class It2MeHost : public base::RefCountedThreadSafe<It2MeHost>, 52 class It2MeHost : public base::RefCountedThreadSafe<It2MeHost>,
51 public HostStatusObserver { 53 public HostStatusObserver {
52 public: 54 public:
53 class Observer { 55 class Observer {
54 public: 56 public:
55 virtual void OnClientAuthenticated(const std::string& client_username) = 0; 57 virtual void OnClientAuthenticated(const std::string& client_username) = 0;
56 virtual void OnStoreAccessCode(const std::string& access_code, 58 virtual void OnStoreAccessCode(const std::string& access_code,
57 base::TimeDelta access_code_lifetime) = 0; 59 base::TimeDelta access_code_lifetime) = 0;
58 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) = 0; 60 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) = 0;
59 virtual void OnStateChanged(It2MeHostState state) = 0; 61 virtual void OnStateChanged(It2MeHostState state) = 0;
60 }; 62 };
61 63
62 It2MeHost( 64 It2MeHost(
63 ChromotingHostContext* context, 65 scoped_ptr<ChromotingHostContext> context,
64 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 66 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher,
65 base::WeakPtr<It2MeHost::Observer> observer, 67 base::WeakPtr<It2MeHost::Observer> observer,
66 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 68 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
67 const std::string& directory_bot_jid); 69 const std::string& directory_bot_jid);
68 70
69 // Methods called by the script object, from the plugin thread. 71 // Methods called by the script object, from the plugin thread.
70 72
71 // Creates It2Me host structures and starts the host. 73 // Creates It2Me host structures and starts the host.
72 virtual void Connect(); 74 virtual void Connect();
73 75
74 // Disconnects the host, ready for tear-down. 76 // Disconnects the host, ready for tear-down.
75 // Also called internally, from the network thread. 77 // Also called internally, from the network thread.
76 virtual void Disconnect(); 78 virtual void Disconnect();
77 79
78 // TODO (weitaosu): Remove RequestNatPolicy from It2MeHost. 80 // TODO (weitaosu): Remove RequestNatPolicy from It2MeHost.
79 // Request a NAT policy notification. 81 // Request a NAT policy notification.
80 virtual void RequestNatPolicy(); 82 virtual void RequestNatPolicy();
81 83
82 // remoting::HostStatusObserver implementation. 84 // remoting::HostStatusObserver implementation.
83 void OnAccessDenied(const std::string& jid) override; 85 void OnAccessDenied(const std::string& jid) override;
84 void OnClientAuthenticated(const std::string& jid) override; 86 void OnClientAuthenticated(const std::string& jid) override;
85 void OnClientDisconnected(const std::string& jid) override; 87 void OnClientDisconnected(const std::string& jid) override;
86 88
87 void SetStateForTesting(It2MeHostState state) { SetState(state); } 89 void SetStateForTesting(It2MeHostState state) { SetState(state); }
88 90
89 protected: 91 protected:
90 friend class base::RefCountedThreadSafe<It2MeHost>; 92 friend class base::RefCountedThreadSafe<It2MeHost>;
91 93
92 ~It2MeHost() override; 94 ~It2MeHost() override;
93 95
94 ChromotingHostContext* host_context() { return host_context_; } 96 ChromotingHostContext* host_context() { return host_context_.get(); }
95 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { 97 scoped_refptr<base::SingleThreadTaskRunner> task_runner() {
96 return task_runner_; 98 return task_runner_;
97 } 99 }
98 base::WeakPtr<It2MeHost::Observer> observer() { return observer_; } 100 base::WeakPtr<It2MeHost::Observer> observer() { return observer_; }
99 101
100 private: 102 private:
101 // Updates state of the host. Can be called only on the network thread. 103 // Updates state of the host. Can be called only on the network thread.
102 void SetState(It2MeHostState state); 104 void SetState(It2MeHostState state);
103 105
104 // Returns true if the host is connected. 106 // Returns true if the host is connected.
(...skipping 11 matching lines...) Expand all
116 const base::TimeDelta& lifetime); 118 const base::TimeDelta& lifetime);
117 119
118 // Shuts down |host_| on the network thread and posts ShutdownOnUiThread() 120 // Shuts down |host_| on the network thread and posts ShutdownOnUiThread()
119 // to shut down UI thread resources. 121 // to shut down UI thread resources.
120 void ShutdownOnNetworkThread(); 122 void ShutdownOnNetworkThread();
121 123
122 // Shuts down |desktop_environment_factory_| and |policy_watcher_| on 124 // Shuts down |desktop_environment_factory_| and |policy_watcher_| on
123 // the UI thread. 125 // the UI thread.
124 void ShutdownOnUiThread(); 126 void ShutdownOnUiThread();
125 127
128 // Called when |policy_watcher_| has stopped listening for changes and it is
129 // safe to delete it.
130 void OnPolicyWatcherShutdown();
131
126 // Called when initial policies are read, and when they change. 132 // Called when initial policies are read, and when they change.
127 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); 133 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies);
128 134
129 // Handlers for NAT traversal and host domain policies. 135 // Handlers for NAT traversal and host domain policies.
130 void UpdateNatPolicy(bool nat_traversal_enabled); 136 void UpdateNatPolicy(bool nat_traversal_enabled);
131 void UpdateHostDomainPolicy(const std::string& host_domain); 137 void UpdateHostDomainPolicy(const std::string& host_domain);
132 138
133 // Caller supplied fields. 139 // Caller supplied fields.
134 140 scoped_ptr<ChromotingHostContext> host_context_;
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_;
138 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 141 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
139 base::WeakPtr<It2MeHost::Observer> observer_; 142 base::WeakPtr<It2MeHost::Observer> observer_;
140 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; 143 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
141 std::string directory_bot_jid_; 144 std::string directory_bot_jid_;
142 145
143 It2MeHostState state_; 146 It2MeHostState state_;
144 147
145 scoped_refptr<RsaKeyPair> host_key_pair_; 148 scoped_refptr<RsaKeyPair> host_key_pair_;
146 scoped_ptr<SignalStrategy> signal_strategy_; 149 scoped_ptr<SignalStrategy> signal_strategy_;
147 scoped_ptr<RegisterSupportHostRequest> register_request_; 150 scoped_ptr<RegisterSupportHostRequest> register_request_;
(...skipping 23 matching lines...) Expand all
171 // variable contains the thunk if it is necessary. 174 // variable contains the thunk if it is necessary.
172 base::Closure pending_connect_; 175 base::Closure pending_connect_;
173 176
174 DISALLOW_COPY_AND_ASSIGN(It2MeHost); 177 DISALLOW_COPY_AND_ASSIGN(It2MeHost);
175 }; 178 };
176 179
177 // Having a factory interface makes it possible for the test to provide a mock 180 // Having a factory interface makes it possible for the test to provide a mock
178 // implementation of the It2MeHost. 181 // implementation of the It2MeHost.
179 class It2MeHostFactory { 182 class It2MeHostFactory {
180 public: 183 public:
181 It2MeHostFactory(); 184 // |policy_service| is used for creating the policy watcher for new
185 // instances of It2MeHost. The caller must ensure that |policy_service| is
186 // valid throughout the lifetime of the It2MeHostFactory and each created
187 // It2MeHost object.
Wez 2014/10/24 00:28:48 It2MeHost objects are ref-counted, so how can the
kelvinp 2014/10/24 21:39:42 Comments updated.
188 It2MeHostFactory(policy::PolicyService* policy_service);
182 virtual ~It2MeHostFactory(); 189 virtual ~It2MeHostFactory();
183 190
184 virtual scoped_refptr<It2MeHost> CreateIt2MeHost( 191 virtual scoped_refptr<It2MeHost> CreateIt2MeHost(
185 ChromotingHostContext* context, 192 scoped_ptr<ChromotingHostContext> context,
186 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
187 base::WeakPtr<It2MeHost::Observer> observer, 193 base::WeakPtr<It2MeHost::Observer> observer,
188 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, 194 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
189 const std::string& directory_bot_jid); 195 const std::string& directory_bot_jid);
190 196
191 private: 197 private:
198 policy::PolicyService* policy_service_;
192 DISALLOW_COPY_AND_ASSIGN(It2MeHostFactory); 199 DISALLOW_COPY_AND_ASSIGN(It2MeHostFactory);
193 }; 200 };
194 201
195 } // namespace remoting 202 } // namespace remoting
196 203
197 #endif // REMOTING_HOST_IT2ME_IT2ME_HOST_H_ 204 #endif // REMOTING_HOST_IT2ME_IT2ME_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698