OLD | NEW |
---|---|
(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/host_signaling_manager.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/chromoting_host_context.h" | |
15 #include "remoting/host/dns_blackhole_checker.h" | |
16 #include "remoting/host/heartbeat_sender.h" | |
17 #include "remoting/host/signaling_connector.h" | |
18 #include "remoting/signaling/xmpp_signal_strategy.h" | |
19 | |
20 namespace remoting { | |
21 | |
22 HostSignalingManager::HostSignalingManager( | |
23 scoped_refptr<AutoThreadTaskRunner> network_task_runner, | |
24 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier, | |
25 scoped_ptr<SignalStrategy> signal_strategy, | |
26 scoped_ptr<SignalingConnector> signaling_connector, | |
27 scoped_ptr<HeartbeatSender> heartbeat_sender) | |
28 : network_task_runner_(network_task_runner), | |
29 network_change_notifier_(network_change_notifier.Pass()), | |
30 signal_strategy_(signal_strategy.Pass()), | |
31 signaling_connector_(signaling_connector.Pass()), | |
32 heartbeat_sender_(heartbeat_sender.Pass()), | |
33 self_(nullptr) { | |
34 } | |
35 | |
36 scoped_ptr<HostSignalingManager> HostSignalingManager::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, | |
Wez
2014/12/18 00:46:21
You only use network_task_runner() and url_context
Łukasz Anforowicz
2014/12/18 19:02:33
I was passing them separately in the first draft,
Wez
2014/12/19 22:05:36
It has too many parameters in part because of the
Łukasz Anforowicz
2015/01/07 01:24:04
Point taken on OAuthCredentials - it will let me r
| |
41 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config, | |
42 const std::string& talkgadget_prefix, | |
43 const std::string& host_id, | |
44 const scoped_refptr<const 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. | |
Wez
2014/12/18 00:46:21
This comment seems to add nothing?
Łukasz Anforowicz
2014/12/18 19:02:33
I am just copy&pasting from the code that was in H
Wez
2014/12/19 22:05:36
Given that none of the code below is commented, I'
Łukasz Anforowicz
2015/01/07 01:24:04
Done.
| |
51 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( | |
52 net::NetworkChangeNotifier::Create()); | |
53 | |
54 scoped_ptr<XmppSignalStrategy> signal_strategy(new XmppSignalStrategy( | |
Wez
2014/12/18 00:46:21
nit: Here & below, IIRC style guide prefers wrappi
Łukasz Anforowicz
2014/12/18 19:02:33
IIRC Lambros complained that this fits on a single
Wez
2014/12/19 22:05:36
Acknowledged.
| |
55 net::ClientSocketFactory::GetDefaultFactory(), | |
56 host_context.url_request_context_getter(), xmpp_server_config)); | |
57 | |
58 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(new DnsBlackholeChecker( | |
59 host_context.url_request_context_getter(), talkgadget_prefix)); | |
60 | |
61 scoped_ptr<SignalingConnector> signaling_connector(new SignalingConnector( | |
62 signal_strategy.get(), dns_blackhole_checker.Pass(), | |
63 on_auth_failed_callback)); | |
64 | |
65 if (!oauth_refresh_token.empty()) { | |
Wez
2014/12/18 00:46:21
What does it mean for the OAuth refresh token to b
Łukasz Anforowicz
2014/12/18 19:02:33
I don't know. Just copy&pasting existing code fro
Wez
2014/12/19 22:05:36
Acknowledged. Can you file a cleanup bug for us to
Łukasz Anforowicz
2015/01/07 01:24:04
Done - crbug.com/446646
| |
66 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials( | |
67 new OAuthTokenGetter::OAuthCredentials(xmpp_server_config.username, | |
68 oauth_refresh_token, | |
69 use_service_account)); | |
70 | |
71 scoped_ptr<OAuthTokenGetter> oauth_token_getter( | |
72 new OAuthTokenGetter(oauth_credentials.Pass(), | |
73 host_context.url_request_context_getter(), false)); | |
74 | |
75 signaling_connector->EnableOAuth(oauth_token_getter.Pass()); | |
76 } | |
77 | |
78 scoped_ptr<HeartbeatSender> heartbeat_sender(new HeartbeatSender( | |
79 on_heartbeat_successful_callback, on_unknown_host_id_error_callback, | |
80 host_id, signal_strategy.get(), key_pair, directory_bot_jid)); | |
81 | |
82 return scoped_ptr<HostSignalingManager>(new HostSignalingManager( | |
83 host_context.network_task_runner(), network_change_notifier.Pass(), | |
84 signal_strategy.Pass(), signaling_connector.Pass(), | |
85 heartbeat_sender.Pass())); | |
86 } | |
87 | |
88 HostSignalingManager::~HostSignalingManager() { | |
89 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
90 | |
91 HOST_LOG << "HostSignalingManager destroyed."; | |
Wez
2014/12/18 00:46:21
Is this really important enough to put in the host
Łukasz Anforowicz
2014/12/18 19:02:33
I hoped that this would help diagnose the case of
Wez
2014/12/19 22:05:37
I think it's fine to remove this since you already
Łukasz Anforowicz
2015/01/07 01:24:04
Done.
| |
92 } | |
93 | |
94 void HostSignalingManager::SendHostOfflineReasonAndDelete( | |
95 const std::string& host_offline_reason, | |
96 const base::TimeDelta& timeout) { | |
97 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
98 | |
99 HOST_LOG << "SendHostOfflineReason: trying to send " << host_offline_reason | |
100 << " to the bot"; | |
101 | |
102 self_ = this; // We own ourselves until the ack-or-timeout callback fires. | |
Wez
2014/12/18 00:46:21
This has no effect, though..?
Łukasz Anforowicz
2014/12/18 19:02:33
Yes. I don't know what I was thinking... :-(
Wez
2014/12/19 22:05:36
Acknowledged.
| |
103 heartbeat_sender_->SetHostOfflineReason( | |
104 host_offline_reason, timeout, | |
105 base::Bind(&HostSignalingManager::OnAckOrTimeout, | |
106 base::Unretained(this))); | |
107 } | |
108 | |
109 void HostSignalingManager::OnAckOrTimeout( | |
110 HeartbeatSender::AckOrTimeout ack_or_timeout) { | |
Wez
2014/12/18 00:46:21
As noted elsewhere, suggest re-expressing this as
Łukasz Anforowicz
2014/12/18 19:02:33
Done.
| |
111 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
112 switch (ack_or_timeout) { | |
113 case HeartbeatSender::Ack: | |
114 HOST_LOG << "SendHostOfflineReason: got ack"; | |
115 break; | |
116 case HeartbeatSender::Timeout: | |
117 HOST_LOG << "SendHostOfflineReason: timed out"; | |
118 break; | |
119 default: | |
Wez
2014/12/18 00:46:21
You're already handling all the possible values, s
Łukasz Anforowicz
2014/12/18 19:02:33
N/A after the switch to bool.
| |
120 NOTREACHED(); | |
121 break; | |
122 } | |
123 | |
124 delete self_; | |
Wez
2014/12/18 00:46:21
delete this
Łukasz Anforowicz
2014/12/18 19:02:33
Right.
| |
125 } | |
126 | |
127 } // namespace remoting | |
OLD | NEW |