Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: remoting/host/minimum_heartbeat_supporter.cc

Issue 719983002: Reporting of policy errors via host-offline-reason: part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hor-nohoststatussender
Patch Set: Rebasing... Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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/minimum_heartbeat_supporter.h"
6
7 #include "base/bind.h"
8 #include "base/time/time.h"
9 #include "net/base/network_change_notifier.h"
10 #include "net/socket/client_socket_factory.h"
11 #include "remoting/base/auto_thread_task_runner.h"
12 #include "remoting/base/logging.h"
13 #include "remoting/base/url_request_context_getter.h"
14 #include "remoting/host/ack_or_timeout_reporter.h"
15 #include "remoting/host/chromoting_host_context.h"
16 #include "remoting/host/dns_blackhole_checker.h"
17 #include "remoting/host/heartbeat_sender.h"
18 #include "remoting/host/signaling_connector.h"
19 #include "remoting/signaling/xmpp_signal_strategy.h"
20
21 namespace remoting {
22
23 MinimumHeartbeatSupporter::MinimumHeartbeatSupporter(
24 scoped_refptr<AutoThreadTaskRunner> network_task_runner,
25 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier,
26 scoped_ptr<XmppSignalStrategy> signal_strategy,
27 scoped_ptr<SignalingConnector> signaling_connector,
28 scoped_ptr<HeartbeatSender> heartbeat_sender)
29 : network_task_runner_(network_task_runner),
30 network_change_notifier_(network_change_notifier.Pass()),
31 signal_strategy_(signal_strategy.Pass()),
32 signaling_connector_(signaling_connector.Pass()),
33 heartbeat_sender_(heartbeat_sender.Pass()) {
34 }
35
36 scoped_refptr<MinimumHeartbeatSupporter> MinimumHeartbeatSupporter::Create(
37 const base::Closure& on_heartbeat_successful_callback,
38 const base::Closure& on_unknown_host_id_error_callback,
39 const base::Closure& on_auth_failed_callback,
40 const ChromotingHostContext& host_context,
41 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
42 const std::string& talkgadget_prefix,
43 const std::string& host_id,
44 const scoped_refptr<RsaKeyPair> key_pair,
45 const std::string& directory_bot_jid,
46 const std::string& oauth_refresh_token,
47 bool use_service_account) {
48 DCHECK(host_context.network_task_runner()->BelongsToCurrentThread());
49
50 // Create a NetworkChangeNotifier for use by the signaling connector.
51 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier(
52 net::NetworkChangeNotifier::Create());
53
54 scoped_ptr<XmppSignalStrategy> signal_strategy(
55 new XmppSignalStrategy(
56 net::ClientSocketFactory::GetDefaultFactory(),
57 host_context.url_request_context_getter(),
58 xmpp_server_config));
59
60 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(
61 new DnsBlackholeChecker(
62 host_context.url_request_context_getter(),
63 talkgadget_prefix));
64
65 scoped_ptr<SignalingConnector> signaling_connector(
66 new SignalingConnector(
67 signal_strategy.get(),
68 dns_blackhole_checker.Pass(),
69 on_auth_failed_callback));
70
71 if (!oauth_refresh_token.empty()) {
72 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials(
73 new OAuthTokenGetter::OAuthCredentials(
74 xmpp_server_config.username,
75 oauth_refresh_token,
76 use_service_account));
77
78 scoped_ptr<OAuthTokenGetter> oauth_token_getter(
79 new OAuthTokenGetter(
80 oauth_credentials.Pass(),
81 host_context.url_request_context_getter(),
82 false));
83
84 signaling_connector->EnableOAuth(oauth_token_getter.Pass());
85 }
86
87 scoped_ptr<HeartbeatSender> heartbeat_sender(
88 new HeartbeatSender(
89 on_heartbeat_successful_callback,
90 on_unknown_host_id_error_callback,
91 host_id,
92 signal_strategy.get(),
93 key_pair,
94 directory_bot_jid));
95
96 return new MinimumHeartbeatSupporter(
97 host_context.network_task_runner(),
98 network_change_notifier.Pass(),
99 signal_strategy.Pass(),
100 signaling_connector.Pass(),
101 heartbeat_sender.Pass());
102 }
103
104 MinimumHeartbeatSupporter::~MinimumHeartbeatSupporter() {
105 DCHECK(network_task_runner_->BelongsToCurrentThread());
106
107 // Order of destroying fields below is important.
Lambros 2014/12/02 03:35:22 Rather than manually calling reset(), why not just
Łukasz Anforowicz 2014/12/02 20:08:01 Good point on the explicit comment - thanks for po
108 heartbeat_sender_.reset();
109 signaling_connector_.reset();
110 signal_strategy_.reset();
111 network_change_notifier_.reset();
112
113 HOST_LOG << "MinimumHeartbeatSupporter is ready to die "
Lambros 2014/12/02 03:35:22 If you do need to log this, you could maybe simpli
Łukasz Anforowicz 2014/12/02 20:08:01 I think I do want to log this to aid in investigat
114 << "and allow the host process to exit";
115 }
116
117 SignalStrategy* MinimumHeartbeatSupporter::GetSignalStrategy() {
118 return signal_strategy_.get();
119 }
120
121 void MinimumHeartbeatSupporter::SendHostOfflineReason(
122 const std::string& host_offline_reason,
123 const base::TimeDelta& timeout) {
124 DCHECK(network_task_runner_->BelongsToCurrentThread());
125
126 HOST_LOG << "SendHostOfflineReason: trying to send "
127 << host_offline_reason
128 << " to the bot";
129
130 ReportAckOrTimeout(
131 // Passing partially bound |SetHostOfflineReason| as |function_that_acks|
132 base::Bind(
133 &HeartbeatSender::SetHostOfflineReason,
134 base::Unretained(heartbeat_sender_.get()),
135 host_offline_reason),
136 timeout,
137 network_task_runner_,
138 // The callback below will keep |this| alive until either ack or timeout.
139 base::Bind(&MinimumHeartbeatSupporter::OnAckOrTimeout, this));
140 }
141
142 void MinimumHeartbeatSupporter::OnAckOrTimeout(AckOrTimeout ack_or_timeout)
143 {
144 DCHECK(network_task_runner_->BelongsToCurrentThread());
145 switch (ack_or_timeout) {
146 case Ack:
147 HOST_LOG << "SendHostOfflineReason: got ack";
148 break;
149 case Timeout:
150 HOST_LOG << "SendHostOfflineReason: timed out";
151 break;
152 default:
153 NOTREACHED();
154 break;
155 }
156 }
157
158 } // namespace remoting
159
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698