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

Side by Side Diff: remoting/host/chromoting_host.h

Issue 13466014: Made the ChromotingHost class not ref-counted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback. Created 7 years, 8 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 | « no previous file | remoting/host/chromoting_host.cc » ('j') | remoting/host/chromoting_host.cc » ('J')
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_CHROMOTING_HOST_H_ 5 #ifndef REMOTING_HOST_CHROMOTING_HOST_H_
6 #define REMOTING_HOST_CHROMOTING_HOST_H_ 6 #define REMOTING_HOST_CHROMOTING_HOST_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "base/threading/non_thread_safe.h"
15 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
16 #include "net/base/backoff_entry.h" 17 #include "net/base/backoff_entry.h"
17 #include "remoting/host/client_session.h" 18 #include "remoting/host/client_session.h"
18 #include "remoting/host/host_status_monitor.h" 19 #include "remoting/host/host_status_monitor.h"
19 #include "remoting/host/host_status_observer.h" 20 #include "remoting/host/host_status_observer.h"
20 #include "remoting/protocol/authenticator.h" 21 #include "remoting/protocol/authenticator.h"
21 #include "remoting/protocol/session_manager.h" 22 #include "remoting/protocol/session_manager.h"
22 #include "remoting/protocol/connection_to_client.h" 23 #include "remoting/protocol/connection_to_client.h"
23 #include "third_party/skia/include/core/SkSize.h" 24 #include "third_party/skia/include/core/SkSize.h"
24 25
(...skipping 27 matching lines...) Expand all
52 // ConnectionToClient to receive mouse / keyboard events from the remote 53 // ConnectionToClient to receive mouse / keyboard events from the remote
53 // client. 54 // client.
54 // After we have done all the initialization we'll start the ScreenRecorder. 55 // After we have done all the initialization we'll start the ScreenRecorder.
55 // We'll then enter the running state of the host process. 56 // We'll then enter the running state of the host process.
56 // 57 //
57 // 3. When the user is disconnected, we will pause the ScreenRecorder 58 // 3. When the user is disconnected, we will pause the ScreenRecorder
58 // and try to terminate the threads we have created. This will allow 59 // and try to terminate the threads we have created. This will allow
59 // all pending tasks to complete. After all of that completed we 60 // all pending tasks to complete. After all of that completed we
60 // return to the idle state. We then go to step (2) if there a new 61 // return to the idle state. We then go to step (2) if there a new
61 // incoming connection. 62 // incoming connection.
62 class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, 63 class ChromotingHost : public base::NonThreadSafe,
63 public ClientSession::EventHandler, 64 public ClientSession::EventHandler,
64 public protocol::SessionManager::Listener, 65 public protocol::SessionManager::Listener,
65 public HostStatusMonitor { 66 public HostStatusMonitor {
66 public: 67 public:
67 // The caller must ensure that |signal_strategy| and 68 // Both |signal_strategy| and |desktop_environment_factory| should outlive
68 // |desktop_environment_factory| remain valid at least until the 69 // this object.
69 // |shutdown_task| supplied to Shutdown() has been notified.
70 ChromotingHost( 70 ChromotingHost(
71 SignalStrategy* signal_strategy, 71 SignalStrategy* signal_strategy,
72 DesktopEnvironmentFactory* desktop_environment_factory, 72 DesktopEnvironmentFactory* desktop_environment_factory,
73 scoped_ptr<protocol::SessionManager> session_manager, 73 scoped_ptr<protocol::SessionManager> session_manager,
74 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, 74 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
75 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, 75 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
76 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, 76 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner,
77 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, 77 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner,
78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
79 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); 79 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
80 virtual ~ChromotingHost();
80 81
81 // Asynchronously start the host process. 82 // Asynchronously starts the host.
82 // 83 //
83 // After this is invoked, the host process will connect to the talk 84 // After this is invoked, the host process will connect to the talk
84 // network and start listening for incoming connections. 85 // network and start listening for incoming connections.
85 // 86 //
86 // This method can only be called once during the lifetime of this object. 87 // This method can only be called once during the lifetime of this object.
87 void Start(const std::string& xmpp_login); 88 void Start(const std::string& xmpp_login);
88 89
89 // Asynchronously shutdown the host process. |shutdown_task| is
90 // called after shutdown is completed.
91 void Shutdown(const base::Closure& shutdown_task);
92
93 // HostStatusMonitor interface. 90 // HostStatusMonitor interface.
94 virtual void AddStatusObserver(HostStatusObserver* observer) OVERRIDE; 91 virtual void AddStatusObserver(HostStatusObserver* observer) OVERRIDE;
95 virtual void RemoveStatusObserver(HostStatusObserver* observer) OVERRIDE; 92 virtual void RemoveStatusObserver(HostStatusObserver* observer) OVERRIDE;
96 93
97 // This method may be called only from 94 // This method may be called only from
98 // HostStatusObserver::OnClientAuthenticated() to reject the new 95 // HostStatusObserver::OnClientAuthenticated() to reject the new
99 // client. 96 // client.
100 void RejectAuthenticatingClient(); 97 void RejectAuthenticatingClient();
101 98
102 // Sets the authenticator factory to use for incoming 99 // Sets the authenticator factory to use for incoming
(...skipping 24 matching lines...) Expand all
127 124
128 // SessionManager::Listener implementation. 125 // SessionManager::Listener implementation.
129 virtual void OnSessionManagerReady() OVERRIDE; 126 virtual void OnSessionManagerReady() OVERRIDE;
130 virtual void OnIncomingSession( 127 virtual void OnIncomingSession(
131 protocol::Session* session, 128 protocol::Session* session,
132 protocol::SessionManager::IncomingSessionResponse* response) OVERRIDE; 129 protocol::SessionManager::IncomingSessionResponse* response) OVERRIDE;
133 130
134 // Sets desired configuration for the protocol. Must be called before Start(). 131 // Sets desired configuration for the protocol. Must be called before Start().
135 void set_protocol_config(scoped_ptr<protocol::CandidateSessionConfig> config); 132 void set_protocol_config(scoped_ptr<protocol::CandidateSessionConfig> config);
136 133
137 // Disconnects all active clients. Clients are disconnected 134 // Disconnects all active clients synchronously. Sub-components might shutdown
138 // asynchronously when this method is called on a thread other than 135 // asynchronously (when they are running on different threads). No callbacks
139 // the network thread. Potentically this may cause disconnection of 136 // will be posted to the host in any case.
140 // clients that were not connected when this method is called.
141 void DisconnectAllClients(); 137 void DisconnectAllClients();
142 138
143 base::WeakPtr<ChromotingHost> AsWeakPtr() { 139 base::WeakPtr<ChromotingHost> AsWeakPtr() {
144 return weak_factory_.GetWeakPtr(); 140 return weak_factory_.GetWeakPtr();
145 } 141 }
146 142
147 private: 143 private:
148 friend class base::RefCountedThreadSafe<ChromotingHost>;
149 friend class ChromotingHostTest; 144 friend class ChromotingHostTest;
150 145
151 typedef std::list<ClientSession*> ClientList; 146 typedef std::list<ClientSession*> ClientList;
152 147
153 enum State { 148 enum State {
Wez 2013/04/09 01:08:21 No longer used? :D
alexeypa (please no reviews) 2013/04/12 18:22:26 Done.
154 kInitial, 149 kInitial,
155 kStarted, 150 kStarted,
156 kStopping,
157 kStopped, 151 kStopped,
158 }; 152 };
159 153
160 virtual ~ChromotingHost();
161
162 // Called from Shutdown() to finish shutdown.
163 void ShutdownFinish();
164
165 // Unless specified otherwise all members of this class must be 154 // Unless specified otherwise all members of this class must be
166 // used on the network thread only. 155 // used on the network thread only.
167 156
168 // Parameters specified when the host was created. 157 // Parameters specified when the host was created.
169 DesktopEnvironmentFactory* desktop_environment_factory_; 158 DesktopEnvironmentFactory* desktop_environment_factory_;
170 scoped_ptr<protocol::SessionManager> session_manager_; 159 scoped_ptr<protocol::SessionManager> session_manager_;
171 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; 160 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
172 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_; 161 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_;
173 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_; 162 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner_;
174 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_; 163 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner_;
175 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 164 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
176 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 165 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
177 166
178 // Connection objects. 167 // Connection objects.
179 SignalStrategy* signal_strategy_; 168 SignalStrategy* signal_strategy_;
180 169
181 // Must be used on the network thread only. 170 // Must be used on the network thread only.
182 ObserverList<HostStatusObserver> status_observers_; 171 ObserverList<HostStatusObserver> status_observers_;
183 172
184 // The connections to remote clients. 173 // The connections to remote clients.
185 ClientList clients_; 174 ClientList clients_;
186 175
187 // Tracks the internal state of the host. 176 // True if the host has been started.
188 State state_; 177 bool started_;
189 178
190 // Configuration of the protocol. 179 // Configuration of the protocol.
191 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_; 180 scoped_ptr<protocol::CandidateSessionConfig> protocol_config_;
192 181
193 // Login backoff state. 182 // Login backoff state.
194 net::BackoffEntry login_backoff_; 183 net::BackoffEntry login_backoff_;
195 184
196 // Flags used for RejectAuthenticatingClient(). 185 // Flags used for RejectAuthenticatingClient().
197 bool authenticating_client_; 186 bool authenticating_client_;
198 bool reject_authenticating_client_; 187 bool reject_authenticating_client_;
199 188
200 // Stores list of tasks that should be executed when we finish
201 // shutdown. Used only while |state_| is set to kStopping.
202 std::vector<base::Closure> shutdown_tasks_;
203
204 // The maximum duration of any session. 189 // The maximum duration of any session.
205 base::TimeDelta max_session_duration_; 190 base::TimeDelta max_session_duration_;
206 191
207 base::WeakPtrFactory<ChromotingHost> weak_factory_; 192 base::WeakPtrFactory<ChromotingHost> weak_factory_;
208 193
209 DISALLOW_COPY_AND_ASSIGN(ChromotingHost); 194 DISALLOW_COPY_AND_ASSIGN(ChromotingHost);
210 }; 195 };
211 196
212 } // namespace remoting 197 } // namespace remoting
213 198
214 #endif // REMOTING_HOST_CHROMOTING_HOST_H_ 199 #endif // REMOTING_HOST_CHROMOTING_HOST_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/host/chromoting_host.cc » ('j') | remoting/host/chromoting_host.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698