summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remoting/host/chromoting_host_context.cc26
-rw-r--r--remoting/host/chromoting_host_context.h17
-rw-r--r--remoting/host/dns_blackhole_checker.cc4
-rw-r--r--remoting/host/dns_blackhole_checker.h2
-rw-r--r--remoting/host/heartbeat_sender.cc49
-rw-r--r--remoting/host/heartbeat_sender.h36
-rw-r--r--remoting/host/heartbeat_sender_unittest.cc37
-rw-r--r--remoting/host/host_signaling_manager.cc117
-rw-r--r--remoting/host/host_signaling_manager.h129
-rw-r--r--remoting/host/mock_callback.h43
-rw-r--r--remoting/host/oauth_token_getter.cc3
-rw-r--r--remoting/host/oauth_token_getter.h11
-rw-r--r--remoting/host/remoting_me2me_host.cc161
-rw-r--r--remoting/host/signaling_connector.cc5
-rw-r--r--remoting/host/signaling_connector.h5
-rw-r--r--remoting/remoting_host_srcs.gypi2
-rw-r--r--remoting/remoting_test.gypi1
-rw-r--r--remoting/signaling/xmpp_signal_strategy.cc2
-rw-r--r--remoting/signaling/xmpp_signal_strategy.h2
19 files changed, 450 insertions, 202 deletions
diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc
index aa73a8c..60e3a73 100644
--- a/remoting/host/chromoting_host_context.cc
+++ b/remoting/host/chromoting_host_context.cc
@@ -39,43 +39,43 @@ scoped_ptr<ChromotingHostContext> ChromotingHostContext::Copy() {
video_encode_task_runner_, url_request_context_getter_));
}
-scoped_refptr<AutoThreadTaskRunner>
-ChromotingHostContext::audio_task_runner() {
+scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::audio_task_runner()
+ const {
return audio_task_runner_;
}
-scoped_refptr<AutoThreadTaskRunner>
-ChromotingHostContext::file_task_runner() {
+scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::file_task_runner()
+ const {
return file_task_runner_;
}
-scoped_refptr<AutoThreadTaskRunner>
-ChromotingHostContext::input_task_runner() {
+scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::input_task_runner()
+ const {
return input_task_runner_;
}
-scoped_refptr<AutoThreadTaskRunner>
-ChromotingHostContext::network_task_runner() {
+scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::network_task_runner()
+ const {
return network_task_runner_;
}
-scoped_refptr<AutoThreadTaskRunner>
-ChromotingHostContext::ui_task_runner() {
+scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::ui_task_runner()
+ const {
return ui_task_runner_;
}
scoped_refptr<AutoThreadTaskRunner>
-ChromotingHostContext::video_capture_task_runner() {
+ChromotingHostContext::video_capture_task_runner() const {
return video_capture_task_runner_;
}
scoped_refptr<AutoThreadTaskRunner>
-ChromotingHostContext::video_encode_task_runner() {
+ChromotingHostContext::video_encode_task_runner() const {
return video_encode_task_runner_;
}
scoped_refptr<net::URLRequestContextGetter>
-ChromotingHostContext::url_request_context_getter() {
+ChromotingHostContext::url_request_context_getter() const {
return url_request_context_getter_;
}
diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h
index 58a0af5..9de7067 100644
--- a/remoting/host/chromoting_host_context.h
+++ b/remoting/host/chromoting_host_context.h
@@ -47,35 +47,36 @@ class ChromotingHostContext {
scoped_ptr<ChromotingHostContext> Copy();
// Task runner for the thread that is used for the UI.
- scoped_refptr<AutoThreadTaskRunner> ui_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> ui_task_runner() const;
// Task runner for the thread used for audio capture and encoding.
- scoped_refptr<AutoThreadTaskRunner> audio_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> audio_task_runner() const;
// Task runner for the thread that is used for blocking file
// IO. This thread is used by the URLRequestContext to read proxy
// configuration and by NatConfig to read policy configs.
- scoped_refptr<AutoThreadTaskRunner> file_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> file_task_runner() const;
// Task runner for the thread that is used by the InputInjector.
//
// TODO(sergeyu): Do we need a separate thread for InputInjector?
// Can we use some other thread instead?
- scoped_refptr<AutoThreadTaskRunner> input_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> input_task_runner() const;
// Task runner for the thread used for network IO. This thread runs
// a libjingle message loop, and is the only thread on which
// libjingle code may be run.
- scoped_refptr<AutoThreadTaskRunner> network_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner() const;
// Task runner for the thread used by the ScreenRecorder to capture
// the screen.
- scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner() const;
// Task runner for the thread used to encode video streams.
- scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner();
+ scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner() const;
- scoped_refptr<net::URLRequestContextGetter> url_request_context_getter();
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter()
+ const;
private:
ChromotingHostContext(
diff --git a/remoting/host/dns_blackhole_checker.cc b/remoting/host/dns_blackhole_checker.cc
index 9e30556..745481e 100644
--- a/remoting/host/dns_blackhole_checker.cc
+++ b/remoting/host/dns_blackhole_checker.cc
@@ -19,9 +19,9 @@ const char kTalkGadgetUrl[] = ".talkgadget.google.com/talkgadget/"
"oauth/chrome-remote-desktop-host";
DnsBlackholeChecker::DnsBlackholeChecker(
- scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
std::string talkgadget_prefix)
- : url_request_context_getter_(url_request_context_getter),
+ : url_request_context_getter_(request_context_getter),
talkgadget_prefix_(talkgadget_prefix) {
}
diff --git a/remoting/host/dns_blackhole_checker.h b/remoting/host/dns_blackhole_checker.h
index 49d73ca..8d7f54db 100644
--- a/remoting/host/dns_blackhole_checker.h
+++ b/remoting/host/dns_blackhole_checker.h
@@ -23,7 +23,7 @@ extern const char kDefaultHostTalkGadgetPrefix[];
class DnsBlackholeChecker : public net::URLFetcherDelegate {
public:
DnsBlackholeChecker(
- scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
std::string talkgadget_prefix);
~DnsBlackholeChecker() override;
diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc
index c64f2f4..ae10955 100644
--- a/remoting/host/heartbeat_sender.cc
+++ b/remoting/host/heartbeat_sender.cc
@@ -7,10 +7,10 @@
#include <math.h>
#include "base/bind.h"
-#include "base/message_loop/message_loop_proxy.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringize_macros.h"
+#include "base/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "remoting/base/constants.h"
#include "remoting/base/logging.h"
@@ -54,13 +54,13 @@ HeartbeatSender::HeartbeatSender(
const base::Closure& on_unknown_host_id_error,
const std::string& host_id,
SignalStrategy* signal_strategy,
- scoped_refptr<RsaKeyPair> key_pair,
+ const scoped_refptr<const RsaKeyPair>& host_key_pair,
const std::string& directory_bot_jid)
: on_heartbeat_successful_callback_(on_heartbeat_successful_callback),
on_unknown_host_id_error_(on_unknown_host_id_error),
host_id_(host_id),
signal_strategy_(signal_strategy),
- key_pair_(key_pair),
+ host_key_pair_(host_key_pair),
directory_bot_jid_(directory_bot_jid),
interval_ms_(kDefaultHeartbeatIntervalMs),
sequence_id_(0),
@@ -69,7 +69,7 @@ HeartbeatSender::HeartbeatSender(
heartbeat_succeeded_(false),
failed_startup_heartbeat_count_(0) {
DCHECK(signal_strategy_);
- DCHECK(key_pair_.get());
+ DCHECK(host_key_pair_.get());
DCHECK(thread_checker_.CalledOnValidThread());
signal_strategy_->AddListener(this);
@@ -102,13 +102,43 @@ bool HeartbeatSender::OnSignalStrategyIncomingStanza(
return false;
}
+void HeartbeatSender::OnHostOfflineReasonTimeout() {
+ DCHECK(!host_offline_reason_ack_callback_.is_null());
+
+ base::Callback<void(bool)> local_callback = host_offline_reason_ack_callback_;
+ host_offline_reason_ack_callback_.Reset();
+ local_callback.Run(false);
+}
+
+void HeartbeatSender::OnHostOfflineReasonAck() {
+ if (host_offline_reason_ack_callback_.is_null()) {
+ DCHECK(!host_offline_reason_timeout_timer_.IsRunning());
+ return;
+ }
+
+ DCHECK(host_offline_reason_timeout_timer_.IsRunning());
+ host_offline_reason_timeout_timer_.Stop();
+
+ // Run the ACK callback under a clean stack via PostTask() (because the
+ // callback can end up deleting |this| HeartbeatSender [i.e. when used from
+ // HostSignalingManager]).
+ base::Closure fully_bound_ack_callback =
+ base::Bind(host_offline_reason_ack_callback_, true);
+ host_offline_reason_ack_callback_.Reset();
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ fully_bound_ack_callback);
+}
+
void HeartbeatSender::SetHostOfflineReason(
const std::string& host_offline_reason,
- const base::Closure& ack_callback) {
+ const base::TimeDelta& timeout,
+ const base::Callback<void(bool success)>& ack_callback) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(host_offline_reason_ack_callback_.is_null());
host_offline_reason_ = host_offline_reason;
host_offline_reason_ack_callback_ = ack_callback;
+ host_offline_reason_timeout_timer_.Start(
+ FROM_HERE, timeout, this, &HeartbeatSender::OnHostOfflineReasonTimeout);
if (signal_strategy_->GetState() == SignalStrategy::CONNECTED) {
DoSendStanza();
}
@@ -230,12 +260,7 @@ void HeartbeatSender::ProcessResponse(
// Notify caller of SetHostOfflineReason that we got an ack.
if (is_offline_heartbeat_response) {
- if (!host_offline_reason_ack_callback_.is_null()) {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- host_offline_reason_ack_callback_);
- host_offline_reason_ack_callback_.Reset();
- }
+ OnHostOfflineReasonAck();
}
}
}
@@ -310,7 +335,7 @@ scoped_ptr<XmlElement> HeartbeatSender::CreateSignature() {
std::string message = signal_strategy_->GetLocalJid() + ' ' +
base::IntToString(sequence_id_);
- std::string signature(key_pair_->SignMessage(message));
+ std::string signature(host_key_pair_->SignMessage(message));
signature_tag->AddText(signature);
return signature_tag.Pass();
diff --git a/remoting/host/heartbeat_sender.h b/remoting/host/heartbeat_sender.h
index 73080be9..c30bfec 100644
--- a/remoting/host/heartbeat_sender.h
+++ b/remoting/host/heartbeat_sender.h
@@ -19,6 +19,7 @@
namespace base {
class MessageLoopProxy;
+class TimeDelta;
} // namespace base
namespace buzz {
@@ -91,25 +92,33 @@ class HeartbeatSender : public SignalStrategy::Listener {
// |signal_strategy| and |delegate| must outlive this
// object. Heartbeats will start when the supplied SignalStrategy
// enters the CONNECTED state.
+ //
+ // |on_heartbeat_successful_callback| is invoked after the first successful
+ // heartbeat.
+ //
+ // |on_unknown_host_id_error| is invoked when the host ID is permanently not
+ // recognized by the server.
HeartbeatSender(const base::Closure& on_heartbeat_successful_callback,
const base::Closure& on_unknown_host_id_error,
const std::string& host_id,
SignalStrategy* signal_strategy,
- scoped_refptr<RsaKeyPair> key_pair,
+ const scoped_refptr<const RsaKeyPair>& host_key_pair,
const std::string& directory_bot_jid);
~HeartbeatSender() override;
- // Sets host offline reason for future heartbeat stanzas,
- // as well as intiates sending a stanza right away.
+ // Sets host offline reason for future heartbeat stanzas, and initiates
+ // sending a stanza right away.
//
- // See rem:host-offline-reason class-level comments for discussion
- // of allowed values for |host_offline_reason| string.
+ // For discussion of allowed values for |host_offline_reason| argument,
+ // please see the description of rem:host-offline-reason xml attribute in
+ // the class-level comments above.
//
- // |ack_callback| will be called once, when the bot acks
- // receiving the |host_offline_reason|.
+ // |ack_callback| will be called once, when the bot acks receiving the
+ // |host_offline_reason| or when |timeout| is reached.
void SetHostOfflineReason(
const std::string& host_offline_reason,
- const base::Closure& ack_callback);
+ const base::TimeDelta& timeout,
+ const base::Callback<void(bool success)>& ack_callback);
// SignalStrategy::Listener interface.
void OnSignalStrategyStateChange(SignalStrategy::State state) override;
@@ -132,6 +141,10 @@ class HeartbeatSender : public SignalStrategy::Listener {
void SetInterval(int interval);
void SetSequenceId(int sequence_id);
+ // Handlers for host-offline-reason completion and timeout.
+ void OnHostOfflineReasonTimeout();
+ void OnHostOfflineReasonAck();
+
// Helper methods used by DoSendStanza() to generate heartbeat stanzas.
scoped_ptr<buzz::XmlElement> CreateHeartbeatMessage();
scoped_ptr<buzz::XmlElement> CreateSignature();
@@ -140,7 +153,7 @@ class HeartbeatSender : public SignalStrategy::Listener {
base::Closure on_unknown_host_id_error_;
std::string host_id_;
SignalStrategy* signal_strategy_;
- scoped_refptr<RsaKeyPair> key_pair_;
+ scoped_refptr<const RsaKeyPair> host_key_pair_;
std::string directory_bot_jid_;
scoped_ptr<IqSender> iq_sender_;
scoped_ptr<IqRequest> request_;
@@ -152,8 +165,11 @@ class HeartbeatSender : public SignalStrategy::Listener {
int sequence_id_recent_set_num_;
bool heartbeat_succeeded_;
int failed_startup_heartbeat_count_;
+
+ // Fields to send and indicate completion of sending host-offline-reason.
std::string host_offline_reason_;
- base::Closure host_offline_reason_ack_callback_;
+ base::Callback<void(bool success)> host_offline_reason_ack_callback_;
+ base::OneShotTimer<HeartbeatSender> host_offline_reason_timeout_timer_;
base::ThreadChecker thread_checker_;
diff --git a/remoting/host/heartbeat_sender_unittest.cc b/remoting/host/heartbeat_sender_unittest.cc
index cd9fb558..38fee24 100644
--- a/remoting/host/heartbeat_sender_unittest.cc
+++ b/remoting/host/heartbeat_sender_unittest.cc
@@ -14,7 +14,6 @@
#include "remoting/base/constants.h"
#include "remoting/base/rsa_key_pair.h"
#include "remoting/base/test_rsa_key_pair.h"
-#include "remoting/host/mock_callback.h"
#include "remoting/signaling/iq_sender.h"
#include "remoting/signaling/mock_signal_strategy.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -42,6 +41,7 @@ const char kHostId[] = "0";
const char kTestJid[] = "user@gmail.com/chromoting123";
const char kStanzaId[] = "123";
const int kTestInterval = 123;
+const base::TimeDelta kTestTimeout = base::TimeDelta::FromSeconds(123);
} // namespace
@@ -53,6 +53,16 @@ ACTION_P(RemoveListener, list) {
list->erase(arg0);
}
+class MockClosure {
+ public:
+ MOCK_CONST_METHOD0(Run, void());
+};
+
+class MockAckCallback {
+ public:
+ MOCK_CONST_METHOD1(Run, void(bool success));
+};
+
class HeartbeatSenderTest
: public testing::Test {
protected:
@@ -72,8 +82,10 @@ class HeartbeatSenderTest
.Times(0);
heartbeat_sender_.reset(new HeartbeatSender(
- mock_heartbeat_successful_callback_.GetCallback(),
- mock_unknown_host_id_error_callback_.GetCallback(),
+ base::Bind(&MockClosure::Run,
+ base::Unretained(&mock_heartbeat_successful_callback_)),
+ base::Bind(&MockClosure::Run,
+ base::Unretained(&mock_unknown_host_id_error_callback_)),
kHostId, &signal_strategy_, key_pair_, kTestBotJid));
}
@@ -246,6 +258,8 @@ TEST_F(HeartbeatSenderTest, ProcessResponseSetInterval) {
// Make sure SetHostOfflineReason sends a correct stanza.
TEST_F(HeartbeatSenderTest, DoSetHostOfflineReason) {
XmlElement* sent_iq = nullptr;
+ MockAckCallback mock_ack_callback;
+
EXPECT_CALL(signal_strategy_, GetLocalJid())
.WillRepeatedly(Return(kTestJid));
EXPECT_CALL(signal_strategy_, GetNextId())
@@ -255,10 +269,11 @@ TEST_F(HeartbeatSenderTest, DoSetHostOfflineReason) {
EXPECT_CALL(signal_strategy_, GetState())
.WillOnce(Return(SignalStrategy::DISCONNECTED))
.WillRepeatedly(Return(SignalStrategy::CONNECTED));
+ EXPECT_CALL(mock_ack_callback, Run(_)).Times(0);
heartbeat_sender_->SetHostOfflineReason(
- "test_error",
- base::Bind(base::DoNothing));
+ "test_error", kTestTimeout,
+ base::Bind(&MockAckCallback::Run, base::Unretained(&mock_ack_callback)));
heartbeat_sender_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
base::RunLoop().RunUntilIdle();
@@ -272,7 +287,7 @@ TEST_F(HeartbeatSenderTest, DoSetHostOfflineReason) {
// Make sure SetHostOfflineReason triggers a callback when bot responds.
TEST_F(HeartbeatSenderTest, ProcessHostOfflineResponses) {
- MockClosure mock_ack_callback;
+ MockAckCallback mock_ack_callback;
EXPECT_CALL(signal_strategy_, GetLocalJid())
.WillRepeatedly(Return(kTestJid));
@@ -287,11 +302,11 @@ TEST_F(HeartbeatSenderTest, ProcessHostOfflineResponses) {
.WillRepeatedly(Return());
// Callback should not run, until response to offline-reason.
- EXPECT_CALL(mock_ack_callback, Run()).Times(0);
+ EXPECT_CALL(mock_ack_callback, Run(_)).Times(0);
heartbeat_sender_->SetHostOfflineReason(
- "test_error",
- mock_ack_callback.GetCallback());
+ "test_error", kTestTimeout,
+ base::Bind(&MockAckCallback::Run, base::Unretained(&mock_ack_callback)));
heartbeat_sender_->OnSignalStrategyStateChange(SignalStrategy::CONNECTED);
base::RunLoop().RunUntilIdle();
@@ -301,7 +316,7 @@ TEST_F(HeartbeatSenderTest, ProcessHostOfflineResponses) {
base::RunLoop().RunUntilIdle();
// Callback should run once, when we get response to offline-reason.
- EXPECT_CALL(mock_ack_callback, Run()).Times(1);
+ EXPECT_CALL(mock_ack_callback, Run(true /* success */)).Times(1);
ProcessResponseWithInterval(
true, // <- This is a response to offline-reason.
kTestInterval);
@@ -309,7 +324,7 @@ TEST_F(HeartbeatSenderTest, ProcessHostOfflineResponses) {
// When subsequent responses to offline-reason come,
// the callback should not be called again.
- EXPECT_CALL(mock_ack_callback, Run()).Times(0);
+ EXPECT_CALL(mock_ack_callback, Run(_)).Times(0);
ProcessResponseWithInterval(true, kTestInterval);
base::RunLoop().RunUntilIdle();
diff --git a/remoting/host/host_signaling_manager.cc b/remoting/host/host_signaling_manager.cc
new file mode 100644
index 0000000..37da304
--- /dev/null
+++ b/remoting/host/host_signaling_manager.cc
@@ -0,0 +1,117 @@
+// Copyright 2014 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/host_signaling_manager.h"
+
+#include "base/bind.h"
+#include "base/time/time.h"
+#include "net/base/network_change_notifier.h"
+#include "net/socket/client_socket_factory.h"
+#include "remoting/base/auto_thread_task_runner.h"
+#include "remoting/base/logging.h"
+#include "remoting/base/url_request_context_getter.h"
+#include "remoting/host/chromoting_host_context.h"
+#include "remoting/host/dns_blackhole_checker.h"
+#include "remoting/host/heartbeat_sender.h"
+#include "remoting/host/signaling_connector.h"
+#include "remoting/signaling/xmpp_signal_strategy.h"
+
+namespace remoting {
+
+HostSignalingManager::HostSignalingManager(
+ scoped_ptr<base::WeakPtrFactory<Listener>> weak_factory_for_listener,
+ const scoped_refptr<AutoThreadTaskRunner>& network_task_runner,
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier,
+ scoped_ptr<SignalStrategy> signal_strategy,
+ scoped_ptr<SignalingConnector> signaling_connector,
+ scoped_ptr<HeartbeatSender> heartbeat_sender)
+ : weak_factory_for_listener_(weak_factory_for_listener.Pass()),
+ network_task_runner_(network_task_runner),
+ network_change_notifier_(network_change_notifier.Pass()),
+ signal_strategy_(signal_strategy.Pass()),
+ signaling_connector_(signaling_connector.Pass()),
+ heartbeat_sender_(heartbeat_sender.Pass()) {
+}
+
+scoped_ptr<HostSignalingManager> HostSignalingManager::Create(
+ Listener* listener,
+ const scoped_refptr<AutoThreadTaskRunner>& network_task_runner,
+ const scoped_refptr<net::URLRequestContextGetter>&
+ url_request_context_getter,
+ const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
+ const std::string& talkgadget_prefix_policy,
+ const std::string& host_id,
+ const scoped_refptr<const RsaKeyPair>& host_key_pair,
+ const std::string& directory_bot_jid,
+ scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials) {
+ DCHECK(network_task_runner->BelongsToCurrentThread());
+
+ scoped_ptr<base::WeakPtrFactory<Listener>> weak_factory(
+ new base::WeakPtrFactory<Listener>(listener));
+
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier(
+ net::NetworkChangeNotifier::Create());
+
+ scoped_ptr<XmppSignalStrategy> signal_strategy(
+ new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
+ url_request_context_getter, xmpp_server_config));
+
+ scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(new DnsBlackholeChecker(
+ url_request_context_getter, talkgadget_prefix_policy));
+
+ scoped_ptr<SignalingConnector> signaling_connector(new SignalingConnector(
+ signal_strategy.get(), dns_blackhole_checker.Pass(),
+ base::Bind(&Listener::OnAuthFailed, weak_factory->GetWeakPtr())));
+
+ if (!oauth_credentials->refresh_token.empty()) {
+ scoped_ptr<OAuthTokenGetter> oauth_token_getter(new OAuthTokenGetter(
+ oauth_credentials.Pass(), url_request_context_getter, false));
+
+ signaling_connector->EnableOAuth(oauth_token_getter.Pass());
+ }
+
+ scoped_ptr<HeartbeatSender> heartbeat_sender(new HeartbeatSender(
+ base::Bind(&Listener::OnHeartbeatSuccessful, weak_factory->GetWeakPtr()),
+ base::Bind(&Listener::OnUnknownHostIdError, weak_factory->GetWeakPtr()),
+ host_id, signal_strategy.get(), host_key_pair, directory_bot_jid));
+
+ return scoped_ptr<HostSignalingManager>(new HostSignalingManager(
+ weak_factory.Pass(), network_task_runner, network_change_notifier.Pass(),
+ signal_strategy.Pass(), signaling_connector.Pass(),
+ heartbeat_sender.Pass()));
+}
+
+HostSignalingManager::~HostSignalingManager() {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+}
+
+void HostSignalingManager::SendHostOfflineReasonAndDelete(
+ const std::string& host_offline_reason,
+ const base::TimeDelta& timeout) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+
+ HOST_LOG << "SendHostOfflineReason: sending " << host_offline_reason;
+
+ // Ensure that any subsequent callbacks from the HeartbeatSender or
+ // SignalingConnector don't touch the Listener.
+ weak_factory_for_listener_->InvalidateWeakPtrs();
+
+ heartbeat_sender_->SetHostOfflineReason(
+ host_offline_reason, timeout,
+ base::Bind(&HostSignalingManager::OnHostOfflineReasonAck,
+ base::Unretained(this)));
+}
+
+void HostSignalingManager::OnHostOfflineReasonAck(bool success) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+ if (success) {
+ HOST_LOG << "SendHostOfflineReason: succeeded";
+ } else {
+ HOST_LOG << "SendHostOfflineReason: timed out";
+ }
+
+ delete this;
+}
+
+} // namespace remoting
diff --git a/remoting/host/host_signaling_manager.h b/remoting/host/host_signaling_manager.h
new file mode 100644
index 0000000..1004dd8
--- /dev/null
+++ b/remoting/host/host_signaling_manager.h
@@ -0,0 +1,129 @@
+// Copyright 2014 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.
+
+#ifndef REMOTING_HOST_HOST_SIGNALING_MANAGER_H_
+#define REMOTING_HOST_HOST_SIGNALING_MANAGER_H_
+
+#include <string>
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "remoting/base/auto_thread_task_runner.h"
+#include "remoting/base/rsa_key_pair.h"
+#include "remoting/host/oauth_token_getter.h"
+#include "remoting/signaling/xmpp_signal_strategy.h"
+
+namespace base {
+class TimeDelta;
+}
+
+namespace net {
+class NetworkChangeNotifier;
+}
+
+namespace remoting {
+
+class ChromotingHostContext;
+class DnsBlackholeChecker;
+class HeartbeatSender;
+class OAuthTokenGetter;
+class SignalStrategy;
+class SignalingConnector;
+
+// HostSignalingManager has 2 functions:
+// 1. Keep sending regular heartbeats to the Chromoting Directory.
+// 2. Keep the host process alive while sending host-offline-reason heartbeat.
+class HostSignalingManager {
+ public:
+ class Listener {
+ public:
+ virtual ~Listener() {}
+
+ // Invoked after the first successful heartbeat.
+ virtual void OnHeartbeatSuccessful() = 0;
+
+ // Invoked when the host ID is permanently not recognized by the server.
+ virtual void OnUnknownHostIdError() = 0;
+
+ // Invoked when authentication fails.
+ virtual void OnAuthFailed() = 0;
+ };
+
+ // TODO(lukasza): Refactor to limit the number of parameters below.
+ // Probably necessitates refactoring HostProcess to extract a new
+ // class to read and store config/policy/cmdline values.
+ //
+ // |listener| has to be valid until either
+ // 1) the returned HostSignalingManager is destroyed
+ // or 2) SendHostOfflineReasonAndDelete is called.
+ static scoped_ptr<HostSignalingManager> Create(
+ Listener* listener,
+ const scoped_refptr<AutoThreadTaskRunner>& network_task_runner,
+ const scoped_refptr<net::URLRequestContextGetter>&
+ url_request_context_getter,
+ const XmppSignalStrategy::XmppServerConfig& xmpp_server_config,
+ const std::string& talkgadget_prefix_policy,
+ const std::string& host_id,
+ const scoped_refptr<const RsaKeyPair>& host_key_pair,
+ const std::string& directory_bot_jid,
+ scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials);
+
+ ~HostSignalingManager();
+
+ // Get the SignalStrategy to use for talking to the Chromoting bot.
+ // Returned SignalStrategy remains owned by the HostSignalingManager.
+ SignalStrategy* signal_strategy() { return signal_strategy_.get(); }
+
+ // Kicks off sending a heartbeat containing a host-offline-reason attribute.
+ // Prevents future calls to the |listener| provided to the Create method.
+ //
+ // Will delete |this| once either the bot acks receiving the
+ // |host_offline_reason|, or the |timeout| is reached. Deleting
+ // |this| will release |network_task_runner_| and allow the host
+ // process to exit.
+ void SendHostOfflineReasonAndDelete(const std::string& host_offline_reason,
+ const base::TimeDelta& timeout);
+
+ private:
+ HostSignalingManager(
+ scoped_ptr<base::WeakPtrFactory<Listener>> weak_factory_for_listener,
+ const scoped_refptr<AutoThreadTaskRunner>& network_task_runner,
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier,
+ scoped_ptr<SignalStrategy> signal_strategy,
+ scoped_ptr<SignalingConnector> signaling_connector,
+ scoped_ptr<HeartbeatSender> heartbeat_sender);
+
+ void OnHostOfflineReasonAck(bool success);
+
+ // Used to bind HeartbeatSender and SignalingConnector callbacks to |listener|
+ // in a way that allows "detaching" the |listener| when either |this| is
+ // destroyed or when SendHostOfflineReasonAndDelete method is called.
+ scoped_ptr<base::WeakPtrFactory<Listener>> weak_factory_for_listener_;
+
+ // By holding a reference to |network_task_runner_|, HostSignalingManager is
+ // extending the lifetime of the host process. This is needed for the case
+ // where an instance of HostProcess has already been destroyed, but we want
+ // to keep the process running while we try to establish a connection and send
+ // host-offline-reason.
+ scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
+
+ // Order of fields below is important for destroying them in the right order.
+ // - |heartbeat_sender_| and |signaling_connector_| have to be destroyed
+ // before |signal_strategy_| because their destructors need to call
+ // signal_strategy_->RemoveListener(this)
+ // - |signaling_connector_| has to be destroyed before
+ // |network_change_notifier_| because its destructor needs to deregister
+ // network change notifications
+ scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
+ scoped_ptr<SignalStrategy> signal_strategy_;
+ scoped_ptr<SignalingConnector> signaling_connector_;
+ scoped_ptr<HeartbeatSender> heartbeat_sender_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostSignalingManager);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_HOST_SIGNALING_MANAGER_H_
diff --git a/remoting/host/mock_callback.h b/remoting/host/mock_callback.h
deleted file mode 100644
index ca3feb6..0000000
--- a/remoting/host/mock_callback.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2014 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.
-
-#ifndef REMOTING_HOST_MOCK_CALLBACK_H_
-#define REMOTING_HOST_MOCK_CALLBACK_H_
-
-// TODO(lukasza): If possible, move this header file to base/mock_callback.h
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/callback.h"
-
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace remoting {
-
-template <typename Sig>
-class MockCallback;
-
-template <typename R>
-class MockCallback<R()> {
- public:
- MOCK_CONST_METHOD0_T(Run, R());
-
- MockCallback() {
- }
-
- // Caller of GetCallback has to guarantee that the returned callback
- // will not be run after |this| is destroyed.
- base::Callback<R()> GetCallback() {
- return base::Bind(&MockCallback<R()>::Run, base::Unretained(this));
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
-};
-
-typedef MockCallback<void(void)> MockClosure;
-
-} // namespace remoting
-
-#endif // REMOTING_HOST_MOCK_CALLBACK_H_
diff --git a/remoting/host/oauth_token_getter.cc b/remoting/host/oauth_token_getter.cc
index 93756b2..bdfe81b 100644
--- a/remoting/host/oauth_token_getter.cc
+++ b/remoting/host/oauth_token_getter.cc
@@ -34,7 +34,8 @@ OAuthTokenGetter::OAuthCredentials::OAuthCredentials(
OAuthTokenGetter::OAuthTokenGetter(
scoped_ptr<OAuthCredentials> oauth_credentials,
- scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
+ const scoped_refptr<net::URLRequestContextGetter>&
+ url_request_context_getter,
bool auto_refresh)
: oauth_credentials_(oauth_credentials.Pass()),
gaia_oauth_client_(
diff --git a/remoting/host/oauth_token_getter.h b/remoting/host/oauth_token_getter.h
index 20b6079..6398532 100644
--- a/remoting/host/oauth_token_getter.h
+++ b/remoting/host/oauth_token_getter.h
@@ -42,6 +42,9 @@ class OAuthTokenGetter :
// This structure contains information required to perform
// authentication to OAuth2.
struct OAuthCredentials {
+ // |is_service_account| should be True if the OAuth refresh token is for a
+ // service account, False for a user account, to allow the correct client-ID
+ // to be used.
OAuthCredentials(const std::string& login,
const std::string& refresh_token,
bool is_service_account);
@@ -56,10 +59,10 @@ class OAuthTokenGetter :
bool is_service_account;
};
- OAuthTokenGetter(
- scoped_ptr<OAuthCredentials> oauth_credentials,
- scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
- bool auto_refresh);
+ OAuthTokenGetter(scoped_ptr<OAuthCredentials> oauth_credentials,
+ const scoped_refptr<net::URLRequestContextGetter>&
+ url_request_context_getter,
+ bool auto_refresh);
~OAuthTokenGetter() override;
// Call |on_access_token| with an access token, or the failure status.
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
index 74ce044c..a364e19 100644
--- a/remoting/host/remoting_me2me_host.cc
+++ b/remoting/host/remoting_me2me_host.cc
@@ -26,7 +26,6 @@
#include "ipc/ipc_channel_proxy.h"
#include "ipc/ipc_listener.h"
#include "media/base/media.h"
-#include "net/base/network_change_notifier.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/ssl_server_socket.h"
#include "net/url_request/url_fetcher.h"
@@ -45,13 +44,12 @@
#include "remoting/host/config_watcher.h"
#include "remoting/host/desktop_environment.h"
#include "remoting/host/desktop_session_connector.h"
-#include "remoting/host/dns_blackhole_checker.h"
-#include "remoting/host/heartbeat_sender.h"
#include "remoting/host/host_change_notification_listener.h"
#include "remoting/host/host_config.h"
#include "remoting/host/host_event_logger.h"
#include "remoting/host/host_exit_codes.h"
#include "remoting/host/host_main.h"
+#include "remoting/host/host_signaling_manager.h"
#include "remoting/host/host_status_logger.h"
#include "remoting/host/ipc_constants.h"
#include "remoting/host/ipc_desktop_environment.h"
@@ -143,15 +141,19 @@ const char kWindowIdSwitchName[] = "window-id";
// of the process.
const int kShutdownTimeoutSeconds = 15;
+// Maximum time to wait for reporting host-offline-reason to the service,
+// before continuing normal process shutdown.
+const int kHostOfflineReasonTimeoutSeconds = 10;
+
} // namespace
namespace remoting {
-class HostProcess
- : public ConfigWatcher::Delegate,
- public HostChangeNotificationListener::Listener,
- public IPC::Listener,
- public base::RefCountedThreadSafe<HostProcess> {
+class HostProcess : public ConfigWatcher::Delegate,
+ public HostSignalingManager::Listener,
+ public HostChangeNotificationListener::Listener,
+ public IPC::Listener,
+ public base::RefCountedThreadSafe<HostProcess> {
public:
// |shutdown_watchdog| is armed when shutdown is started, and should be kept
// alive as long as possible until the process exits (since destroying the
@@ -254,19 +256,23 @@ class HostProcess
bool OnPairingPolicyUpdate(base::DictionaryValue* policies);
bool OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies);
- void StartHost();
+ scoped_ptr<HostSignalingManager> CreateHostSignalingManager();
- void OnHeartbeatSuccessful();
- void OnUnknownHostIdError();
+ void StartHost();
- void OnAuthFailed();
+ // Overrides for HostSignalingManager::Listener interface.
+ void OnHeartbeatSuccessful() override;
+ void OnUnknownHostIdError() override;
+ void OnAuthFailed() override;
void RestartHost();
// Stops the host and shuts down the process with the specified |exit_code|.
void ShutdownHost(HostExitCodes exit_code);
- void ScheduleHostShutdown();
+ // Private helper used by ShutdownHost method to initiate sending of
+ // host-offline-reason before continuing shutdown.
+ void SendOfflineReasonAndShutdownOnNetworkThread(HostExitCodes exit_code);
void ShutdownOnNetworkThread();
@@ -289,9 +295,6 @@ class HostProcess
scoped_ptr<ChromotingHostContext> context_;
- // Created on the UI thread but used from the network thread.
- scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
-
// Accessed on the UI thread.
scoped_ptr<IPC::ChannelProxy> daemon_channel_;
@@ -341,10 +344,10 @@ class HostProcess
// Used to specify which window to stream, if enabled.
webrtc::WindowId window_id_;
- scoped_ptr<OAuthTokenGetter> oauth_token_getter_;
- scoped_ptr<XmppSignalStrategy> signal_strategy_;
- scoped_ptr<SignalingConnector> signaling_connector_;
- scoped_ptr<HeartbeatSender> heartbeat_sender_;
+ // Used to send heartbeats while running, and the reason for going offline
+ // when shutting down.
+ scoped_ptr<HostSignalingManager> host_signaling_manager_;
+
scoped_ptr<HostChangeNotificationListener> host_change_notification_listener_;
scoped_ptr<HostStatusLogger> host_status_logger_;
scoped_ptr<HostEventLogger> host_event_logger_;
@@ -364,6 +367,8 @@ class HostProcess
scoped_refptr<PairingRegistry> pairing_registry_;
ShutdownWatchdog* shutdown_watchdog_;
+
+ DISALLOW_COPY_AND_ASSIGN(HostProcess);
};
HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context,
@@ -777,7 +782,6 @@ void HostProcess::ShutdownOnUiThread() {
DCHECK(context_->ui_task_runner()->BelongsToCurrentThread());
// Tear down resources that need to be torn down on the UI thread.
- network_change_notifier_.reset();
daemon_channel_.reset();
desktop_environment_factory_.reset();
@@ -793,7 +797,6 @@ void HostProcess::ShutdownOnUiThread() {
#endif
}
-// Overridden from HeartbeatSender::Listener
void HostProcess::OnUnknownHostIdError() {
LOG(ERROR) << "Host ID not found.";
ShutdownHost(kInvalidHostIdExitCode);
@@ -899,7 +902,8 @@ bool HostProcess::ApplyConfig(const base::DictionaryValue& config) {
}
if (!oauth_refresh_token_.empty()) {
- // SignalingConnector is responsible for getting OAuth token.
+ // SignalingConnector (inside HostSignalingManager) is responsible for
+ // getting OAuth token.
xmpp_server_config_.auth_token = "";
xmpp_server_config_.auth_service = "oauth2";
} else if (!config.GetString(kXmppAuthServiceConfigPath,
@@ -1279,44 +1283,32 @@ bool HostProcess::OnGnubbyAuthPolicyUpdate(base::DictionaryValue* policies) {
return true;
}
+scoped_ptr<HostSignalingManager> HostProcess::CreateHostSignalingManager() {
+ DCHECK(!host_id_.empty()); // |ApplyConfig| should already have been run.
+
+ scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials(
+ new OAuthTokenGetter::OAuthCredentials(xmpp_server_config_.username,
+ oauth_refresh_token_,
+ use_service_account_));
+
+ return HostSignalingManager::Create(this, context_->network_task_runner(),
+ context_->url_request_context_getter(),
+ xmpp_server_config_, talkgadget_prefix_,
+ host_id_, key_pair_, directory_bot_jid_,
+ oauth_credentials.Pass());
+}
+
void HostProcess::StartHost() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
DCHECK(!host_);
- DCHECK(!signal_strategy_.get());
+ DCHECK(!host_signaling_manager_);
+
DCHECK(state_ == HOST_INITIALIZING || state_ == HOST_STOPPING_TO_RESTART ||
- state_ == HOST_STOPPED) << state_;
+ state_ == HOST_STOPPED)
+ << "state_ = " << state_;
state_ = HOST_STARTED;
- signal_strategy_.reset(
- new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(),
- context_->url_request_context_getter(),
- xmpp_server_config_));
-
- scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker(
- new DnsBlackholeChecker(context_->url_request_context_getter(),
- talkgadget_prefix_));
-
- // Create a NetworkChangeNotifier for use by the signaling connector.
- network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
-
- signaling_connector_.reset(new SignalingConnector(
- signal_strategy_.get(),
- dns_blackhole_checker.Pass(),
- base::Bind(&HostProcess::OnAuthFailed, this)));
-
- if (!oauth_refresh_token_.empty()) {
- scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials;
- oauth_credentials.reset(
- new OAuthTokenGetter::OAuthCredentials(
- xmpp_server_config_.username, oauth_refresh_token_,
- use_service_account_));
-
- oauth_token_getter_.reset(new OAuthTokenGetter(
- oauth_credentials.Pass(), context_->url_request_context_getter(),
- false));
-
- signaling_connector_->EnableOAuth(oauth_token_getter_.get());
- }
+ host_signaling_manager_ = CreateHostSignalingManager();
uint32 network_flags = 0;
if (allow_nat_traversal_) {
@@ -1340,15 +1332,14 @@ void HostProcess::StartHost() {
}
host_.reset(new ChromotingHost(
- signal_strategy_.get(),
+ host_signaling_manager_->signal_strategy(),
desktop_environment_factory_.get(),
- CreateHostSessionManager(signal_strategy_.get(), network_settings,
+ CreateHostSessionManager(host_signaling_manager_->signal_strategy(),
+ network_settings,
context_->url_request_context_getter()),
- context_->audio_task_runner(),
- context_->input_task_runner(),
+ context_->audio_task_runner(), context_->input_task_runner(),
context_->video_capture_task_runner(),
- context_->video_encode_task_runner(),
- context_->network_task_runner(),
+ context_->video_encode_task_runner(), context_->network_task_runner(),
context_->ui_task_runner()));
if (enable_vp9_) {
@@ -1370,17 +1361,13 @@ void HostProcess::StartHost() {
host_->SetMaximumSessionDuration(base::TimeDelta::FromHours(20));
#endif
- heartbeat_sender_.reset(new HeartbeatSender(
- base::Bind(&HostProcess::OnHeartbeatSuccessful, base::Unretained(this)),
- base::Bind(&HostProcess::OnUnknownHostIdError, base::Unretained(this)),
- host_id_, signal_strategy_.get(), key_pair_, directory_bot_jid_));
-
host_change_notification_listener_.reset(new HostChangeNotificationListener(
- this, host_id_, signal_strategy_.get(), directory_bot_jid_));
+ this, host_id_, host_signaling_manager_->signal_strategy(),
+ directory_bot_jid_));
- host_status_logger_.reset(
- new HostStatusLogger(host_->AsWeakPtr(), ServerLogEntry::ME2ME,
- signal_strategy_.get(), directory_bot_jid_));
+ host_status_logger_.reset(new HostStatusLogger(
+ host_->AsWeakPtr(), ServerLogEntry::ME2ME,
+ host_signaling_manager_->signal_strategy(), directory_bot_jid_));
// Set up reporting the host status notifications.
#if defined(REMOTING_MULTI_PROCESS)
@@ -1409,6 +1396,16 @@ void HostProcess::RestartHost() {
ShutdownOnNetworkThread();
}
+void HostProcess::SendOfflineReasonAndShutdownOnNetworkThread(
+ HostExitCodes exit_code) {
+ DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
+ DCHECK(host_signaling_manager_);
+ host_signaling_manager_.release()->SendHostOfflineReasonAndDelete(
+ ExitCodeToString(exit_code),
+ base::TimeDelta::FromSeconds(kHostOfflineReasonTimeoutSeconds));
+ ShutdownOnNetworkThread();
+}
+
void HostProcess::ShutdownHost(HostExitCodes exit_code) {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
@@ -1417,14 +1414,14 @@ void HostProcess::ShutdownHost(HostExitCodes exit_code) {
switch (state_) {
case HOST_INITIALIZING:
state_ = HOST_STOPPING;
- ShutdownOnNetworkThread();
+ DCHECK(!host_signaling_manager_);
+ host_signaling_manager_ = CreateHostSignalingManager();
+ SendOfflineReasonAndShutdownOnNetworkThread(exit_code);
break;
case HOST_STARTED:
state_ = HOST_STOPPING;
- heartbeat_sender_->SetHostOfflineReason(
- ExitCodeToString(exit_code), base::Bind(base::DoNothing));
- ScheduleHostShutdown();
+ SendOfflineReasonAndShutdownOnNetworkThread(exit_code);
break;
case HOST_STOPPING_TO_RESTART:
@@ -1438,28 +1435,14 @@ void HostProcess::ShutdownHost(HostExitCodes exit_code) {
}
}
-// TODO(weitaosu): shut down the host once we get an ACK for the offline status
-// XMPP message.
-void HostProcess::ScheduleHostShutdown() {
- // Delay the shutdown by 2 second to allow SendOfflineStatus to complete.
- context_->network_task_runner()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&HostProcess::ShutdownOnNetworkThread, base::Unretained(this)),
- base::TimeDelta::FromSeconds(2));
-}
-
void HostProcess::ShutdownOnNetworkThread() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
host_.reset();
host_event_logger_.reset();
host_status_logger_.reset();
- heartbeat_sender_.reset();
+ host_signaling_manager_.reset();
host_change_notification_listener_.reset();
- signaling_connector_.reset();
- oauth_token_getter_.reset();
- signal_strategy_.reset();
- network_change_notifier_.reset();
if (state_ == HOST_STOPPING_TO_RESTART) {
StartHost();
diff --git a/remoting/host/signaling_connector.cc b/remoting/host/signaling_connector.cc
index dbc2f33..adc1571 100644
--- a/remoting/host/signaling_connector.cc
+++ b/remoting/host/signaling_connector.cc
@@ -45,8 +45,9 @@ SignalingConnector::~SignalingConnector() {
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
}
-void SignalingConnector::EnableOAuth(OAuthTokenGetter* oauth_token_getter) {
- oauth_token_getter_ = oauth_token_getter;
+void SignalingConnector::EnableOAuth(
+ scoped_ptr<OAuthTokenGetter> oauth_token_getter) {
+ oauth_token_getter_ = oauth_token_getter.Pass();
}
void SignalingConnector::OnSignalStrategyStateChange(
diff --git a/remoting/host/signaling_connector.h b/remoting/host/signaling_connector.h
index feba6cf..acb6921 100644
--- a/remoting/host/signaling_connector.h
+++ b/remoting/host/signaling_connector.h
@@ -39,8 +39,7 @@ class SignalingConnector
// May be called immediately after the constructor to enable OAuth
// access token updating.
- // |oauth_token_getter| must outlive SignalingConnector.
- void EnableOAuth(OAuthTokenGetter* oauth_token_getter);
+ void EnableOAuth(scoped_ptr<OAuthTokenGetter> oauth_token_getter);
// OAuthTokenGetter callback.
void OnAccessToken(OAuthTokenGetter::Status status,
@@ -69,7 +68,7 @@ class SignalingConnector
base::Closure auth_failed_callback_;
scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker_;
- OAuthTokenGetter* oauth_token_getter_;
+ scoped_ptr<OAuthTokenGetter> oauth_token_getter_;
// Number of times we tried to connect without success.
int reconnect_attempts_;
diff --git a/remoting/remoting_host_srcs.gypi b/remoting/remoting_host_srcs.gypi
index 76eb02b..8a27eb8 100644
--- a/remoting/remoting_host_srcs.gypi
+++ b/remoting/remoting_host_srcs.gypi
@@ -118,6 +118,8 @@
'host/host_extension_session_manager.h',
'host/host_secret.cc',
'host/host_secret.h',
+ 'host/host_signaling_manager.cc',
+ 'host/host_signaling_manager.h',
'host/host_status_logger.cc',
'host/host_status_logger.h',
'host/host_status_monitor.h',
diff --git a/remoting/remoting_test.gypi b/remoting/remoting_test.gypi
index 9b837e1..348aba8 100644
--- a/remoting/remoting_test.gypi
+++ b/remoting/remoting_test.gypi
@@ -26,7 +26,6 @@
'host/fake_host_status_monitor.h',
'host/fake_mouse_cursor_monitor.cc',
'host/fake_mouse_cursor_monitor.h',
- 'host/mock_callback.h',
'host/policy_hack/fake_policy_watcher.cc',
'host/policy_hack/fake_policy_watcher.h',
'host/policy_hack/mock_policy_callback.cc',
diff --git a/remoting/signaling/xmpp_signal_strategy.cc b/remoting/signaling/xmpp_signal_strategy.cc
index c862923..806852e 100644
--- a/remoting/signaling/xmpp_signal_strategy.cc
+++ b/remoting/signaling/xmpp_signal_strategy.cc
@@ -48,7 +48,7 @@ XmppSignalStrategy::XmppServerConfig::~XmppServerConfig() {}
XmppSignalStrategy::XmppSignalStrategy(
net::ClientSocketFactory* socket_factory,
- scoped_refptr<net::URLRequestContextGetter> request_context_getter,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
const XmppSignalStrategy::XmppServerConfig& xmpp_server_config)
: socket_factory_(socket_factory),
request_context_getter_(request_context_getter),
diff --git a/remoting/signaling/xmpp_signal_strategy.h b/remoting/signaling/xmpp_signal_strategy.h
index 5216d77..18ae841 100644
--- a/remoting/signaling/xmpp_signal_strategy.h
+++ b/remoting/signaling/xmpp_signal_strategy.h
@@ -55,7 +55,7 @@ class XmppSignalStrategy : public base::NonThreadSafe,
XmppSignalStrategy(
net::ClientSocketFactory* socket_factory,
- scoped_refptr<net::URLRequestContextGetter> request_context_getter,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
const XmppServerConfig& xmpp_server_config);
~XmppSignalStrategy() override;