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/it2me_host_user_interface.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "remoting/host/chromoting_host.h" | |
9 #include "remoting/host/continue_window.h" | |
10 #include "remoting/host/local_input_monitor.h" | |
11 | |
12 namespace { | |
13 | |
14 // Milliseconds before the continue window is shown. | |
15 static const int kContinueWindowShowTimeoutMs = 10 * 60 * 1000; | |
16 | |
17 // Milliseconds before the continue window is automatically dismissed and | |
18 // the connection is closed. | |
19 static const int kContinueWindowHideTimeoutMs = 60 * 1000; | |
20 | |
21 } // namespace | |
22 | |
23 namespace remoting { | |
24 | |
25 It2MeHostUserInterface::It2MeHostUserInterface( | |
26 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
27 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | |
28 const UiStrings& ui_strings) | |
29 : HostUserInterface(network_task_runner, ui_task_runner, ui_strings), | |
30 ALLOW_THIS_IN_INITIALIZER_LIST(timer_weak_factory_(this)) { | |
31 DCHECK(ui_task_runner->BelongsToCurrentThread()); | |
32 } | |
33 | |
34 It2MeHostUserInterface::~It2MeHostUserInterface() { | |
35 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
36 | |
37 ShowContinueWindow(false); | |
38 } | |
39 | |
40 void It2MeHostUserInterface::Init() { | |
41 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
42 | |
43 HostUserInterface::Init(); | |
44 continue_window_ = ContinueWindow::Create(&ui_strings()); | |
45 } | |
46 | |
47 void It2MeHostUserInterface::ProcessOnClientAuthenticated( | |
48 const std::string& username) { | |
49 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
50 | |
51 HostUserInterface::ProcessOnClientAuthenticated(username); | |
52 StartContinueWindowTimer(true); | |
53 } | |
54 | |
55 void It2MeHostUserInterface::ProcessOnClientDisconnected() { | |
56 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
57 | |
58 HostUserInterface::ProcessOnClientDisconnected(); | |
59 ShowContinueWindow(false); | |
60 StartContinueWindowTimer(false); | |
61 } | |
62 | |
63 void It2MeHostUserInterface::ContinueSession(bool continue_session) { | |
64 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
65 | |
66 if (continue_session) { | |
67 get_host()->PauseSession(false); | |
68 StartContinueWindowTimer(true); | |
69 } else { | |
70 DisconnectSession(); | |
71 } | |
72 } | |
73 | |
74 void It2MeHostUserInterface::OnContinueWindowTimer() { | |
75 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
76 | |
77 get_host()->PauseSession(true); | |
78 ShowContinueWindow(true); | |
79 | |
80 // Cancel any pending timer and post one to hide the continue window. | |
81 timer_weak_factory_.InvalidateWeakPtrs(); | |
82 ui_task_runner()->PostDelayedTask( | |
83 FROM_HERE, | |
84 base::Bind(&It2MeHostUserInterface::OnShutdownHostTimer, | |
85 timer_weak_factory_.GetWeakPtr()), | |
86 base::TimeDelta::FromMilliseconds(kContinueWindowHideTimeoutMs)); | |
87 } | |
88 | |
89 void It2MeHostUserInterface::OnShutdownHostTimer() { | |
90 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
91 | |
92 ShowContinueWindow(false); | |
93 DisconnectSession(); | |
94 } | |
95 | |
96 void It2MeHostUserInterface::ShowContinueWindow(bool show) { | |
97 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
98 | |
99 if (show) { | |
100 continue_window_->Show(base::Bind( | |
101 &It2MeHostUserInterface::ContinueSession, base::Unretained(this))); | |
102 } else { | |
103 continue_window_->Hide(); | |
104 } | |
105 } | |
106 | |
107 void It2MeHostUserInterface::StartContinueWindowTimer(bool start) { | |
108 DCHECK(ui_task_runner()->BelongsToCurrentThread()); | |
109 | |
110 // Abandon previous timer events by invalidating their weak pointer to us. | |
111 timer_weak_factory_.InvalidateWeakPtrs(); | |
112 if (start) { | |
113 ui_task_runner()->PostDelayedTask( | |
114 FROM_HERE, | |
115 base::Bind(&It2MeHostUserInterface::OnContinueWindowTimer, | |
116 timer_weak_factory_.GetWeakPtr()), | |
117 base::TimeDelta::FromMilliseconds(kContinueWindowShowTimeoutMs)); | |
118 } | |
119 } | |
120 | |
121 } // namespace remoting | |
OLD | NEW |