| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/host/host_user_interface.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "remoting/host/chromoting_host.h" | |
| 9 | |
| 10 namespace remoting { | |
| 11 | |
| 12 HostUserInterface::HostUserInterface( | |
| 13 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
| 14 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | |
| 15 const UiStrings& ui_strings) | |
| 16 : host_(NULL), | |
| 17 network_task_runner_(network_task_runner), | |
| 18 ui_task_runner_(ui_task_runner), | |
| 19 ui_strings_(ui_strings), | |
| 20 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | |
| 21 weak_ptr_(weak_factory_.GetWeakPtr()) { | |
| 22 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 23 } | |
| 24 | |
| 25 HostUserInterface::~HostUserInterface() { | |
| 26 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 27 } | |
| 28 | |
| 29 void HostUserInterface::Init() { | |
| 30 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 31 } | |
| 32 | |
| 33 void HostUserInterface::Start(ChromotingHost* host, | |
| 34 const base::Closure& disconnect_callback) { | |
| 35 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
| 36 DCHECK(host_ == NULL); | |
| 37 | |
| 38 host_ = host; | |
| 39 disconnect_callback_ = disconnect_callback; | |
| 40 host_->AddStatusObserver(this); | |
| 41 } | |
| 42 | |
| 43 void HostUserInterface::OnClientAuthenticated(const std::string& jid) { | |
| 44 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
| 45 | |
| 46 authenticated_jid_ = jid; | |
| 47 | |
| 48 std::string username = jid.substr(0, jid.find('/')); | |
| 49 ui_task_runner_->PostTask(FROM_HERE, base::Bind( | |
| 50 &HostUserInterface::ProcessOnClientAuthenticated, | |
| 51 weak_ptr_, username)); | |
| 52 } | |
| 53 | |
| 54 void HostUserInterface::OnClientDisconnected(const std::string& jid) { | |
| 55 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
| 56 | |
| 57 if (jid == authenticated_jid_) { | |
| 58 ui_task_runner_->PostTask(FROM_HERE, base::Bind( | |
| 59 &HostUserInterface::ProcessOnClientDisconnected, | |
| 60 weak_ptr_)); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void HostUserInterface::OnAccessDenied(const std::string& jid) { | |
| 65 } | |
| 66 | |
| 67 void HostUserInterface::OnShutdown() { | |
| 68 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
| 69 | |
| 70 // Host status observers must be removed on the network thread, so | |
| 71 // it must happen here instead of in the destructor. | |
| 72 host_->RemoveStatusObserver(this); | |
| 73 host_ = NULL; | |
| 74 } | |
| 75 | |
| 76 void HostUserInterface::OnDisconnectCallback() { | |
| 77 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 78 | |
| 79 DisconnectSession(); | |
| 80 } | |
| 81 | |
| 82 base::SingleThreadTaskRunner* HostUserInterface::network_task_runner() const { | |
| 83 return network_task_runner_; | |
| 84 } | |
| 85 | |
| 86 base::SingleThreadTaskRunner* HostUserInterface::ui_task_runner() const { | |
| 87 return ui_task_runner_; | |
| 88 } | |
| 89 | |
| 90 void HostUserInterface::DisconnectSession() const { | |
| 91 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 92 | |
| 93 disconnect_callback_.Run(); | |
| 94 } | |
| 95 | |
| 96 void HostUserInterface::ProcessOnClientAuthenticated( | |
| 97 const std::string& username) { | |
| 98 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 99 } | |
| 100 | |
| 101 void HostUserInterface::ProcessOnClientDisconnected() { | |
| 102 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 103 } | |
| 104 | |
| 105 } // namespace remoting | |
| OLD | NEW |