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