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/it2me_host_user_interface.h" | 5 #include "remoting/host/it2me_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/continue_window.h" | 10 #include "remoting/host/continue_window.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 namespace remoting { | 25 namespace remoting { |
26 | 26 |
27 It2MeHostUserInterface::It2MeHostUserInterface(ChromotingHostContext* context) | 27 It2MeHostUserInterface::It2MeHostUserInterface(ChromotingHostContext* context) |
28 : HostUserInterface(context), | 28 : HostUserInterface(context), |
29 ALLOW_THIS_IN_INITIALIZER_LIST(timer_weak_factory_(this)) { | 29 ALLOW_THIS_IN_INITIALIZER_LIST(timer_weak_factory_(this)) { |
30 } | 30 } |
31 | 31 |
32 It2MeHostUserInterface::~It2MeHostUserInterface() { | 32 It2MeHostUserInterface::~It2MeHostUserInterface() { |
33 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 33 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
34 | 34 |
35 ShowContinueWindow(false); | 35 ShowContinueWindow(false); |
36 } | 36 } |
37 | 37 |
38 void It2MeHostUserInterface::Start(ChromotingHost* host, | 38 void It2MeHostUserInterface::Start(ChromotingHost* host, |
39 const base::Closure& disconnect_callback) { | 39 const base::Closure& disconnect_callback) { |
40 DCHECK(network_message_loop()->BelongsToCurrentThread()); | 40 DCHECK(network_task_runner()->BelongsToCurrentThread()); |
41 | 41 |
42 HostUserInterface::Start(host, disconnect_callback); | 42 HostUserInterface::Start(host, disconnect_callback); |
43 continue_window_ = ContinueWindow::Create(); | 43 continue_window_ = ContinueWindow::Create(); |
44 } | 44 } |
45 | 45 |
46 void It2MeHostUserInterface::OnClientAuthenticated(const std::string& jid) { | 46 void It2MeHostUserInterface::OnClientAuthenticated(const std::string& jid) { |
47 if (!get_authenticated_jid().empty()) { | 47 if (!get_authenticated_jid().empty()) { |
48 // If we already authenticated another client then one of the | 48 // If we already authenticated another client then one of the |
49 // connections may be an attacker, so both are suspect and we have | 49 // connections may be an attacker, so both are suspect and we have |
50 // to reject the second connection and shutdown the host. | 50 // to reject the second connection and shutdown the host. |
51 get_host()->RejectAuthenticatingClient(); | 51 get_host()->RejectAuthenticatingClient(); |
52 network_message_loop()->PostTask(FROM_HERE, base::Bind( | 52 network_task_runner()->PostTask(FROM_HERE, base::Bind( |
53 &ChromotingHost::Shutdown, get_host(), base::Closure())); | 53 &ChromotingHost::Shutdown, get_host(), base::Closure())); |
54 } else { | 54 } else { |
55 HostUserInterface::OnClientAuthenticated(jid); | 55 HostUserInterface::OnClientAuthenticated(jid); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 void It2MeHostUserInterface::ProcessOnClientAuthenticated( | 59 void It2MeHostUserInterface::ProcessOnClientAuthenticated( |
60 const std::string& username) { | 60 const std::string& username) { |
61 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 61 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
62 | 62 |
63 HostUserInterface::ProcessOnClientAuthenticated(username); | 63 HostUserInterface::ProcessOnClientAuthenticated(username); |
64 StartContinueWindowTimer(true); | 64 StartContinueWindowTimer(true); |
65 } | 65 } |
66 | 66 |
67 void It2MeHostUserInterface::ProcessOnClientDisconnected() { | 67 void It2MeHostUserInterface::ProcessOnClientDisconnected() { |
68 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 68 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
69 | 69 |
70 HostUserInterface::ProcessOnClientDisconnected(); | 70 HostUserInterface::ProcessOnClientDisconnected(); |
71 ShowContinueWindow(false); | 71 ShowContinueWindow(false); |
72 StartContinueWindowTimer(false); | 72 StartContinueWindowTimer(false); |
73 } | 73 } |
74 | 74 |
75 void It2MeHostUserInterface::StartForTest( | 75 void It2MeHostUserInterface::StartForTest( |
76 ChromotingHost* host, | 76 ChromotingHost* host, |
77 const base::Closure& disconnect_callback, | 77 const base::Closure& disconnect_callback, |
78 scoped_ptr<DisconnectWindow> disconnect_window, | 78 scoped_ptr<DisconnectWindow> disconnect_window, |
79 scoped_ptr<ContinueWindow> continue_window, | 79 scoped_ptr<ContinueWindow> continue_window, |
80 scoped_ptr<LocalInputMonitor> local_input_monitor) { | 80 scoped_ptr<LocalInputMonitor> local_input_monitor) { |
81 HostUserInterface::StartForTest(host, disconnect_callback, | 81 HostUserInterface::StartForTest(host, disconnect_callback, |
82 disconnect_window.Pass(), | 82 disconnect_window.Pass(), |
83 local_input_monitor.Pass()); | 83 local_input_monitor.Pass()); |
84 continue_window_ = continue_window.Pass(); | 84 continue_window_ = continue_window.Pass(); |
85 } | 85 } |
86 | 86 |
87 void It2MeHostUserInterface::ContinueSession(bool continue_session) { | 87 void It2MeHostUserInterface::ContinueSession(bool continue_session) { |
88 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 88 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
89 | 89 |
90 if (continue_session) { | 90 if (continue_session) { |
91 get_host()->PauseSession(false); | 91 get_host()->PauseSession(false); |
92 StartContinueWindowTimer(true); | 92 StartContinueWindowTimer(true); |
93 } else { | 93 } else { |
94 DisconnectSession(); | 94 DisconnectSession(); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 void It2MeHostUserInterface::OnContinueWindowTimer() { | 98 void It2MeHostUserInterface::OnContinueWindowTimer() { |
99 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 99 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
100 | 100 |
101 get_host()->PauseSession(true); | 101 get_host()->PauseSession(true); |
102 ShowContinueWindow(true); | 102 ShowContinueWindow(true); |
103 | 103 |
104 // Cancel any pending timer and post one to hide the continue window. | 104 // Cancel any pending timer and post one to hide the continue window. |
105 timer_weak_factory_.InvalidateWeakPtrs(); | 105 timer_weak_factory_.InvalidateWeakPtrs(); |
106 ui_message_loop()->PostDelayedTask( | 106 ui_task_runner()->PostDelayedTask( |
107 FROM_HERE, | 107 FROM_HERE, |
108 base::Bind(&It2MeHostUserInterface::OnShutdownHostTimer, | 108 base::Bind(&It2MeHostUserInterface::OnShutdownHostTimer, |
109 timer_weak_factory_.GetWeakPtr()), | 109 timer_weak_factory_.GetWeakPtr()), |
110 base::TimeDelta::FromMilliseconds(kContinueWindowHideTimeoutMs)); | 110 base::TimeDelta::FromMilliseconds(kContinueWindowHideTimeoutMs)); |
111 } | 111 } |
112 | 112 |
113 void It2MeHostUserInterface::OnShutdownHostTimer() { | 113 void It2MeHostUserInterface::OnShutdownHostTimer() { |
114 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 114 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
115 | 115 |
116 ShowContinueWindow(false); | 116 ShowContinueWindow(false); |
117 DisconnectSession(); | 117 DisconnectSession(); |
118 } | 118 } |
119 | 119 |
120 void It2MeHostUserInterface::ShowContinueWindow(bool show) { | 120 void It2MeHostUserInterface::ShowContinueWindow(bool show) { |
121 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 121 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
122 | 122 |
123 if (show) { | 123 if (show) { |
124 continue_window_->Show(get_host(), base::Bind( | 124 continue_window_->Show(get_host(), base::Bind( |
125 &It2MeHostUserInterface::ContinueSession, base::Unretained(this))); | 125 &It2MeHostUserInterface::ContinueSession, base::Unretained(this))); |
126 } else { | 126 } else { |
127 continue_window_->Hide(); | 127 continue_window_->Hide(); |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 void It2MeHostUserInterface::StartContinueWindowTimer(bool start) { | 131 void It2MeHostUserInterface::StartContinueWindowTimer(bool start) { |
132 DCHECK(ui_message_loop()->BelongsToCurrentThread()); | 132 DCHECK(ui_task_runner()->BelongsToCurrentThread()); |
133 | 133 |
134 // Abandon previous timer events by invalidating their weak pointer to us. | 134 // Abandon previous timer events by invalidating their weak pointer to us. |
135 timer_weak_factory_.InvalidateWeakPtrs(); | 135 timer_weak_factory_.InvalidateWeakPtrs(); |
136 if (start) { | 136 if (start) { |
137 ui_message_loop()->PostDelayedTask( | 137 ui_task_runner()->PostDelayedTask( |
138 FROM_HERE, | 138 FROM_HERE, |
139 base::Bind(&It2MeHostUserInterface::OnContinueWindowTimer, | 139 base::Bind(&It2MeHostUserInterface::OnContinueWindowTimer, |
140 timer_weak_factory_.GetWeakPtr()), | 140 timer_weak_factory_.GetWeakPtr()), |
141 base::TimeDelta::FromMilliseconds(kContinueWindowShowTimeoutMs)); | 141 base::TimeDelta::FromMilliseconds(kContinueWindowShowTimeoutMs)); |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 } // namespace remoting | 145 } // namespace remoting |
OLD | NEW |