summaryrefslogtreecommitdiffstats
path: root/remoting/host
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 15:56:57 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-03 15:56:57 +0000
commite05eb1d621ca0a26e0b33c650d4dbf456dba6863 (patch)
tree97322432de7e2381eb065cc3af19d53abba6e2f3 /remoting/host
parentfbc94a82c898c17dffbb7bad4f2ed70ffc15b133 (diff)
downloadchromium_src-e05eb1d621ca0a26e0b33c650d4dbf456dba6863.zip
chromium_src-e05eb1d621ca0a26e0b33c650d4dbf456dba6863.tar.gz
chromium_src-e05eb1d621ca0a26e0b33c650d4dbf456dba6863.tar.bz2
Refactor JingleClient to support thunking the xmpp signaling into Javascript.
We do this so that we may make HTTP requests using the javascript libraries available to Google Talk. This is required to allow us to sandbox. BUG=none TEST=none Review URL: http://codereview.chromium.org/6597092 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76746 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r--remoting/host/chromoting_host.cc19
-rw-r--r--remoting/host/chromoting_host.h2
-rw-r--r--remoting/host/heartbeat_sender.cc33
-rw-r--r--remoting/host/heartbeat_sender.h15
-rw-r--r--remoting/host/heartbeat_sender_unittest.cc36
5 files changed, 64 insertions, 41 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 38437e8..9522b5c 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -97,12 +97,19 @@ void ChromotingHost::Start(Task* shutdown_task) {
return;
// Connect to the talk network with a JingleClient.
- jingle_client_ = new JingleClient(context_->jingle_thread());
- jingle_client_->Init(xmpp_login, xmpp_auth_token,
- kChromotingTokenServiceName, this);
-
- heartbeat_sender_ = new HeartbeatSender();
- if (!heartbeat_sender_->Init(config_, jingle_client_.get())) {
+ signal_strategy_.reset(
+ new XmppSignalStrategy(context_->jingle_thread(), xmpp_login,
+ xmpp_auth_token,
+ kChromotingTokenServiceName));
+ jingle_client_ = new JingleClient(context_->jingle_thread(),
+ signal_strategy_.get(),
+ this);
+ jingle_client_->Init();
+
+ heartbeat_sender_ =
+ new HeartbeatSender(context_->jingle_thread()->message_loop(),
+ jingle_client_.get(), config_);
+ if (!heartbeat_sender_->Init()) {
LOG(ERROR) << "Failed to initialize HeartbeatSender.";
return;
}
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index 5a5959f..fc6daaf 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -154,6 +154,8 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
scoped_ptr<DesktopEnvironment> desktop_environment_;
+ scoped_ptr<SignalStrategy> signal_strategy_;
+
// The libjingle client. This is used to connect to the talk network to
// receive connection requests from chromoting client.
scoped_refptr<JingleClient> jingle_client_;
diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc
index 74c08c3..56ec751 100644
--- a/remoting/host/heartbeat_sender.cc
+++ b/remoting/host/heartbeat_sender.cc
@@ -33,29 +33,32 @@ const char kSetIntervalTag[] = "set-interval";
const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes.
}
-HeartbeatSender::HeartbeatSender()
+HeartbeatSender::HeartbeatSender(MessageLoop* message_loop,
+ JingleClient* jingle_client,
+ MutableHostConfig* config)
+
: state_(CREATED),
+ message_loop_(message_loop),
+ jingle_client_(jingle_client),
+ config_(config),
interval_ms_(kDefaultHeartbeatIntervalMs) {
+ DCHECK(jingle_client_);
+ DCHECK(config_);
}
HeartbeatSender::~HeartbeatSender() {
DCHECK(state_ == CREATED || state_ == INITIALIZED || state_ == STOPPED);
}
-bool HeartbeatSender::Init(MutableHostConfig* config,
- JingleClient* jingle_client) {
- DCHECK(jingle_client);
+bool HeartbeatSender::Init() {
DCHECK(state_ == CREATED);
- jingle_client_ = jingle_client;
- config_ = config;
-
if (!config_->GetString(kHostIdConfigPath, &host_id_)) {
LOG(ERROR) << "host_id is not defined in the config.";
return false;
}
- if (!key_pair_.Load(config)) {
+ if (!key_pair_.Load(config_)) {
return false;
}
@@ -65,8 +68,8 @@ bool HeartbeatSender::Init(MutableHostConfig* config,
}
void HeartbeatSender::Start() {
- if (MessageLoop::current() != jingle_client_->message_loop()) {
- jingle_client_->message_loop()->PostTask(
+ if (MessageLoop::current() != message_loop_) {
+ message_loop_->PostTask(
FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::Start));
return;
}
@@ -77,13 +80,13 @@ void HeartbeatSender::Start() {
request_.reset(jingle_client_->CreateIqRequest());
request_->set_callback(NewCallback(this, &HeartbeatSender::ProcessResponse));
- jingle_client_->message_loop()->PostTask(
+ message_loop_->PostTask(
FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::DoSendStanza));
}
void HeartbeatSender::Stop() {
- if (MessageLoop::current() != jingle_client_->message_loop()) {
- jingle_client_->message_loop()->PostTask(
+ if (MessageLoop::current() != message_loop_) {
+ message_loop_->PostTask(
FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::Stop));
return;
}
@@ -99,7 +102,7 @@ void HeartbeatSender::DoSendStanza() {
if (state_ == STARTED) {
// |jingle_client_| may be already destroyed if |state_| is set to
// |STOPPED|, so don't touch it here unless we are in |STARTED| state.
- DCHECK(MessageLoop::current() == jingle_client_->message_loop());
+ DCHECK(MessageLoop::current() == message_loop_);
VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid;
@@ -107,7 +110,7 @@ void HeartbeatSender::DoSendStanza() {
CreateHeartbeatMessage());
// Schedule next heartbeat.
- jingle_client_->message_loop()->PostDelayedTask(
+ message_loop_->PostDelayedTask(
FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::DoSendStanza),
interval_ms_);
}
diff --git a/remoting/host/heartbeat_sender.h b/remoting/host/heartbeat_sender.h
index ef310b4..089e040 100644
--- a/remoting/host/heartbeat_sender.h
+++ b/remoting/host/heartbeat_sender.h
@@ -18,6 +18,7 @@ namespace remoting {
class IqRequest;
class HostKeyPair;
class JingleClient;
+class JingleThread;
class MutableHostConfig;
// HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot.
@@ -56,13 +57,14 @@ class MutableHostConfig;
// TODO(sergeyu): Is it enough to sign JID and nothing else?
class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> {
public:
- HeartbeatSender();
+ HeartbeatSender(MessageLoop* main_loop,
+ JingleClient* jingle_client,
+ MutableHostConfig* config);
virtual ~HeartbeatSender();
- // Initializes heart-beating for |jingle_client| with the specified
- // config. Returns false if the config is invalid (e.g. private key
- // cannot be parsed).
- bool Init(MutableHostConfig* config, JingleClient* jingle_client);
+ // Initializes heart-beating for |jingle_client_| with |config_|. Returns
+ // false if the config is invalid (e.g. private key cannot be parsed).
+ bool Init();
// Starts heart-beating. Must be called after init.
void Start();
@@ -96,8 +98,9 @@ class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> {
void ProcessResponse(const buzz::XmlElement* response);
State state_;
- scoped_refptr<MutableHostConfig> config_;
+ MessageLoop* message_loop_;
JingleClient* jingle_client_;
+ scoped_refptr<MutableHostConfig> config_;
scoped_ptr<IqRequest> request_;
std::string host_id_;
HostKeyPair key_pair_;
diff --git a/remoting/host/heartbeat_sender_unittest.cc b/remoting/host/heartbeat_sender_unittest.cc
index 6e1f4fe..fc59c33 100644
--- a/remoting/host/heartbeat_sender_unittest.cc
+++ b/remoting/host/heartbeat_sender_unittest.cc
@@ -36,20 +36,21 @@ const char kTestJid[] = "user@gmail.com/chromoting123";
const int64 kTestTime = 123123123;
} // namespace
-class MockJingleClient : public JingleClient {
+class MockSignalStrategy : public SignalStrategy {
public:
- explicit MockJingleClient(JingleThread* thread) : JingleClient(thread) { }
+ MOCK_METHOD1(Init, void(StatusObserver* observer));
+ MOCK_METHOD0(port_allocator, cricket::BasicPortAllocator*());
+ MOCK_METHOD1(StartSession, void(cricket::SessionManager* session_manager));
+ MOCK_METHOD0(EndSession, void());
MOCK_METHOD0(CreateIqRequest, IqRequest*());
};
class MockIqRequest : public IqRequest {
public:
- explicit MockIqRequest(JingleClient* jingle_client)
- : IqRequest(jingle_client) {
- }
MOCK_METHOD3(SendIq, void(const std::string& type,
const std::string& addressee,
XmlElement* iq_body));
+ MOCK_METHOD1(set_callback, void(IqRequest::ReplyCallback*));
};
class HeartbeatSenderTest : public testing::Test {
@@ -61,12 +62,15 @@ class HeartbeatSenderTest : public testing::Test {
jingle_thread_.message_loop_ = &message_loop_;
- jingle_client_ = new MockJingleClient(&jingle_thread_);
+ signal_strategy_.reset(new MockSignalStrategy());
+ jingle_client_ =
+ new JingleClient(&jingle_thread_, signal_strategy_.get(), NULL);
jingle_client_->full_jid_ = kTestJid;
}
JingleThread jingle_thread_;
- scoped_refptr<MockJingleClient> jingle_client_;
+ scoped_ptr<MockSignalStrategy> signal_strategy_;
+ scoped_refptr<JingleClient> jingle_client_;
MessageLoop message_loop_;
scoped_refptr<InMemoryHostConfig> config_;
};
@@ -75,12 +79,14 @@ class HeartbeatSenderTest : public testing::Test {
// being send.
TEST_F(HeartbeatSenderTest, DoSendStanza) {
// |iq_request| is freed by HeartbeatSender.
- MockIqRequest* iq_request = new MockIqRequest(jingle_client_);
+ MockIqRequest* iq_request = new MockIqRequest();
+ EXPECT_CALL(*iq_request, set_callback(_)).Times(1);
- scoped_refptr<HeartbeatSender> heartbeat_sender(new HeartbeatSender());
- ASSERT_TRUE(heartbeat_sender->Init(config_, jingle_client_));
+ scoped_refptr<HeartbeatSender> heartbeat_sender(
+ new HeartbeatSender(&message_loop_, jingle_client_.get(), config_));
+ ASSERT_TRUE(heartbeat_sender->Init());
- EXPECT_CALL(*jingle_client_, CreateIqRequest())
+ EXPECT_CALL(*signal_strategy_, CreateIqRequest())
.WillOnce(Return(iq_request));
EXPECT_CALL(*iq_request, SendIq(buzz::STR_SET, kChromotingBotJid, NotNull()))
@@ -95,8 +101,9 @@ TEST_F(HeartbeatSenderTest, DoSendStanza) {
// Validate format of the heartbeat stanza.
TEST_F(HeartbeatSenderTest, CreateHeartbeatMessage) {
- scoped_refptr<HeartbeatSender> heartbeat_sender(new HeartbeatSender());
- ASSERT_TRUE(heartbeat_sender->Init(config_, jingle_client_));
+ scoped_refptr<HeartbeatSender> heartbeat_sender(
+ new HeartbeatSender(&message_loop_, jingle_client_.get(), config_));
+ ASSERT_TRUE(heartbeat_sender->Init());
int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT());
@@ -145,7 +152,8 @@ TEST_F(HeartbeatSenderTest, ProcessResponse) {
const int kTestInterval = 123;
set_interval->AddText(base::IntToString(kTestInterval));
- scoped_refptr<HeartbeatSender> heartbeat_sender(new HeartbeatSender());
+ scoped_refptr<HeartbeatSender> heartbeat_sender(
+ new HeartbeatSender(&message_loop_, jingle_client_.get(), config_));
heartbeat_sender->ProcessResponse(response.get());
EXPECT_EQ(kTestInterval * 1000, heartbeat_sender->interval_ms_);