OLD | NEW |
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/host_user_interface.h" | 5 #include "remoting/host/host_user_interface.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "remoting/host/chromoting_host.h" | 8 #include "remoting/host/chromoting_host.h" |
9 #include "remoting/host/chromoting_host_context.h" | 9 #include "remoting/host/chromoting_host_context.h" |
10 #include "remoting/host/disconnect_window.h" | 10 #include "remoting/host/disconnect_window.h" |
11 #include "remoting/host/local_input_monitor.h" | 11 #include "remoting/host/local_input_monitor.h" |
12 | 12 |
13 namespace remoting { | 13 namespace remoting { |
14 | 14 |
15 HostUserInterface::HostUserInterface(ChromotingHostContext* context) | 15 HostUserInterface::HostUserInterface(ChromotingHostContext* context) |
16 : host_(NULL), | 16 : host_(NULL), |
17 context_(context), | 17 context_(context), |
18 is_monitoring_local_inputs_(false), | 18 is_monitoring_local_inputs_(false), |
19 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 19 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
20 weak_ptr_(weak_factory_.GetWeakPtr()) { | 20 weak_ptr_(weak_factory_.GetWeakPtr()) { |
21 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 21 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
22 } | 22 } |
23 | 23 |
24 HostUserInterface::~HostUserInterface() { | 24 HostUserInterface::~HostUserInterface() { |
25 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 25 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
26 | 26 |
27 MonitorLocalInputs(false); | 27 MonitorLocalInputs(false); |
28 ShowDisconnectWindow(false, std::string()); | 28 ShowDisconnectWindow(false, std::string()); |
29 } | 29 } |
30 | 30 |
31 void HostUserInterface::Start(ChromotingHost* host, | 31 void HostUserInterface::Start(ChromotingHost* host, |
32 const base::Closure& disconnect_callback) { | 32 const base::Closure& disconnect_callback) { |
33 DCHECK(network_message_loop()->BelongsToCurrentThread()); | 33 DCHECK(network_task_runner()->BelongsToCurrentThread()); |
34 DCHECK(host_ == NULL); | 34 DCHECK(host_ == NULL); |
35 DCHECK(disconnect_callback_.is_null()); | 35 DCHECK(disconnect_callback_.is_null()); |
36 | 36 |
37 host_ = host; | 37 host_ = host; |
38 disconnect_callback_ = disconnect_callback; | 38 disconnect_callback_ = disconnect_callback; |
39 disconnect_window_ = DisconnectWindow::Create(); | 39 disconnect_window_ = DisconnectWindow::Create(); |
40 local_input_monitor_ = LocalInputMonitor::Create(); | 40 local_input_monitor_ = LocalInputMonitor::Create(); |
41 host_->AddStatusObserver(this); | 41 host_->AddStatusObserver(this); |
42 } | 42 } |
43 | 43 |
44 void HostUserInterface::OnClientAuthenticated(const std::string& jid) { | 44 void HostUserInterface::OnClientAuthenticated(const std::string& jid) { |
45 DCHECK(network_message_loop()->BelongsToCurrentThread()); | 45 DCHECK(network_task_runner()->BelongsToCurrentThread()); |
46 | 46 |
47 authenticated_jid_ = jid; | 47 authenticated_jid_ = jid; |
48 | 48 |
49 std::string username = jid.substr(0, jid.find('/')); | 49 std::string username = jid.substr(0, jid.find('/')); |
50 ui_message_loop()->PostTask(FROM_HERE, base::Bind( | 50 ui_task_runner()->PostTask(FROM_HERE, base::Bind( |
51 &HostUserInterface::ProcessOnClientAuthenticated, | 51 &HostUserInterface::ProcessOnClientAuthenticated, |
52 weak_ptr_, username)); | 52 weak_ptr_, username)); |
53 } | 53 } |
54 | 54 |
55 void HostUserInterface::OnClientDisconnected(const std::string& jid) { | 55 void HostUserInterface::OnClientDisconnected(const std::string& jid) { |
56 DCHECK(network_message_loop()->BelongsToCurrentThread()); | 56 DCHECK(network_task_runner()->BelongsToCurrentThread()); |
57 | 57 |
58 if (jid == authenticated_jid_) { | 58 if (jid == authenticated_jid_) { |
59 ui_message_loop()->PostTask(FROM_HERE, base::Bind( | 59 ui_task_runner()->PostTask(FROM_HERE, base::Bind( |
60 &HostUserInterface::ProcessOnClientDisconnected, | 60 &HostUserInterface::ProcessOnClientDisconnected, |
61 weak_ptr_)); | 61 weak_ptr_)); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 void HostUserInterface::OnAccessDenied(const std::string& jid) { | 65 void HostUserInterface::OnAccessDenied(const std::string& jid) { |
66 } | 66 } |
67 | 67 |
68 void HostUserInterface::OnShutdown() { | 68 void HostUserInterface::OnShutdown() { |
69 DCHECK(network_message_loop()->BelongsToCurrentThread()); | 69 DCHECK(network_task_runner()->BelongsToCurrentThread()); |
70 | 70 |
71 // Host status observers must be removed on the network thread, so | 71 // Host status observers must be removed on the network thread, so |
72 // it must happen here instead of in the destructor. | 72 // it must happen here instead of in the destructor. |
73 host_->RemoveStatusObserver(this); | 73 host_->RemoveStatusObserver(this); |
74 host_ = NULL; | 74 host_ = NULL; |
75 } | 75 } |
76 | 76 |
77 void HostUserInterface::OnDisconnectCallback() { | 77 void HostUserInterface::OnDisconnectCallback() { |
78 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 78 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
79 | 79 |
80 MonitorLocalInputs(false); | 80 MonitorLocalInputs(false); |
81 ShowDisconnectWindow(false, std::string()); | 81 ShowDisconnectWindow(false, std::string()); |
82 DisconnectSession(); | 82 DisconnectSession(); |
83 } | 83 } |
84 | 84 |
85 base::MessageLoopProxy* HostUserInterface::network_message_loop() const { | 85 base::SingleThreadTaskRunner* HostUserInterface::network_task_runner() const { |
86 return context_->network_message_loop(); | 86 return context_->network_task_runner(); |
87 } | 87 } |
88 base::MessageLoopProxy* HostUserInterface::ui_message_loop() const { | 88 base::SingleThreadTaskRunner* HostUserInterface::ui_task_runner() const { |
89 return context_->ui_message_loop(); | 89 return context_->ui_task_runner(); |
90 } | 90 } |
91 | 91 |
92 void HostUserInterface::DisconnectSession() const { | 92 void HostUserInterface::DisconnectSession() const { |
93 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 93 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
94 DCHECK(!disconnect_callback_.is_null()); | 94 DCHECK(!disconnect_callback_.is_null()); |
95 | 95 |
96 disconnect_callback_.Run(); | 96 disconnect_callback_.Run(); |
97 } | 97 } |
98 | 98 |
99 void HostUserInterface::ProcessOnClientAuthenticated( | 99 void HostUserInterface::ProcessOnClientAuthenticated( |
100 const std::string& username) { | 100 const std::string& username) { |
101 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 101 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
102 | 102 |
103 MonitorLocalInputs(true); | 103 MonitorLocalInputs(true); |
104 ShowDisconnectWindow(true, username); | 104 ShowDisconnectWindow(true, username); |
105 } | 105 } |
106 | 106 |
107 void HostUserInterface::ProcessOnClientDisconnected() { | 107 void HostUserInterface::ProcessOnClientDisconnected() { |
108 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 108 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
109 | 109 |
110 MonitorLocalInputs(false); | 110 MonitorLocalInputs(false); |
111 ShowDisconnectWindow(false, std::string()); | 111 ShowDisconnectWindow(false, std::string()); |
112 } | 112 } |
113 | 113 |
114 void HostUserInterface::StartForTest( | 114 void HostUserInterface::StartForTest( |
115 ChromotingHost* host, | 115 ChromotingHost* host, |
116 const base::Closure& disconnect_callback, | 116 const base::Closure& disconnect_callback, |
117 scoped_ptr<DisconnectWindow> disconnect_window, | 117 scoped_ptr<DisconnectWindow> disconnect_window, |
118 scoped_ptr<LocalInputMonitor> local_input_monitor) { | 118 scoped_ptr<LocalInputMonitor> local_input_monitor) { |
119 DCHECK(network_message_loop()->BelongsToCurrentThread()); | 119 DCHECK(network_task_runner()->BelongsToCurrentThread()); |
120 DCHECK(host_ == NULL); | 120 DCHECK(host_ == NULL); |
121 DCHECK(disconnect_callback_.is_null()); | 121 DCHECK(disconnect_callback_.is_null()); |
122 | 122 |
123 host_ = host; | 123 host_ = host; |
124 disconnect_callback_ = disconnect_callback; | 124 disconnect_callback_ = disconnect_callback; |
125 disconnect_window_ = disconnect_window.Pass(); | 125 disconnect_window_ = disconnect_window.Pass(); |
126 local_input_monitor_ = local_input_monitor.Pass(); | 126 local_input_monitor_ = local_input_monitor.Pass(); |
127 } | 127 } |
128 | 128 |
129 void HostUserInterface::MonitorLocalInputs(bool enable) { | 129 void HostUserInterface::MonitorLocalInputs(bool enable) { |
130 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 130 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
131 | 131 |
132 if (enable != is_monitoring_local_inputs_) { | 132 if (enable != is_monitoring_local_inputs_) { |
133 if (enable) { | 133 if (enable) { |
134 local_input_monitor_->Start(host_, disconnect_callback_); | 134 local_input_monitor_->Start(host_, disconnect_callback_); |
135 } else { | 135 } else { |
136 local_input_monitor_->Stop(); | 136 local_input_monitor_->Stop(); |
137 } | 137 } |
138 is_monitoring_local_inputs_ = enable; | 138 is_monitoring_local_inputs_ = enable; |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 void HostUserInterface::ShowDisconnectWindow(bool show, | 142 void HostUserInterface::ShowDisconnectWindow(bool show, |
143 const std::string& username) { | 143 const std::string& username) { |
144 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 144 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
145 | 145 |
146 if (show) { | 146 if (show) { |
147 disconnect_window_->Show( | 147 disconnect_window_->Show( |
148 host_, | 148 host_, |
149 base::Bind(&HostUserInterface::OnDisconnectCallback, weak_ptr_), | 149 base::Bind(&HostUserInterface::OnDisconnectCallback, weak_ptr_), |
150 username); | 150 username); |
151 } else { | 151 } else { |
152 disconnect_window_->Hide(); | 152 disconnect_window_->Hide(); |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 } // namespace remoting | 156 } // namespace remoting |
OLD | NEW |