OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 344 |
345 void HostNPScriptObject::OnAccessDenied() { | 345 void HostNPScriptObject::OnAccessDenied() { |
346 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); | 346 DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread()); |
347 | 347 |
348 ++failed_login_attempts_; | 348 ++failed_login_attempts_; |
349 if (failed_login_attempts_ == kMaxLoginAttempts) | 349 if (failed_login_attempts_ == kMaxLoginAttempts) |
350 DisconnectInternal(); | 350 DisconnectInternal(); |
351 } | 351 } |
352 | 352 |
353 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { | 353 void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { |
354 DCHECK_EQ(MessageLoop::current(), host_context_.main_message_loop()); | 354 if (MessageLoop::current() != host_context_.main_message_loop()) { |
| 355 host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind( |
| 356 &HostNPScriptObject::OnClientAuthenticated, |
| 357 base::Unretained(this), jid)); |
| 358 return; |
| 359 } |
355 | 360 |
356 if (state_ == kDisconnecting) { | 361 if (state_ == kDisconnecting) { |
357 // Ignore the new connection if we are disconnecting. | 362 // Ignore the new connection if we are disconnecting. |
358 return; | 363 return; |
359 } | 364 } |
360 | 365 |
361 client_username_ = jid; | 366 client_username_ = jid; |
362 size_t pos = client_username_.find('/'); | 367 size_t pos = client_username_.find('/'); |
363 if (pos != std::string::npos) | 368 if (pos != std::string::npos) |
364 client_username_.replace(pos, std::string::npos, ""); | 369 client_username_.replace(pos, std::string::npos, ""); |
365 LOG(INFO) << "Client " << client_username_ << " connected."; | 370 LOG(INFO) << "Client " << client_username_ << " connected."; |
366 SetState(kConnected); | 371 SetState(kConnected); |
367 } | 372 } |
368 | 373 |
369 void HostNPScriptObject::OnClientDisconnected(const std::string& jid) { | 374 void HostNPScriptObject::OnClientDisconnected(const std::string& jid) { |
370 DCHECK_EQ(MessageLoop::current(), host_context_.main_message_loop()); | 375 if (MessageLoop::current() != host_context_.main_message_loop()) { |
| 376 host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind( |
| 377 &HostNPScriptObject::OnClientDisconnected, |
| 378 base::Unretained(this), jid)); |
| 379 return; |
| 380 } |
371 | 381 |
372 client_username_.clear(); | 382 client_username_.clear(); |
373 | 383 |
374 // Disconnect the host when a client disconnects. | 384 // Disconnect the host when a client disconnects. |
375 DisconnectInternal(); | 385 DisconnectInternal(); |
376 } | 386 } |
377 | 387 |
378 void HostNPScriptObject::OnShutdown() { | 388 void HostNPScriptObject::OnShutdown() { |
379 DCHECK_EQ(MessageLoop::current(), host_context_.main_message_loop()); | 389 if (MessageLoop::current() != host_context_.main_message_loop()) { |
| 390 host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind( |
| 391 &HostNPScriptObject::OnShutdown, base::Unretained(this))); |
| 392 return; |
| 393 } |
380 | 394 |
381 host_ = NULL; | 395 host_ = NULL; |
382 if (state_ != kDisconnected) { | 396 if (state_ != kDisconnected) { |
383 SetState(kDisconnected); | 397 SetState(kDisconnected); |
384 } | 398 } |
385 } | 399 } |
386 | 400 |
387 // string uid, string auth_token | 401 // string uid, string auth_token |
388 bool HostNPScriptObject::Connect(const NPVariant* args, | 402 bool HostNPScriptObject::Connect(const NPVariant* args, |
389 uint32_t arg_count, | 403 uint32_t arg_count, |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 | 590 |
577 default: | 591 default: |
578 DCHECK(host_); | 592 DCHECK(host_); |
579 SetState(kDisconnecting); | 593 SetState(kDisconnecting); |
580 host_->Shutdown( | 594 host_->Shutdown( |
581 NewRunnableMethod(this, &HostNPScriptObject::OnShutdownFinished)); | 595 NewRunnableMethod(this, &HostNPScriptObject::OnShutdownFinished)); |
582 } | 596 } |
583 } | 597 } |
584 | 598 |
585 void HostNPScriptObject::OnShutdownFinished() { | 599 void HostNPScriptObject::OnShutdownFinished() { |
586 DCHECK_EQ(MessageLoop::current(), host_context_.main_message_loop()); | 600 if (MessageLoop::current() != host_context_.main_message_loop()) { |
| 601 host_context_.main_message_loop()->PostTask(FROM_HERE, base::Bind( |
| 602 &HostNPScriptObject::OnShutdownFinished, base::Unretained(this))); |
| 603 return; |
| 604 } |
587 | 605 |
588 disconnected_event_.Signal(); | 606 disconnected_event_.Signal(); |
589 } | 607 } |
590 | 608 |
591 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { | 609 void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { |
592 if (MessageLoop::current() != host_context_.main_message_loop()) { | 610 if (MessageLoop::current() != host_context_.main_message_loop()) { |
593 host_context_.main_message_loop()->PostTask( | 611 host_context_.main_message_loop()->PostTask( |
594 FROM_HERE, | 612 FROM_HERE, |
595 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, | 613 base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, |
596 base::Unretained(this), nat_traversal_enabled)); | 614 base::Unretained(this), nat_traversal_enabled)); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 uint32_t argCount) { | 837 uint32_t argCount) { |
820 NPVariant np_result; | 838 NPVariant np_result; |
821 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, | 839 bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, |
822 argCount, &np_result); | 840 argCount, &np_result); |
823 if (is_good) | 841 if (is_good) |
824 g_npnetscape_funcs->releasevariantvalue(&np_result); | 842 g_npnetscape_funcs->releasevariantvalue(&np_result); |
825 return is_good; | 843 return is_good; |
826 } | 844 } |
827 | 845 |
828 } // namespace remoting | 846 } // namespace remoting |
OLD | NEW |