Revert of Remove OneClickSigninHelper since it is no longer used. (patchset #5 id...
[chromium-blink-merge.git] / remoting / host / host_signaling_manager.cc
blobf9bb94199888521d575397f6c2348a66bfd52444
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.
5 #include "remoting/host/host_signaling_manager.h"
7 #include "base/bind.h"
8 #include "base/time/time.h"
9 #include "net/socket/client_socket_factory.h"
10 #include "remoting/base/auto_thread_task_runner.h"
11 #include "remoting/base/logging.h"
12 #include "remoting/base/url_request_context_getter.h"
13 #include "remoting/host/chromoting_host_context.h"
14 #include "remoting/host/dns_blackhole_checker.h"
15 #include "remoting/host/heartbeat_sender.h"
16 #include "remoting/host/signaling_connector.h"
17 #include "remoting/signaling/xmpp_signal_strategy.h"
19 namespace remoting {
21 HostSignalingManager::HostSignalingManager(
22 scoped_ptr<SignalStrategy> signal_strategy,
23 scoped_ptr<SignalingConnector> signaling_connector,
24 scoped_ptr<HeartbeatSender> heartbeat_sender)
25 : signal_strategy_(signal_strategy.Pass()),
26 signaling_connector_(signaling_connector.Pass()),
27 heartbeat_sender_(heartbeat_sender.Pass()) {
30 scoped_ptr<HostSignalingManager> HostSignalingManager::Create(
31 Listener* listener,
32 const scoped_refptr<net::URLRequestContextGetter>&
33 url_request_context_getter,
34 const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
35 const std::string& talkgadget_prefix_policy,
36 const std::string& host_id,
37 const scoped_refptr<const RsaKeyPair>& host_key_pair,
38 const std::string& directory_bot_jid,
39 scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials) {
40 scoped_ptr<XmppSignalStrategy> signal_strategy(
41 new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
42 url_request_context_getter, xmpp_server_config));
44 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(new DnsBlackholeChecker(
45 url_request_context_getter, talkgadget_prefix_policy));
46 scoped_ptr<OAuthTokenGetter> oauth_token_getter(new OAuthTokenGetter(
47 oauth_credentials.Pass(), url_request_context_getter, false));
49 scoped_ptr<SignalingConnector> signaling_connector(new SignalingConnector(
50 signal_strategy.get(), dns_blackhole_checker.Pass(),
51 oauth_token_getter.Pass(),
52 base::Bind(&Listener::OnAuthFailed, base::Unretained(listener))));
54 scoped_ptr<HeartbeatSender> heartbeat_sender(new HeartbeatSender(
55 base::Bind(&Listener::OnHeartbeatSuccessful, base::Unretained(listener)),
56 base::Bind(&Listener::OnUnknownHostIdError, base::Unretained(listener)),
57 host_id, signal_strategy.get(), host_key_pair, directory_bot_jid));
59 return scoped_ptr<HostSignalingManager>(new HostSignalingManager(
60 signal_strategy.Pass(), signaling_connector.Pass(),
61 heartbeat_sender.Pass()));
64 HostSignalingManager::~HostSignalingManager() {
65 DCHECK(thread_checker_.CalledOnValidThread());
68 void HostSignalingManager::SendHostOfflineReason(
69 const std::string& host_offline_reason,
70 const base::TimeDelta& timeout,
71 const base::Callback<void(bool success)>& ack_callback) {
72 DCHECK(thread_checker_.CalledOnValidThread());
73 HOST_LOG << "SendHostOfflineReason: sending " << host_offline_reason << ".";
74 heartbeat_sender_->SetHostOfflineReason(host_offline_reason, timeout,
75 ack_callback);
78 } // namespace remoting