Chromium Code Reviews| 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/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<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. | |
| 51 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( | |
| 52 net::NetworkChangeNotifier::Create()); | |
| 53 | |
| 54 scoped_ptr<XmppSignalStrategy> signal_strategy(new XmppSignalStrategy( | |
| 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()) { | |
| 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 new MinimumHeartbeatSupporter( | |
| 83 host_context.network_task_runner(), network_change_notifier.Pass(), | |
| 84 signal_strategy.Pass(), signaling_connector.Pass(), | |
| 85 heartbeat_sender.Pass()); | |
| 86 } | |
| 87 | |
| 88 MinimumHeartbeatSupporter::~MinimumHeartbeatSupporter() { | |
| 89 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
| 90 | |
| 91 HOST_LOG << "MinimumHeartbeatSupporter destroyed."; | |
| 92 } | |
| 93 | |
| 94 void MinimumHeartbeatSupporter::SendHostOfflineReason( | |
| 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 ReportAckOrTimeout( | |
| 103 // Passing partially bound |SetHostOfflineReason| as |function_that_acks| | |
|
Sergey Ulanov
2014/12/15 22:39:19
nit: Add . at the end. Comments should be full sen
Sergey Ulanov
2014/12/15 22:39:19
nit: SetHostOfflineReason() instead of |SetHostOff
Łukasz Anforowicz
2014/12/16 00:59:52
N/A after removing ReportAckOrTimeout.
Łukasz Anforowicz
2014/12/16 00:59:52
N/A after removing ReportAckOrTimeout.
| |
| 104 base::Bind(&HeartbeatSender::SetHostOfflineReason, | |
|
Sergey Ulanov
2014/12/15 22:39:19
If you replace ReportAckOrTimeout() with CreateCal
Łukasz Anforowicz
2014/12/16 00:59:52
N/A after removing ReportAckOrTimeout.
| |
| 105 base::Unretained(heartbeat_sender_.get()), | |
| 106 host_offline_reason), | |
| 107 timeout, network_task_runner_, | |
| 108 // The callback below will keep |this| alive until either ack or timeout. | |
| 109 base::Bind(&MinimumHeartbeatSupporter::OnAckOrTimeout, this)); | |
| 110 } | |
| 111 | |
| 112 void MinimumHeartbeatSupporter::OnAckOrTimeout(AckOrTimeout ack_or_timeout) { | |
| 113 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
| 114 switch (ack_or_timeout) { | |
| 115 case Ack: | |
| 116 HOST_LOG << "SendHostOfflineReason: got ack"; | |
| 117 break; | |
| 118 case Timeout: | |
| 119 HOST_LOG << "SendHostOfflineReason: timed out"; | |
| 120 break; | |
| 121 default: | |
| 122 NOTREACHED(); | |
| 123 break; | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 } // namespace remoting | |
| OLD | NEW |