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

Side by Side Diff: remoting/host/plugin/host_script_object.cc

Issue 13466014: Made the ChromotingHost class not ref-counted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cosmetic 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
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 #include "remoting/host/plugin/host_script_object.h" 5 #include "remoting/host/plugin/host_script_object.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // Called by ReadPolicyAndConnect once policies have been read. 135 // Called by ReadPolicyAndConnect once policies have been read.
136 void FinishConnect(const std::string& uid, 136 void FinishConnect(const std::string& uid,
137 const std::string& auth_token, 137 const std::string& auth_token,
138 const std::string& auth_service); 138 const std::string& auth_service);
139 139
140 // Called when the support host registration completes. 140 // Called when the support host registration completes.
141 void OnReceivedSupportID(bool success, 141 void OnReceivedSupportID(bool success,
142 const std::string& support_id, 142 const std::string& support_id,
143 const base::TimeDelta& lifetime); 143 const base::TimeDelta& lifetime);
144 144
145 // Called when ChromotingHost::Shutdown() has completed. 145 // Shuts down |host_| on the network thread.
Wez 2013/04/02 19:58:33 nit: ... and posts ShutdownOnUiThread() to shut do
alexeypa (please no reviews) 2013/04/08 23:28:17 Done.
146 void OnShutdownFinished(); 146 void ShutdownOnNetworkThread();
147
148 // Shuts down |desktop_environment_factory_| and |policy_watcher_| on
149 // the UI thread.
150 void ShutdownOnUiThread();
147 151
148 // Called when initial policies are read, and when they change. 152 // Called when initial policies are read, and when they change.
149 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies); 153 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies);
150 154
151 // Handlers for NAT traversal and host domain policies. 155 // Handlers for NAT traversal and host domain policies.
152 void UpdateNatPolicy(bool nat_traversal_enabled); 156 void UpdateNatPolicy(bool nat_traversal_enabled);
153 void UpdateHostDomainPolicy(const std::string& host_domain); 157 void UpdateHostDomainPolicy(const std::string& host_domain);
154 158
155 // Caller supplied fields. 159 // Caller supplied fields.
156 scoped_ptr<ChromotingHostContext> host_context_; 160 scoped_ptr<ChromotingHostContext> host_context_;
157 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_; 161 scoped_refptr<base::SingleThreadTaskRunner> plugin_task_runner_;
158 base::WeakPtr<HostNPScriptObject> script_object_; 162 base::WeakPtr<HostNPScriptObject> script_object_;
159 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; 163 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
160 std::string directory_bot_jid_; 164 std::string directory_bot_jid_;
161 165
162 State state_; 166 State state_;
163 167
164 scoped_refptr<RsaKeyPair> host_key_pair_; 168 scoped_refptr<RsaKeyPair> host_key_pair_;
165 scoped_ptr<SignalStrategy> signal_strategy_; 169 scoped_ptr<SignalStrategy> signal_strategy_;
166 scoped_ptr<RegisterSupportHostRequest> register_request_; 170 scoped_ptr<RegisterSupportHostRequest> register_request_;
167 scoped_ptr<LogToServer> log_to_server_; 171 scoped_ptr<LogToServer> log_to_server_;
168 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; 172 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
169 scoped_ptr<HostEventLogger> host_event_logger_; 173 scoped_ptr<HostEventLogger> host_event_logger_;
170 174
171 scoped_refptr<ChromotingHost> host_; 175 scoped_ptr<ChromotingHost> host_;
172 int failed_login_attempts_; 176 int failed_login_attempts_;
173 177
174 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; 178 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_;
175 179
176 // Host the current nat traversal policy setting. 180 // Host the current nat traversal policy setting.
177 bool nat_traversal_enabled_; 181 bool nat_traversal_enabled_;
178 182
179 // The host domain policy setting. 183 // The host domain policy setting.
180 std::string required_host_domain_; 184 std::string required_host_domain_;
181 185
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 void HostNPScriptObject::It2MeImpl::Disconnect() { 251 void HostNPScriptObject::It2MeImpl::Disconnect() {
248 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 252 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
249 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 253 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
250 host_context_->network_task_runner()->PostTask( 254 host_context_->network_task_runner()->PostTask(
251 FROM_HERE, base::Bind(&It2MeImpl::Disconnect, this)); 255 FROM_HERE, base::Bind(&It2MeImpl::Disconnect, this));
252 return; 256 return;
253 } 257 }
254 258
255 switch (state_) { 259 switch (state_) {
256 case kDisconnected: 260 case kDisconnected:
257 OnShutdownFinished(); 261 ShutdownOnUiThread();
Wez 2013/04/02 19:58:33 nit: Call ShutdownOnNetworkThread() here and let t
alexeypa (please no reviews) 2013/04/08 23:28:17 Done.
258 return; 262 return;
259 263
260 case kStarting: 264 case kStarting:
261 SetState(kDisconnecting); 265 SetState(kDisconnecting);
262 SetState(kDisconnected); 266 SetState(kDisconnected);
263 OnShutdownFinished(); 267 ShutdownOnUiThread();
264 return; 268 return;
265 269
266 case kDisconnecting: 270 case kDisconnecting:
267 return; 271 return;
268 272
269 default: 273 default:
270 SetState(kDisconnecting); 274 SetState(kDisconnecting);
271 275
272 if (!host_) { 276 if (!host_) {
273 OnShutdownFinished(); 277 SetState(kDisconnected);
278 ShutdownOnUiThread();
274 return; 279 return;
275 } 280 }
276 281
277 // ChromotingHost::Shutdown() may destroy SignalStrategy 282 // ChromotingHost::Shutdown() may destroy SignalStrategy
278 // synchronously, but SignalStrategy::Listener handlers are not 283 // synchronously, but SignalStrategy::Listener handlers are not
279 // allowed to destroy SignalStrategy, so post task to call 284 // allowed to destroy SignalStrategy, so post task to call
280 // Shutdown() later. 285 // ChromotingHost::Shutdown() later.
Wez 2013/04/02 19:58:33 nit: Move this comment into ShutdownOnNetworkThrea
alexeypa (please no reviews) 2013/04/08 23:28:17 It will not work because HostNPScriptObject::It2Me
281 host_context_->network_task_runner()->PostTask( 286 host_context_->network_task_runner()->PostTask(
282 FROM_HERE, base::Bind( 287 FROM_HERE, base::Bind(&It2MeImpl::ShutdownOnNetworkThread, this));
283 &ChromotingHost::Shutdown, host_,
284 base::Bind(&It2MeImpl::OnShutdownFinished, this)));
285 return; 288 return;
286 } 289 }
287 } 290 }
288 291
289 void HostNPScriptObject::It2MeImpl::RequestNatPolicy() { 292 void HostNPScriptObject::It2MeImpl::RequestNatPolicy() {
290 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { 293 if (!host_context_->network_task_runner()->BelongsToCurrentThread()) {
291 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 294 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
292 host_context_->network_task_runner()->PostTask( 295 host_context_->network_task_runner()->PostTask(
293 FROM_HERE, base::Bind(&It2MeImpl::RequestNatPolicy, this)); 296 FROM_HERE, base::Bind(&It2MeImpl::RequestNatPolicy, this));
294 return; 297 return;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 NetworkSettings network_settings( 365 NetworkSettings network_settings(
363 nat_traversal_enabled_ ? 366 nat_traversal_enabled_ ?
364 NetworkSettings::NAT_TRAVERSAL_ENABLED : 367 NetworkSettings::NAT_TRAVERSAL_ENABLED :
365 NetworkSettings::NAT_TRAVERSAL_DISABLED); 368 NetworkSettings::NAT_TRAVERSAL_DISABLED);
366 if (!nat_traversal_enabled_) { 369 if (!nat_traversal_enabled_) {
367 network_settings.min_port = NetworkSettings::kDefaultMinPort; 370 network_settings.min_port = NetworkSettings::kDefaultMinPort;
368 network_settings.max_port = NetworkSettings::kDefaultMaxPort; 371 network_settings.max_port = NetworkSettings::kDefaultMaxPort;
369 } 372 }
370 373
371 // Create the host. 374 // Create the host.
372 host_ = new ChromotingHost( 375 host_.reset(new ChromotingHost(
373 signal_strategy_.get(), 376 signal_strategy_.get(),
374 desktop_environment_factory_.get(), 377 desktop_environment_factory_.get(),
375 CreateHostSessionManager(network_settings, 378 CreateHostSessionManager(network_settings,
376 host_context_->url_request_context_getter()), 379 host_context_->url_request_context_getter()),
377 host_context_->audio_task_runner(), 380 host_context_->audio_task_runner(),
378 host_context_->input_task_runner(), 381 host_context_->input_task_runner(),
379 host_context_->video_capture_task_runner(), 382 host_context_->video_capture_task_runner(),
380 host_context_->video_encode_task_runner(), 383 host_context_->video_encode_task_runner(),
381 host_context_->network_task_runner(), 384 host_context_->network_task_runner(),
382 host_context_->ui_task_runner()); 385 host_context_->ui_task_runner()));
383 host_->AddStatusObserver(this); 386 host_->AddStatusObserver(this);
384 log_to_server_.reset( 387 log_to_server_.reset(
385 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::IT2ME, 388 new LogToServer(host_->AsWeakPtr(), ServerLogEntry::IT2ME,
386 signal_strategy_.get(), directory_bot_jid_)); 389 signal_strategy_.get(), directory_bot_jid_));
387 390
388 // Disable audio by default. 391 // Disable audio by default.
389 // TODO(sergeyu): Add UI to enable it. 392 // TODO(sergeyu): Add UI to enable it.
390 scoped_ptr<protocol::CandidateSessionConfig> protocol_config = 393 scoped_ptr<protocol::CandidateSessionConfig> protocol_config =
391 protocol::CandidateSessionConfig::CreateDefault(); 394 protocol::CandidateSessionConfig::CreateDefault();
392 protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get()); 395 protocol::CandidateSessionConfig::DisableAudioChannel(protocol_config.get());
393 host_->set_protocol_config(protocol_config.Pass()); 396 host_->set_protocol_config(protocol_config.Pass());
394 397
395 // Create event logger. 398 // Create event logger.
396 host_event_logger_ = 399 host_event_logger_ =
397 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName); 400 HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName);
398 401
399 // Connect signaling and start the host. 402 // Connect signaling and start the host.
400 signal_strategy_->Connect(); 403 signal_strategy_->Connect();
401 host_->Start(uid); 404 host_->Start(uid);
402 405
403 SetState(kRequestedAccessCode); 406 SetState(kRequestedAccessCode);
404 return; 407 return;
405 } 408 }
406 409
407 void HostNPScriptObject::It2MeImpl::OnShutdownFinished() { 410 void HostNPScriptObject::It2MeImpl::ShutdownOnNetworkThread() {
411 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
412 DCHECK_EQ(state_, kDisconnecting);
413
414 host_->Shutdown();
415 host_.reset();
416 SetState(kDisconnected);
417
418 ShutdownOnUiThread();
419 }
420
421 void HostNPScriptObject::It2MeImpl::ShutdownOnUiThread() {
408 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) { 422 if (!host_context_->ui_task_runner()->BelongsToCurrentThread()) {
Wez 2013/04/02 19:58:33 Rather than thread-hop here, can you move the post
alexeypa (please no reviews) 2013/04/08 23:28:17 Done.
409 host_context_->ui_task_runner()->PostTask( 423 host_context_->ui_task_runner()->PostTask(
410 FROM_HERE, base::Bind(&It2MeImpl::OnShutdownFinished, this)); 424 FROM_HERE, base::Bind(&It2MeImpl::ShutdownOnUiThread, this));
411 return; 425 return;
412 } 426 }
413 427
414 // Note that OnShutdownFinished() may be called more than once. 428 // Note that ShutdownOnUiThread() may be called more than once.
Wez 2013/04/02 19:58:33 Is this still true?
alexeypa (please no reviews) 2013/04/08 23:28:17 Done.
415 429
416 // Destroy the DesktopEnvironmentFactory, to free thread references. 430 // Destroy the DesktopEnvironmentFactory, to free thread references.
417 desktop_environment_factory_.reset(); 431 desktop_environment_factory_.reset();
418 432
419 // Stop listening for policy updates. 433 // Stop listening for policy updates.
420 if (policy_watcher_.get()) { 434 if (policy_watcher_.get()) {
421 base::WaitableEvent policy_watcher_stopped_(true, false); 435 base::WaitableEvent policy_watcher_stopped_(true, false);
422 policy_watcher_->StopWatching(&policy_watcher_stopped_); 436 policy_watcher_->StopWatching(&policy_watcher_stopped_);
423 policy_watcher_stopped_.Wait(); 437 policy_watcher_stopped_.Wait();
424 policy_watcher_.reset(); 438 policy_watcher_.reset();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 493 }
480 494
481 void HostNPScriptObject::It2MeImpl::OnShutdown() { 495 void HostNPScriptObject::It2MeImpl::OnShutdown() {
482 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 496 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
483 497
484 register_request_.reset(); 498 register_request_.reset();
485 log_to_server_.reset(); 499 log_to_server_.reset();
486 signal_strategy_.reset(); 500 signal_strategy_.reset();
487 host_event_logger_.reset(); 501 host_event_logger_.reset();
488 host_->RemoveStatusObserver(this); 502 host_->RemoveStatusObserver(this);
489 host_ = NULL;
490
491 if (state_ != kDisconnected) {
492 SetState(kDisconnected);
493 }
494 } 503 }
495 504
496 void HostNPScriptObject::It2MeImpl::OnPolicyUpdate( 505 void HostNPScriptObject::It2MeImpl::OnPolicyUpdate(
497 scoped_ptr<base::DictionaryValue> policies) { 506 scoped_ptr<base::DictionaryValue> policies) {
498 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); 507 DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread());
499 508
500 bool nat_policy; 509 bool nat_policy;
501 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName, 510 if (policies->GetBoolean(policy_hack::PolicyWatcher::kNatPolicyName,
502 &nat_policy)) { 511 &nat_policy)) {
503 UpdateNatPolicy(nat_policy); 512 UpdateNatPolicy(nat_policy);
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 } 1573 }
1565 1574
1566 void HostNPScriptObject::SetException(const std::string& exception_string) { 1575 void HostNPScriptObject::SetException(const std::string& exception_string) {
1567 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); 1576 DCHECK(plugin_task_runner_->BelongsToCurrentThread());
1568 1577
1569 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); 1578 g_npnetscape_funcs->setexception(parent_, exception_string.c_str());
1570 LOG(INFO) << exception_string; 1579 LOG(INFO) << exception_string;
1571 } 1580 }
1572 1581
1573 } // namespace remoting 1582 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698