summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
Diffstat (limited to 'remoting')
-rw-r--r--remoting/client/chromoting_client.cc21
-rw-r--r--remoting/client/chromoting_client.h2
-rw-r--r--remoting/client/client_context.cc4
-rw-r--r--remoting/client/client_context.h6
-rw-r--r--remoting/client/plugin/pepper_xmpp_proxy.cc9
-rw-r--r--remoting/client/plugin/pepper_xmpp_proxy.h9
-rw-r--r--remoting/host/chromoting_host.cc24
-rw-r--r--remoting/host/chromoting_host_context.cc4
-rw-r--r--remoting/host/chromoting_host_context.h2
-rw-r--r--remoting/host/chromoting_host_unittest.cc9
-rw-r--r--remoting/host/client_session.h1
-rw-r--r--remoting/host/client_session_unittest.cc6
-rw-r--r--remoting/host/heartbeat_sender.cc12
-rw-r--r--remoting/host/heartbeat_sender.h8
-rw-r--r--remoting/host/heartbeat_sender_unittest.cc9
-rw-r--r--remoting/host/host_mock_objects.h2
-rw-r--r--remoting/host/plugin/host_script_object.cc3
-rw-r--r--remoting/host/screen_recorder.cc13
-rw-r--r--remoting/host/screen_recorder.h8
-rw-r--r--remoting/host/screen_recorder_unittest.cc7
-rw-r--r--remoting/jingle_glue/jingle_thread.cc6
-rw-r--r--remoting/jingle_glue/jingle_thread.h10
-rw-r--r--remoting/protocol/buffered_socket_writer.cc26
-rw-r--r--remoting/protocol/buffered_socket_writer.h13
-rw-r--r--remoting/protocol/client_control_sender.cc5
-rw-r--r--remoting/protocol/client_control_sender.h7
-rw-r--r--remoting/protocol/connection_to_client.cc20
-rw-r--r--remoting/protocol/connection_to_client.h9
-rw-r--r--remoting/protocol/connection_to_client_unittest.cc4
-rw-r--r--remoting/protocol/connection_to_host.cc28
-rw-r--r--remoting/protocol/connection_to_host.h8
-rw-r--r--remoting/protocol/fake_session.h2
-rw-r--r--remoting/protocol/host_control_sender.cc5
-rw-r--r--remoting/protocol/host_control_sender.h7
-rw-r--r--remoting/protocol/host_message_dispatcher.h4
-rw-r--r--remoting/protocol/input_sender.cc5
-rw-r--r--remoting/protocol/input_sender.h7
-rw-r--r--remoting/protocol/jingle_session.cc6
-rw-r--r--remoting/protocol/jingle_session_manager.cc14
-rw-r--r--remoting/protocol/jingle_session_manager.h7
-rw-r--r--remoting/protocol/jingle_session_unittest.cc7
-rw-r--r--remoting/protocol/message_reader.cc9
-rw-r--r--remoting/protocol/message_reader.h3
-rw-r--r--remoting/protocol/message_reader_unittest.cc4
-rw-r--r--remoting/protocol/protobuf_video_writer.cc5
-rw-r--r--remoting/protocol/protobuf_video_writer.h6
-rw-r--r--remoting/protocol/protocol_mock_objects.cc13
-rw-r--r--remoting/protocol/protocol_mock_objects.h4
-rw-r--r--remoting/protocol/protocol_test_client.cc4
-rw-r--r--remoting/protocol/rtcp_writer.cc4
-rw-r--r--remoting/protocol/rtcp_writer.h6
-rw-r--r--remoting/protocol/rtp_video_reader.cc3
-rw-r--r--remoting/protocol/rtp_video_reader.h6
-rw-r--r--remoting/protocol/rtp_video_reader_unittest.cc4
-rw-r--r--remoting/protocol/rtp_video_writer.cc5
-rw-r--r--remoting/protocol/rtp_video_writer.h6
-rw-r--r--remoting/protocol/rtp_video_writer_unittest.cc5
-rw-r--r--remoting/protocol/rtp_writer.cc6
-rw-r--r--remoting/protocol/rtp_writer.h2
-rw-r--r--remoting/protocol/video_reader.cc12
-rw-r--r--remoting/protocol/video_reader.h7
-rw-r--r--remoting/protocol/video_writer.cc7
-rw-r--r--remoting/protocol/video_writer.h7
63 files changed, 303 insertions, 184 deletions
diff --git a/remoting/client/chromoting_client.cc b/remoting/client/chromoting_client.cc
index 48b8a21..b78d4b8 100644
--- a/remoting/client/chromoting_client.cc
+++ b/remoting/client/chromoting_client.cc
@@ -5,7 +5,6 @@
#include "remoting/client/chromoting_client.h"
#include "base/bind.h"
-#include "base/message_loop.h"
#include "jingle/glue/thread_wrapper.h"
#include "remoting/base/tracer.h"
#include "remoting/client/chromoting_view.h"
@@ -40,7 +39,7 @@ ChromotingClient::~ChromotingClient() {
}
void ChromotingClient::Start(scoped_refptr<XmppProxy> xmpp_proxy) {
- if (message_loop() != MessageLoop::current()) {
+ if (!message_loop()->BelongsToCurrentThread()) {
message_loop()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &ChromotingClient::Start, xmpp_proxy));
@@ -59,7 +58,7 @@ void ChromotingClient::Start(scoped_refptr<XmppProxy> xmpp_proxy) {
}
void ChromotingClient::Stop(const base::Closure& shutdown_task) {
- if (message_loop() != MessageLoop::current()) {
+ if (!message_loop()->BelongsToCurrentThread()) {
message_loop()->PostTask(
FROM_HERE, base::Bind(&ChromotingClient::Stop,
base::Unretained(this), shutdown_task));
@@ -87,7 +86,7 @@ ChromotingStats* ChromotingClient::GetStats() {
}
void ChromotingClient::Repaint() {
- if (message_loop() != MessageLoop::current()) {
+ if (!message_loop()->BelongsToCurrentThread()) {
message_loop()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &ChromotingClient::Repaint));
@@ -99,7 +98,7 @@ void ChromotingClient::Repaint() {
void ChromotingClient::ProcessVideoPacket(const VideoPacket* packet,
Task* done) {
- if (message_loop() != MessageLoop::current()) {
+ if (!message_loop()->BelongsToCurrentThread()) {
message_loop()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &ChromotingClient::ProcessVideoPacket,
@@ -142,7 +141,7 @@ int ChromotingClient::GetPendingPackets() {
}
void ChromotingClient::DispatchPacket() {
- DCHECK_EQ(message_loop(), MessageLoop::current());
+ DCHECK(message_loop()->BelongsToCurrentThread());
CHECK(!packet_being_processed_);
if (received_packets_.empty()) {
@@ -182,14 +181,14 @@ void ChromotingClient::OnConnectionFailed(protocol::ConnectionToHost* conn) {
SetConnectionState(FAILED);
}
-MessageLoop* ChromotingClient::message_loop() {
+base::MessageLoopProxy* ChromotingClient::message_loop() {
return context_->network_message_loop();
}
void ChromotingClient::SetConnectionState(ConnectionState s) {
// TODO(ajwong): We actually may want state to be a shared variable. Think
// through later.
- if (message_loop() != MessageLoop::current()) {
+ if (!message_loop()->BelongsToCurrentThread()) {
message_loop()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &ChromotingClient::SetConnectionState, s));
@@ -204,7 +203,7 @@ void ChromotingClient::SetConnectionState(ConnectionState s) {
void ChromotingClient::OnPacketDone(bool last_packet,
base::Time decode_start) {
- if (message_loop() != MessageLoop::current()) {
+ if (!message_loop()->BelongsToCurrentThread()) {
message_loop()->PostTask(
FROM_HERE,
NewTracedMethod(this, &ChromotingClient::OnPacketDone,
@@ -232,7 +231,7 @@ void ChromotingClient::OnPacketDone(bool last_packet,
}
void ChromotingClient::Initialize() {
- if (message_loop() != MessageLoop::current()) {
+ if (!message_loop()->BelongsToCurrentThread()) {
message_loop()->PostTask(
FROM_HERE,
NewTracedMethod(this, &ChromotingClient::Initialize));
@@ -254,7 +253,7 @@ void ChromotingClient::Initialize() {
// ClientStub control channel interface.
void ChromotingClient::BeginSessionResponse(
const protocol::LocalLoginStatus* msg, Task* done) {
- if (message_loop() != MessageLoop::current()) {
+ if (!message_loop()->BelongsToCurrentThread()) {
message_loop()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &ChromotingClient::BeginSessionResponse,
diff --git a/remoting/client/chromoting_client.h b/remoting/client/chromoting_client.h
index 45d103d..0dfbb4c 100644
--- a/remoting/client/chromoting_client.h
+++ b/remoting/client/chromoting_client.h
@@ -81,7 +81,7 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
Task* done;
};
- MessageLoop* message_loop();
+ base::MessageLoopProxy* message_loop();
// Initializes connection.
void Initialize();
diff --git a/remoting/client/client_context.cc b/remoting/client/client_context.cc
index 4ad0fab..ca12714 100644
--- a/remoting/client/client_context.cc
+++ b/remoting/client/client_context.cc
@@ -38,8 +38,8 @@ MessageLoop* ClientContext::decode_message_loop() {
return decode_thread_.message_loop();
}
-MessageLoop* ClientContext::network_message_loop() {
- return network_thread_.message_loop();
+base::MessageLoopProxy* ClientContext::network_message_loop() {
+ return network_thread_.message_loop_proxy();
}
} // namespace remoting
diff --git a/remoting/client/client_context.h b/remoting/client/client_context.h
index e825d44..d0d584a 100644
--- a/remoting/client/client_context.h
+++ b/remoting/client/client_context.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/message_loop_proxy.h"
#include "base/threading/thread.h"
namespace remoting {
@@ -23,7 +24,7 @@ class ClientContext {
MessageLoop* main_message_loop();
MessageLoop* decode_message_loop();
- MessageLoop* network_message_loop();
+ base::MessageLoopProxy* network_message_loop();
private:
// A thread that handles capture rate control and sending data to the
@@ -34,6 +35,9 @@ class ClientContext {
base::Thread decode_thread_;
// A thread that handles all network IO.
+ //
+ // TODO(sergeyu): Remove |network_thread_| and use main plugin
+ // message loop for network IO.
base::Thread network_thread_;
DISALLOW_COPY_AND_ASSIGN(ClientContext);
diff --git a/remoting/client/plugin/pepper_xmpp_proxy.cc b/remoting/client/plugin/pepper_xmpp_proxy.cc
index cfdb842..fb96bd1 100644
--- a/remoting/client/plugin/pepper_xmpp_proxy.cc
+++ b/remoting/client/plugin/pepper_xmpp_proxy.cc
@@ -2,17 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "remoting/client/plugin/pepper_xmpp_proxy.h"
#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "remoting/client/plugin/chromoting_scriptable_object.h"
#include "remoting/client/plugin/pepper_util.h"
-#include "remoting/client/plugin/pepper_xmpp_proxy.h"
namespace remoting {
PepperXmppProxy::PepperXmppProxy(
base::WeakPtr<ChromotingScriptableObject> scriptable_object,
- MessageLoop* callback_message_loop)
+ base::MessageLoopProxy* callback_message_loop)
: scriptable_object_(scriptable_object),
callback_message_loop_(callback_message_loop) {
CHECK(CurrentlyOnPluginThread());
@@ -22,7 +23,7 @@ PepperXmppProxy::~PepperXmppProxy() {
}
void PepperXmppProxy::AttachCallback(base::WeakPtr<ResponseCallback> callback) {
- CHECK_EQ(callback_message_loop_, MessageLoop::current());
+ DCHECK(callback_message_loop_->BelongsToCurrentThread());
callback_ = callback;
}
@@ -44,7 +45,7 @@ void PepperXmppProxy::SendIq(const std::string& request_xml) {
}
void PepperXmppProxy::OnIq(const std::string& response_xml) {
- if (MessageLoop::current() != callback_message_loop_) {
+ if (!callback_message_loop_->BelongsToCurrentThread()) {
callback_message_loop_->PostTask(
FROM_HERE,NewRunnableMethod(this,
&PepperXmppProxy::OnIq,
diff --git a/remoting/client/plugin/pepper_xmpp_proxy.h b/remoting/client/plugin/pepper_xmpp_proxy.h
index fc5ee42..aca7f94 100644
--- a/remoting/client/plugin/pepper_xmpp_proxy.h
+++ b/remoting/client/plugin/pepper_xmpp_proxy.h
@@ -5,9 +5,14 @@
#ifndef REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_
#define REMOTING_CLIENT_PLUGIN_PEPPER_XMPP_PROXY_H_
+#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "remoting/jingle_glue/xmpp_proxy.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
class ChromotingScriptableObject;
@@ -16,7 +21,7 @@ class PepperXmppProxy : public XmppProxy {
public:
PepperXmppProxy(
base::WeakPtr<ChromotingScriptableObject> scriptable_object,
- MessageLoop* callback_message_loop);
+ base::MessageLoopProxy* callback_message_loop);
// Registered the callback class with this object.
//
@@ -38,7 +43,7 @@ class PepperXmppProxy : public XmppProxy {
base::WeakPtr<ChromotingScriptableObject> scriptable_object_;
- MessageLoop* callback_message_loop_;
+ scoped_refptr<base::MessageLoopProxy> callback_message_loop_;
// Must only be access on callback_message_loop_.
base::WeakPtr<ResponseCallback> callback_;
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index fbfc0ea..c615528 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/logging.h"
+#include "base/message_loop_proxy.h"
#include "build/build_config.h"
#include "remoting/base/constants.h"
#include "remoting/base/encoder.h"
@@ -67,7 +68,7 @@ ChromotingHost::~ChromotingHost() {
}
void ChromotingHost::Start() {
- if (MessageLoop::current() != context_->network_message_loop()) {
+ if (!context_->network_message_loop()->BelongsToCurrentThread()) {
context_->network_message_loop()->PostTask(
FROM_HERE, base::Bind(&ChromotingHost::Start, this));
return;
@@ -153,7 +154,7 @@ void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) {
////////////////////////////////////////////////////////////////////////////
// protocol::ConnectionToClient::EventHandler implementations
void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) {
- DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
+ DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
VLOG(1) << "Connection to client established.";
// TODO(wez): ChromotingHost shouldn't need to know about Me2Mom.
if (is_it2me_) {
@@ -164,7 +165,7 @@ void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) {
}
void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) {
- DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
+ DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
VLOG(1) << "Connection to client closed.";
context_->main_message_loop()->PostTask(
@@ -173,7 +174,7 @@ void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) {
}
void ChromotingHost::OnConnectionFailed(ConnectionToClient* connection) {
- DCHECK_EQ(context_->network_message_loop(), MessageLoop::current());
+ DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
LOG(ERROR) << "Connection failed unexpectedly.";
context_->main_message_loop()->PostTask(
@@ -199,14 +200,15 @@ void ChromotingHost::OnSequenceNumberUpdated(ConnectionToClient* connection,
// SignalStrategy::StatusObserver implementations
void ChromotingHost::OnStateChange(
SignalStrategy::StatusObserver::State state) {
- DCHECK_EQ(MessageLoop::current(), context_->network_message_loop());
+ DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
if (state == SignalStrategy::StatusObserver::CONNECTED) {
LOG(INFO) << "Host connected as " << local_jid_;
// Create and start session manager.
protocol::JingleSessionManager* server =
- protocol::JingleSessionManager::CreateNotSandboxed();
+ protocol::JingleSessionManager::CreateNotSandboxed(
+ context_->network_message_loop());
// TODO(ajwong): Make this a command switch when we're more stable.
server->set_allow_local_ips(true);
@@ -239,12 +241,12 @@ void ChromotingHost::OnStateChange(
}
void ChromotingHost::OnJidChange(const std::string& full_jid) {
- DCHECK_EQ(MessageLoop::current(), context_->network_message_loop());
+ DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
local_jid_ = full_jid;
}
void ChromotingHost::OnSessionManagerInitialized() {
- DCHECK_EQ(MessageLoop::current(), context_->network_message_loop());
+ DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
// Don't need to do anything here, just wait for incoming
// connections.
}
@@ -252,7 +254,7 @@ void ChromotingHost::OnSessionManagerInitialized() {
void ChromotingHost::OnIncomingSession(
protocol::Session* session,
protocol::SessionManager::IncomingSessionResponse* response) {
- DCHECK_EQ(MessageLoop::current(), context_->network_message_loop());
+ DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
base::AutoLock auto_lock(lock_);
if (state_ != kStarted) {
@@ -332,7 +334,7 @@ void ChromotingHost::set_protocol_config(
}
void ChromotingHost::LocalMouseMoved(const gfx::Point& new_pos) {
- if (MessageLoop::current() != context_->network_message_loop()) {
+ if (!context_->network_message_loop()->BelongsToCurrentThread()) {
context_->network_message_loop()->PostTask(
FROM_HERE, base::Bind(&ChromotingHost::LocalMouseMoved, this, new_pos));
return;
@@ -567,7 +569,7 @@ void ChromotingHost::OnScreenRecorderStopped() {
}
void ChromotingHost::ShutdownNetwork() {
- if (MessageLoop::current() != context_->network_message_loop()) {
+ if (!context_->network_message_loop()->BelongsToCurrentThread()) {
context_->network_message_loop()->PostTask(
FROM_HERE, base::Bind(&ChromotingHost::ShutdownNetwork, this));
return;
diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc
index 603a8e9..de99a1f 100644
--- a/remoting/host/chromoting_host_context.cc
+++ b/remoting/host/chromoting_host_context.cc
@@ -49,8 +49,8 @@ MessageLoop* ChromotingHostContext::encode_message_loop() {
return encode_thread_.message_loop();
}
-MessageLoop* ChromotingHostContext::network_message_loop() {
- return jingle_thread_.message_loop();
+base::MessageLoopProxy* ChromotingHostContext::network_message_loop() {
+ return jingle_thread_.message_loop_proxy();
}
MessageLoop* ChromotingHostContext::desktop_message_loop() {
diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h
index 65c23ed..38f1cae 100644
--- a/remoting/host/chromoting_host_context.h
+++ b/remoting/host/chromoting_host_context.h
@@ -44,7 +44,7 @@ class ChromotingHostContext {
virtual MessageLoop* main_message_loop();
virtual MessageLoop* encode_message_loop();
- virtual MessageLoop* network_message_loop();
+ virtual base::MessageLoopProxy* network_message_loop();
virtual MessageLoop* desktop_message_loop();
// Must be called from the main GUI thread.
diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc
index 6fe5db8..d37f79f 100644
--- a/remoting/host/chromoting_host_unittest.cc
+++ b/remoting/host/chromoting_host_unittest.cc
@@ -4,6 +4,7 @@
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop_proxy.h"
#include "base/task.h"
#include "remoting/host/capturer_fake.h"
#include "remoting/host/chromoting_host.h"
@@ -68,13 +69,14 @@ class ChromotingHostTest : public testing::Test {
}
virtual void SetUp() OVERRIDE {
+ message_loop_proxy_ = base::MessageLoopProxy::CreateForCurrentThread();
config_ = new InMemoryHostConfig();
ON_CALL(context_, main_message_loop())
.WillByDefault(Return(&message_loop_));
ON_CALL(context_, encode_message_loop())
.WillByDefault(Return(&message_loop_));
ON_CALL(context_, network_message_loop())
- .WillByDefault(Return(&message_loop_));
+ .WillByDefault(Return(message_loop_proxy_.get()));
ON_CALL(context_, ui_message_loop())
.WillByDefault(Return(&message_loop_));
EXPECT_CALL(context_, main_message_loop())
@@ -111,9 +113,9 @@ class ChromotingHostTest : public testing::Test {
credentials_.set_username("user");
credentials_.set_credential("password");
connection_ = new MockConnectionToClient(
- &message_loop_, &handler_, &host_stub_, event_executor_);
+ &handler_, &host_stub_, event_executor_);
connection2_ = new MockConnectionToClient(
- &message_loop_, &handler_, &host_stub2_, &event_executor2_);
+ &handler_, &host_stub2_, &event_executor2_);
session_.reset(new MockSession());
session2_.reset(new MockSession());
session_config_.reset(SessionConfig::CreateDefault());
@@ -212,6 +214,7 @@ class ChromotingHostTest : public testing::Test {
protected:
MessageLoop message_loop_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
MockConnectionToClientEventHandler handler_;
scoped_ptr<DesktopEnvironment> desktop_environment_;
scoped_refptr<ChromotingHost> host_;
diff --git a/remoting/host/client_session.h b/remoting/host/client_session.h
index b8339fb..12962ce 100644
--- a/remoting/host/client_session.h
+++ b/remoting/host/client_session.h
@@ -8,6 +8,7 @@
#include <list>
#include <set>
+#include "base/time.h"
#include "remoting/protocol/connection_to_client.h"
#include "remoting/protocol/host_stub.h"
#include "remoting/protocol/input_stub.h"
diff --git a/remoting/host/client_session_unittest.cc b/remoting/host/client_session_unittest.cc
index 94325b1..fca7cd2 100644
--- a/remoting/host/client_session_unittest.cc
+++ b/remoting/host/client_session_unittest.cc
@@ -34,10 +34,8 @@ class ClientSessionTest : public testing::Test {
ClientSessionTest() {}
virtual void SetUp() {
- connection_ = new MockConnectionToClient(&message_loop_,
- &connection_event_handler_,
- &host_stub_,
- &input_stub_);
+ connection_ = new MockConnectionToClient(
+ &connection_event_handler_, &host_stub_, &input_stub_);
user_authenticator_ = new MockUserAuthenticator();
client_session_ = new ClientSession(
&session_event_handler_,
diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc
index f22486c..af739b0 100644
--- a/remoting/host/heartbeat_sender.cc
+++ b/remoting/host/heartbeat_sender.cc
@@ -5,7 +5,7 @@
#include "remoting/host/heartbeat_sender.h"
#include "base/logging.h"
-#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "base/string_number_conversions.h"
#include "base/time.h"
#include "remoting/base/constants.h"
@@ -33,7 +33,7 @@ const char kSetIntervalTag[] = "set-interval";
const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes.
}
-HeartbeatSender::HeartbeatSender(MessageLoop* message_loop,
+HeartbeatSender::HeartbeatSender(base::MessageLoopProxy* message_loop,
MutableHostConfig* config)
: state_(CREATED),
@@ -66,7 +66,7 @@ bool HeartbeatSender::Init() {
void HeartbeatSender::OnSignallingConnected(SignalStrategy* signal_strategy,
const std::string& full_jid) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
+ DCHECK(message_loop_->BelongsToCurrentThread());
DCHECK(state_ == INITIALIZED || state_ == STOPPED);
state_ = STARTED;
@@ -80,7 +80,7 @@ void HeartbeatSender::OnSignallingConnected(SignalStrategy* signal_strategy,
}
void HeartbeatSender::OnSignallingDisconnected() {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
+ DCHECK(message_loop_->BelongsToCurrentThread());
state_ = STOPPED;
request_.reset(NULL);
}
@@ -95,7 +95,7 @@ void HeartbeatSender::OnClientDisconnected(
void HeartbeatSender::OnShutdown() { }
void HeartbeatSender::DoSendStanza() {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
+ DCHECK(message_loop_->BelongsToCurrentThread());
DCHECK_EQ(state_, STARTED);
VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid;
@@ -103,7 +103,7 @@ void HeartbeatSender::DoSendStanza() {
}
void HeartbeatSender::ProcessResponse(const XmlElement* response) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
+ DCHECK(message_loop_->BelongsToCurrentThread());
std::string type = response->Attr(buzz::QN_TYPE);
if (type == buzz::STR_ERROR) {
diff --git a/remoting/host/heartbeat_sender.h b/remoting/host/heartbeat_sender.h
index d914e55..f30c07a 100644
--- a/remoting/host/heartbeat_sender.h
+++ b/remoting/host/heartbeat_sender.h
@@ -16,6 +16,10 @@
#include "remoting/jingle_glue/iq_request.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
class IqRequest;
@@ -58,7 +62,7 @@ class MutableHostConfig;
// TODO(sergeyu): Is it enough to sign JID and nothing else?
class HeartbeatSender : public HostStatusObserver {
public:
- HeartbeatSender(MessageLoop* main_loop,
+ HeartbeatSender(base::MessageLoopProxy* main_loop,
MutableHostConfig* config);
virtual ~HeartbeatSender();
@@ -99,7 +103,7 @@ class HeartbeatSender : public HostStatusObserver {
buzz::XmlElement* CreateSignature();
State state_;
- MessageLoop* message_loop_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
scoped_refptr<MutableHostConfig> config_;
std::string host_id_;
HostKeyPair key_pair_;
diff --git a/remoting/host/heartbeat_sender_unittest.cc b/remoting/host/heartbeat_sender_unittest.cc
index 617bf03..bf42d25 100644
--- a/remoting/host/heartbeat_sender_unittest.cc
+++ b/remoting/host/heartbeat_sender_unittest.cc
@@ -59,7 +59,8 @@ TEST_F(HeartbeatSenderTest, DoSendStanza) {
EXPECT_CALL(*iq_request, set_callback(_)).Times(1);
scoped_ptr<HeartbeatSender> heartbeat_sender(
- new HeartbeatSender(&message_loop_, config_));
+ new HeartbeatSender(base::MessageLoopProxy::CreateForCurrentThread(),
+ config_));
ASSERT_TRUE(heartbeat_sender->Init());
EXPECT_CALL(signal_strategy_, CreateIqRequest())
@@ -78,7 +79,8 @@ TEST_F(HeartbeatSenderTest, DoSendStanza) {
// Validate format of the heartbeat stanza.
TEST_F(HeartbeatSenderTest, CreateHeartbeatMessage) {
scoped_ptr<HeartbeatSender> heartbeat_sender(
- new HeartbeatSender(&message_loop_, config_));
+ new HeartbeatSender(base::MessageLoopProxy::CreateForCurrentThread(),
+ config_));
ASSERT_TRUE(heartbeat_sender->Init());
int64 start_time = static_cast<int64>(base::Time::Now().ToDoubleT());
@@ -129,7 +131,8 @@ TEST_F(HeartbeatSenderTest, ProcessResponse) {
set_interval->AddText(base::IntToString(kTestInterval));
scoped_ptr<HeartbeatSender> heartbeat_sender(
- new HeartbeatSender(&message_loop_, config_));
+ new HeartbeatSender(base::MessageLoopProxy::CreateForCurrentThread(),
+ config_));
heartbeat_sender->ProcessResponse(response.get());
EXPECT_EQ(kTestInterval * 1000, heartbeat_sender->interval_ms_);
diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h
index ec486c1..5a627ea 100644
--- a/remoting/host/host_mock_objects.h
+++ b/remoting/host/host_mock_objects.h
@@ -83,7 +83,7 @@ class MockChromotingHostContext : public ChromotingHostContext {
MOCK_METHOD0(jingle_thread, JingleThread*());
MOCK_METHOD0(main_message_loop, MessageLoop*());
MOCK_METHOD0(encode_message_loop, MessageLoop*());
- MOCK_METHOD0(network_message_loop, MessageLoop*());
+ MOCK_METHOD0(network_message_loop, base::MessageLoopProxy*());
MOCK_METHOD0(ui_message_loop, MessageLoop*());
private:
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index 2ba2c46..5357cfb 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "base/threading/platform_thread.h"
#include "remoting/base/auth_token_util.h"
#include "remoting/base/util.h"
@@ -318,7 +319,7 @@ void HostNPScriptObject::OnSignallingDisconnected() {
}
void HostNPScriptObject::OnAccessDenied() {
- DCHECK_EQ(MessageLoop::current(), host_context_.network_message_loop());
+ DCHECK(host_context_.network_message_loop()->BelongsToCurrentThread());
++failed_login_attempts_;
if (failed_login_attempts_ == kMaxLoginAttempts)
diff --git a/remoting/host/screen_recorder.cc b/remoting/host/screen_recorder.cc
index 5d3de30..d3f0e49 100644
--- a/remoting/host/screen_recorder.cc
+++ b/remoting/host/screen_recorder.cc
@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop_proxy.h"
#include "base/stl_util.h"
#include "base/task.h"
#include "base/time.h"
@@ -38,7 +39,7 @@ static const int kMaxRecordings = 2;
ScreenRecorder::ScreenRecorder(
MessageLoop* capture_loop,
MessageLoop* encode_loop,
- MessageLoop* network_loop,
+ base::MessageLoopProxy* network_loop,
Capturer* capturer,
Encoder* encoder)
: capture_loop_(capture_loop),
@@ -262,7 +263,7 @@ void ScreenRecorder::DoInvalidateFullScreen() {
// Network thread --------------------------------------------------------------
void ScreenRecorder::DoSendVideoPacket(VideoPacket* packet) {
- DCHECK_EQ(network_loop_, MessageLoop::current());
+ DCHECK(network_loop_->BelongsToCurrentThread());
TraceContext::tracer()->PrintString("DoSendVideoPacket");
@@ -306,14 +307,14 @@ void ScreenRecorder::FrameSentCallback(VideoPacket* packet) {
void ScreenRecorder::DoAddConnection(
scoped_refptr<ConnectionToClient> connection) {
- DCHECK_EQ(network_loop_, MessageLoop::current());
+ DCHECK(network_loop_->BelongsToCurrentThread());
connections_.push_back(connection);
}
void ScreenRecorder::DoRemoveClient(
scoped_refptr<ConnectionToClient> connection) {
- DCHECK_EQ(network_loop_, MessageLoop::current());
+ DCHECK(network_loop_->BelongsToCurrentThread());
ConnectionToClientList::iterator it =
std::find(connections_.begin(), connections_.end(), connection);
@@ -323,14 +324,14 @@ void ScreenRecorder::DoRemoveClient(
}
void ScreenRecorder::DoRemoveAllClients() {
- DCHECK_EQ(network_loop_, MessageLoop::current());
+ DCHECK(network_loop_->BelongsToCurrentThread());
// Clear the list of connections.
connections_.clear();
}
void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) {
- DCHECK_EQ(network_loop_, MessageLoop::current());
+ DCHECK(network_loop_->BelongsToCurrentThread());
// There could be tasks on the network thread when this method is being
// executed. By setting the flag we'll not post anymore tasks from network
diff --git a/remoting/host/screen_recorder.h b/remoting/host/screen_recorder.h
index 64eb1ad..2e341c7 100644
--- a/remoting/host/screen_recorder.h
+++ b/remoting/host/screen_recorder.h
@@ -18,6 +18,10 @@
#include "remoting/host/capturer.h"
#include "remoting/proto/video.pb.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
namespace protocol {
@@ -75,7 +79,7 @@ class ScreenRecorder : public base::RefCountedThreadSafe<ScreenRecorder> {
// This object does not own capturer but owns encoder.
ScreenRecorder(MessageLoop* capture_loop,
MessageLoop* encode_loop,
- MessageLoop* network_loop,
+ base::MessageLoopProxy* network_loop,
Capturer* capturer,
Encoder* encoder);
@@ -159,7 +163,7 @@ class ScreenRecorder : public base::RefCountedThreadSafe<ScreenRecorder> {
// Message loops used by this class.
MessageLoop* capture_loop_;
MessageLoop* encode_loop_;
- MessageLoop* network_loop_;
+ scoped_refptr<base::MessageLoopProxy> network_loop_;
// Reference to the capturer. This member is always accessed on the capture
// thread.
diff --git a/remoting/host/screen_recorder_unittest.cc b/remoting/host/screen_recorder_unittest.cc
index 55a7e45..0af77f1 100644
--- a/remoting/host/screen_recorder_unittest.cc
+++ b/remoting/host/screen_recorder_unittest.cc
@@ -78,11 +78,12 @@ class ScreenRecorderTest : public testing::Test {
// Capturer and Encoder are owned by ScreenRecorder.
encoder_ = new MockEncoder();
- connection_ = new MockConnectionToClient(&message_loop_, &handler_,
- &host_stub_, &event_executor_);
+ connection_ = new MockConnectionToClient(
+ &handler_, &host_stub_, &event_executor_);
record_ = new ScreenRecorder(
- &message_loop_, &message_loop_, &message_loop_,
+ &message_loop_, &message_loop_,
+ base::MessageLoopProxy::CreateForCurrentThread(),
&capturer_, encoder_);
}
diff --git a/remoting/jingle_glue/jingle_thread.cc b/remoting/jingle_glue/jingle_thread.cc
index b0b409a..2dc37ad 100644
--- a/remoting/jingle_glue/jingle_thread.cc
+++ b/remoting/jingle_glue/jingle_thread.cc
@@ -6,6 +6,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/message_loop_proxy.h"
#include "base/message_pump.h"
#include "base/time.h"
#include "third_party/libjingle/source/talk/base/ssladapter.h"
@@ -153,6 +154,7 @@ void JingleThread::Start() {
void JingleThread::Run() {
JingleThreadMessageLoop message_loop(this);
message_loop_ = &message_loop;
+ message_loop_proxy_ = base::MessageLoopProxy::CreateForCurrentThread();
TaskPump task_pump;
task_pump_ = &task_pump;
@@ -180,6 +182,10 @@ MessageLoop* JingleThread::message_loop() {
return message_loop_;
}
+base::MessageLoopProxy* JingleThread::message_loop_proxy() {
+ return message_loop_proxy_;
+}
+
TaskPump* JingleThread::task_pump() {
return task_pump_;
}
diff --git a/remoting/jingle_glue/jingle_thread.h b/remoting/jingle_glue/jingle_thread.h
index 35b46f2..80924a21 100644
--- a/remoting/jingle_glue/jingle_thread.h
+++ b/remoting/jingle_glue/jingle_thread.h
@@ -12,9 +12,13 @@
#include "third_party/libjingle/source/talk/base/taskrunner.h"
#include "third_party/libjingle/source/talk/base/thread.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace buzz {
class XmppClient;
-}
+} // namespace buzz
namespace remoting {
@@ -56,9 +60,8 @@ class JingleThread : public talk_base::Thread {
virtual void Stop();
// Returns Chromiums message loop for this thread.
- // TODO(sergeyu): remove this method when we use base::Thread instead of
- // talk_base::Thread
MessageLoop* message_loop();
+ base::MessageLoopProxy* message_loop_proxy();
// Returns task pump if the thread is running, otherwise NULL is returned.
TaskPump* task_pump();
@@ -68,6 +71,7 @@ class JingleThread : public talk_base::Thread {
base::WaitableEvent started_event_;
base::WaitableEvent stopped_event_;
MessageLoop* message_loop_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
DISALLOW_COPY_AND_ASSIGN(JingleThread);
};
diff --git a/remoting/protocol/buffered_socket_writer.cc b/remoting/protocol/buffered_socket_writer.cc
index 415d09e..d993a37 100644
--- a/remoting/protocol/buffered_socket_writer.cc
+++ b/remoting/protocol/buffered_socket_writer.cc
@@ -4,7 +4,7 @@
#include "remoting/protocol/buffered_socket_writer.h"
-#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "base/stl_util.h"
#include "net/base/net_errors.h"
@@ -33,10 +33,11 @@ class BufferedSocketWriterBase::PendingPacket {
DISALLOW_COPY_AND_ASSIGN(PendingPacket);
};
-BufferedSocketWriterBase::BufferedSocketWriterBase()
+BufferedSocketWriterBase::BufferedSocketWriterBase(
+ base::MessageLoopProxy* message_loop)
: buffer_size_(0),
socket_(NULL),
- message_loop_(NULL),
+ message_loop_(message_loop),
write_pending_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(
written_callback_(this, &BufferedSocketWriterBase::OnWritten)),
@@ -49,7 +50,6 @@ void BufferedSocketWriterBase::Init(net::Socket* socket,
WriteFailedCallback* callback) {
// TODO(garykac) Save copy of WriteFailedCallback.
base::AutoLock auto_lock(lock_);
- message_loop_ = MessageLoop::current();
socket_ = socket;
DCHECK(socket_);
}
@@ -67,7 +67,7 @@ bool BufferedSocketWriterBase::Write(
}
void BufferedSocketWriterBase::DoWrite() {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
DCHECK(socket_);
// Don't try to write if there is another write pending.
@@ -109,7 +109,7 @@ void BufferedSocketWriterBase::DoWrite() {
}
void BufferedSocketWriterBase::OnWritten(int result) {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
write_pending_ = false;
if (result < 0) {
@@ -130,7 +130,7 @@ void BufferedSocketWriterBase::OnWritten(int result) {
}
void BufferedSocketWriterBase::HandleError(int result) {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
closed_ = true;
@@ -152,7 +152,7 @@ int BufferedSocketWriterBase::GetBufferChunks() {
}
void BufferedSocketWriterBase::Close() {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
closed_ = true;
}
@@ -162,7 +162,10 @@ void BufferedSocketWriterBase::PopQueue() {
queue_.pop_front();
}
-BufferedSocketWriter::BufferedSocketWriter() { }
+BufferedSocketWriter::BufferedSocketWriter(
+ base::MessageLoopProxy* message_loop)
+ : BufferedSocketWriterBase(message_loop) {
+}
BufferedSocketWriter::~BufferedSocketWriter() {
STLDeleteElements(&queue_);
@@ -197,7 +200,10 @@ void BufferedSocketWriter::OnError_Locked(int result) {
current_buf_ = NULL;
}
-BufferedDatagramWriter::BufferedDatagramWriter() { }
+BufferedDatagramWriter::BufferedDatagramWriter(
+ base::MessageLoopProxy* message_loop)
+ : BufferedSocketWriterBase(message_loop) {
+}
BufferedDatagramWriter::~BufferedDatagramWriter() { }
void BufferedDatagramWriter::GetNextPacket_Locked(
diff --git a/remoting/protocol/buffered_socket_writer.h b/remoting/protocol/buffered_socket_writer.h
index 3bb03d3..424c4dc 100644
--- a/remoting/protocol/buffered_socket_writer.h
+++ b/remoting/protocol/buffered_socket_writer.h
@@ -12,9 +12,12 @@
#include "net/base/io_buffer.h"
#include "net/socket/socket.h"
-class MessageLoop;
class Task;
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace net {
class Socket;
} // namespace net
@@ -36,7 +39,7 @@ class BufferedSocketWriterBase
public:
typedef Callback1<int>::Type WriteFailedCallback;
- explicit BufferedSocketWriterBase();
+ explicit BufferedSocketWriterBase(base::MessageLoopProxy* message_loop);
virtual ~BufferedSocketWriterBase();
// Initializes the writer. Must be called on the thread that will be used
@@ -91,7 +94,7 @@ class BufferedSocketWriterBase
base::Lock lock_;
net::Socket* socket_;
- MessageLoop* message_loop_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
scoped_ptr<WriteFailedCallback> write_failed_callback_;
bool write_pending_;
@@ -103,7 +106,7 @@ class BufferedSocketWriterBase
class BufferedSocketWriter : public BufferedSocketWriterBase {
public:
- BufferedSocketWriter();
+ BufferedSocketWriter(base::MessageLoopProxy* message_loop);
virtual ~BufferedSocketWriter();
protected:
@@ -117,7 +120,7 @@ class BufferedSocketWriter : public BufferedSocketWriterBase {
class BufferedDatagramWriter : public BufferedSocketWriterBase {
public:
- BufferedDatagramWriter();
+ BufferedDatagramWriter(base::MessageLoopProxy* message_loop);
virtual ~BufferedDatagramWriter();
protected:
diff --git a/remoting/protocol/client_control_sender.cc b/remoting/protocol/client_control_sender.cc
index c9d2d6f..aa7549a 100644
--- a/remoting/protocol/client_control_sender.cc
+++ b/remoting/protocol/client_control_sender.cc
@@ -16,8 +16,9 @@
namespace remoting {
namespace protocol {
-ClientControlSender::ClientControlSender(net::Socket* socket)
- : buffered_writer_(new BufferedSocketWriter()) {
+ClientControlSender::ClientControlSender(base::MessageLoopProxy* message_loop,
+ net::Socket* socket)
+ : buffered_writer_(new BufferedSocketWriter(message_loop)) {
buffered_writer_->Init(socket, NULL);
}
diff --git a/remoting/protocol/client_control_sender.h b/remoting/protocol/client_control_sender.h
index e53ef2c..47911d5 100644
--- a/remoting/protocol/client_control_sender.h
+++ b/remoting/protocol/client_control_sender.h
@@ -19,6 +19,10 @@
class Task;
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace net {
class Socket;
} // namespace net
@@ -33,7 +37,8 @@ class BufferedSocketWriter;
// other thread.
class ClientControlSender : public ClientStub {
public:
- explicit ClientControlSender(net::Socket* socket);
+ explicit ClientControlSender(base::MessageLoopProxy* message_loop,
+ net::Socket* socket);
virtual ~ClientControlSender();
virtual void BeginSessionResponse(const LocalLoginStatus* msg,
diff --git a/remoting/protocol/connection_to_client.cc b/remoting/protocol/connection_to_client.cc
index 4330984..f0cbc6a 100644
--- a/remoting/protocol/connection_to_client.cc
+++ b/remoting/protocol/connection_to_client.cc
@@ -5,6 +5,7 @@
#include "remoting/protocol/connection_to_client.h"
#include "base/bind.h"
+#include "base/message_loop_proxy.h"
#include "google/protobuf/message.h"
#include "net/base/io_buffer.h"
#include "remoting/protocol/client_control_sender.h"
@@ -22,16 +23,16 @@ namespace protocol {
// average update stream.
static const size_t kAverageUpdateStream = 10;
-ConnectionToClient::ConnectionToClient(MessageLoop* message_loop,
+ConnectionToClient::ConnectionToClient(base::MessageLoopProxy* message_loop,
EventHandler* handler)
- : loop_(message_loop),
+ : message_loop_(message_loop),
handler_(handler),
host_stub_(NULL),
input_stub_(NULL),
control_connected_(false),
input_connected_(false),
video_connected_(false) {
- DCHECK(loop_);
+ DCHECK(message_loop_);
DCHECK(handler_);
}
@@ -41,7 +42,7 @@ ConnectionToClient::~ConnectionToClient() {
}
void ConnectionToClient::Init(protocol::Session* session) {
- DCHECK_EQ(loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
session_.reset(session);
session_->SetStateChangeCallback(
NewCallback(this, &ConnectionToClient::OnSessionStateChange));
@@ -53,8 +54,8 @@ protocol::Session* ConnectionToClient::session() {
void ConnectionToClient::Disconnect() {
// This method can be called from main thread so perform threading switching.
- if (MessageLoop::current() != loop_) {
- loop_->PostTask(
+ if (!message_loop_->BelongsToCurrentThread()) {
+ message_loop_->PostTask(
FROM_HERE,
NewRunnableMethod(this, &ConnectionToClient::Disconnect));
return;
@@ -89,7 +90,7 @@ void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) {
}
void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) {
- DCHECK_EQ(loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
DCHECK(handler_);
switch(state) {
@@ -98,7 +99,8 @@ void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) {
break;
case protocol::Session::CONNECTED:
- video_writer_.reset(VideoWriter::Create(session_->config()));
+ video_writer_.reset(
+ VideoWriter::Create(message_loop_, session_->config()));
video_writer_->Init(
session_.get(), base::Bind(&ConnectionToClient::OnVideoInitialized,
base::Unretained(this)));
@@ -106,7 +108,7 @@ void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) {
case protocol::Session::CONNECTED_CHANNELS:
client_control_sender_.reset(
- new ClientControlSender(session_->control_channel()));
+ new ClientControlSender(message_loop_, session_->control_channel()));
dispatcher_.reset(new HostMessageDispatcher());
dispatcher_->Initialize(this, host_stub_, input_stub_);
diff --git a/remoting/protocol/connection_to_client.h b/remoting/protocol/connection_to_client.h
index 76e95de..fc892d0 100644
--- a/remoting/protocol/connection_to_client.h
+++ b/remoting/protocol/connection_to_client.h
@@ -10,11 +10,14 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop.h"
#include "base/synchronization/lock.h"
#include "remoting/protocol/session.h"
#include "remoting/protocol/video_writer.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
namespace protocol {
@@ -54,7 +57,7 @@ class ConnectionToClient :
// that this object runs on. A viewer object receives events and messages from
// a libjingle channel, these events are delegated to |handler|.
// It is guaranteed that |handler| is called only on the |message_loop|.
- ConnectionToClient(MessageLoop* message_loop,
+ ConnectionToClient(base::MessageLoopProxy* message_loop,
EventHandler* handler);
virtual void Init(Session* session);
@@ -101,7 +104,7 @@ class ConnectionToClient :
void CloseChannels();
// The message loop that this object runs on.
- MessageLoop* loop_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
// Event handler for handling events sent from this object.
EventHandler* handler_;
diff --git a/remoting/protocol/connection_to_client_unittest.cc b/remoting/protocol/connection_to_client_unittest.cc
index 9c2b6af..f6c9321 100644
--- a/remoting/protocol/connection_to_client_unittest.cc
+++ b/remoting/protocol/connection_to_client_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "remoting/base/base_mock_objects.h"
#include "remoting/base/constants.h"
#include "remoting/protocol/fake_session.h"
@@ -28,7 +29,8 @@ class ConnectionToClientTest : public testing::Test {
session_->set_message_loop(&message_loop_);
// Allocate a ClientConnection object with the mock objects.
- viewer_ = new ConnectionToClient(&message_loop_, &handler_);
+ viewer_ = new ConnectionToClient(
+ base::MessageLoopProxy::CreateForCurrentThread(), &handler_);
viewer_->set_host_stub(&host_stub_);
viewer_->set_input_stub(&input_stub_);
viewer_->Init(session_);
diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc
index 91384da..3b82499 100644
--- a/remoting/protocol/connection_to_host.cc
+++ b/remoting/protocol/connection_to_host.cc
@@ -6,7 +6,7 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "remoting/base/constants.h"
#include "remoting/jingle_glue/host_resolver.h"
#include "remoting/jingle_glue/http_port_allocator.h"
@@ -26,7 +26,7 @@ namespace remoting {
namespace protocol {
ConnectionToHost::ConnectionToHost(
- MessageLoop* message_loop,
+ base::MessageLoopProxy* message_loop,
talk_base::NetworkManager* network_manager,
talk_base::PacketSocketFactory* socket_factory,
HostResolverFactory* host_resolver_factory,
@@ -84,7 +84,7 @@ void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy,
}
void ConnectionToHost::Disconnect(const base::Closure& shutdown_task) {
- if (MessageLoop::current() != message_loop_) {
+ if (!message_loop_->BelongsToCurrentThread()) {
message_loop_->PostTask(
FROM_HERE, base::Bind(&ConnectionToHost::Disconnect,
base::Unretained(this), shutdown_task));
@@ -106,12 +106,12 @@ void ConnectionToHost::Disconnect(const base::Closure& shutdown_task) {
}
void ConnectionToHost::InitSession() {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
// Initialize chromotocol |session_manager_|.
JingleSessionManager* session_manager =
JingleSessionManager::CreateSandboxed(
- network_manager_.release(), socket_factory_.release(),
+ message_loop_, network_manager_.release(), socket_factory_.release(),
host_resolver_factory_.release(),
port_allocator_session_factory_.release());
@@ -129,7 +129,7 @@ const SessionConfig* ConnectionToHost::config() {
void ConnectionToHost::OnStateChange(
SignalStrategy::StatusObserver::State state) {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
DCHECK(event_callback_);
if (state == SignalStrategy::StatusObserver::CONNECTED) {
@@ -142,12 +142,12 @@ void ConnectionToHost::OnStateChange(
}
void ConnectionToHost::OnJidChange(const std::string& full_jid) {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
local_jid_ = full_jid;
}
void ConnectionToHost::OnSessionManagerInitialized() {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
// After SessionManager is initialized we can try to connect to the host.
CandidateSessionConfig* candidate_config =
@@ -165,14 +165,14 @@ void ConnectionToHost::OnSessionManagerInitialized() {
void ConnectionToHost::OnIncomingSession(
Session* session,
SessionManager::IncomingSessionResponse* response) {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
// Client always rejects incoming sessions.
*response = SessionManager::DECLINE;
}
void ConnectionToHost::OnSessionStateChange(
Session::State state) {
- DCHECK_EQ(message_loop_, MessageLoop::current());
+ DCHECK(message_loop_->BelongsToCurrentThread());
DCHECK(event_callback_);
switch (state) {
@@ -189,7 +189,8 @@ void ConnectionToHost::OnSessionStateChange(
case Session::CONNECTED:
// Initialize reader and writer.
- video_reader_.reset(VideoReader::Create(session_->config()));
+ video_reader_.reset(
+ VideoReader::Create(message_loop_, session_->config()));
video_reader_->Init(
session_.get(), video_stub_,
base::Bind(&ConnectionToHost::OnVideoChannelInitialized,
@@ -199,7 +200,7 @@ void ConnectionToHost::OnSessionStateChange(
case Session::CONNECTED_CHANNELS:
state_ = STATE_CONNECTED;
host_control_sender_.reset(
- new HostControlSender(session_->control_channel()));
+ new HostControlSender(message_loop_, session_->control_channel()));
dispatcher_.reset(new ClientMessageDispatcher());
dispatcher_->Initialize(session_.get(), client_stub_);
@@ -252,7 +253,8 @@ void ConnectionToHost::OnClientAuthenticated() {
state_ = STATE_AUTHENTICATED;
// Create and enable the input stub now that we're authenticated.
- input_sender_.reset(new InputSender(session_->event_channel()));
+ input_sender_.reset(
+ new InputSender(message_loop_, session_->event_channel()));
}
ConnectionToHost::State ConnectionToHost::state() const {
diff --git a/remoting/protocol/connection_to_host.h b/remoting/protocol/connection_to_host.h
index ec8ceb6..ada717b 100644
--- a/remoting/protocol/connection_to_host.h
+++ b/remoting/protocol/connection_to_host.h
@@ -17,7 +17,9 @@
#include "remoting/protocol/session.h"
#include "remoting/protocol/session_manager.h"
-class MessageLoop;
+namespace base {
+class MessageLoopProxy;
+} // namespace base
namespace talk_base {
class NetworkManager;
@@ -74,7 +76,7 @@ class ConnectionToHost : public SignalStrategy::StatusObserver,
// |network_manager| and |socket_factory| may be set to NULL.
//
// TODO(sergeyu): Constructor shouldn't need thread here.
- ConnectionToHost(MessageLoop* network_message_loop,
+ ConnectionToHost(base::MessageLoopProxy* network_message_loop,
talk_base::NetworkManager* network_manager,
talk_base::PacketSocketFactory* socket_factory,
HostResolverFactory* host_resolver_factory,
@@ -137,7 +139,7 @@ class ConnectionToHost : public SignalStrategy::StatusObserver,
// Stops writing in the channels.
void CloseChannels();
- MessageLoop* message_loop_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
scoped_ptr<talk_base::NetworkManager> network_manager_;
scoped_ptr<talk_base::PacketSocketFactory> socket_factory_;
scoped_ptr<HostResolverFactory> host_resolver_factory_;
diff --git a/remoting/protocol/fake_session.h b/remoting/protocol/fake_session.h
index f0d5828..e89a208 100644
--- a/remoting/protocol/fake_session.h
+++ b/remoting/protocol/fake_session.h
@@ -14,6 +14,8 @@
#include "net/socket/stream_socket.h"
#include "remoting/protocol/session.h"
+class MessageLoop;
+
namespace remoting {
namespace protocol {
diff --git a/remoting/protocol/host_control_sender.cc b/remoting/protocol/host_control_sender.cc
index 6acc940..6e71341 100644
--- a/remoting/protocol/host_control_sender.cc
+++ b/remoting/protocol/host_control_sender.cc
@@ -16,8 +16,9 @@
namespace remoting {
namespace protocol {
-HostControlSender::HostControlSender(net::Socket* socket)
- : buffered_writer_(new BufferedSocketWriter()) {
+HostControlSender::HostControlSender(base::MessageLoopProxy* message_loop,
+ net::Socket* socket)
+ : buffered_writer_(new BufferedSocketWriter(message_loop)) {
buffered_writer_->Init(socket, NULL);
}
diff --git a/remoting/protocol/host_control_sender.h b/remoting/protocol/host_control_sender.h
index b1b88de..c1425da 100644
--- a/remoting/protocol/host_control_sender.h
+++ b/remoting/protocol/host_control_sender.h
@@ -18,6 +18,10 @@
class Task;
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace net {
class Socket;
} // namespace net
@@ -32,7 +36,8 @@ class BufferedSocketWriter;
// other thread.
class HostControlSender : public HostStub {
public:
- explicit HostControlSender(net::Socket* socket);
+ explicit HostControlSender(base::MessageLoopProxy* message_loop,
+ net::Socket* socket);
virtual ~HostControlSender();
virtual void BeginSessionRequest(
diff --git a/remoting/protocol/host_message_dispatcher.h b/remoting/protocol/host_message_dispatcher.h
index 67df286..2a55474 100644
--- a/remoting/protocol/host_message_dispatcher.h
+++ b/remoting/protocol/host_message_dispatcher.h
@@ -10,6 +10,10 @@
#include "base/task.h"
#include "remoting/protocol/message_reader.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
namespace protocol {
diff --git a/remoting/protocol/input_sender.cc b/remoting/protocol/input_sender.cc
index dbe4d26..fb4102c 100644
--- a/remoting/protocol/input_sender.cc
+++ b/remoting/protocol/input_sender.cc
@@ -16,8 +16,9 @@
namespace remoting {
namespace protocol {
-InputSender::InputSender(net::Socket* socket)
- : buffered_writer_(new BufferedSocketWriter()) {
+InputSender::InputSender(base::MessageLoopProxy* message_loop,
+ net::Socket* socket)
+ : buffered_writer_(new BufferedSocketWriter(message_loop)) {
// TODO(garykac) Set write failed callback.
DCHECK(socket);
buffered_writer_->Init(socket, NULL);
diff --git a/remoting/protocol/input_sender.h b/remoting/protocol/input_sender.h
index 5abcb33..464237f 100644
--- a/remoting/protocol/input_sender.h
+++ b/remoting/protocol/input_sender.h
@@ -19,6 +19,10 @@
class Task;
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace net {
class Socket;
} // namespace net
@@ -34,7 +38,8 @@ class BufferedSocketWriter;
class InputSender : public InputStub {
public:
// Create a stub using a socket.
- explicit InputSender(net::Socket* socket);
+ explicit InputSender(base::MessageLoopProxy* message_loop,
+ net::Socket* socket);
virtual ~InputSender();
// InputStub implementation.
diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc
index 3354ae0..ae0539a 100644
--- a/remoting/protocol/jingle_session.cc
+++ b/remoting/protocol/jingle_session.cc
@@ -5,7 +5,7 @@
#include "remoting/protocol/jingle_session.h"
#include "base/bind.h"
-#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "base/rand_util.h"
#include "base/stl_util.h"
#include "crypto/hmac.h"
@@ -317,11 +317,11 @@ void JingleSession::OnInitiate() {
// P2PTransportChannel is created only after we return from this
// method.
// TODO(sergeyu): Add set_incoming_only() in TransportChannelProxy.
- MessageLoop::current()->PostTask(
+ jingle_session_manager_->message_loop_->PostTask(
FROM_HERE, task_factory_.NewRunnableMethod(
&JingleSession::SetState, CONNECTING));
} else {
- MessageLoop::current()->PostTask(
+ jingle_session_manager_->message_loop_->PostTask(
FROM_HERE, task_factory_.NewRunnableMethod(
&JingleSession::AcceptConnection));
}
diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc
index c4ff55a..1dae59d 100644
--- a/remoting/protocol/jingle_session_manager.cc
+++ b/remoting/protocol/jingle_session_manager.cc
@@ -7,7 +7,7 @@
#include <limits>
#include "base/bind.h"
-#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "base/string_util.h"
#include "base/task.h"
#include "remoting/base/constants.h"
@@ -29,27 +29,31 @@ namespace remoting {
namespace protocol {
// static
-JingleSessionManager* JingleSessionManager::CreateNotSandboxed() {
- return new JingleSessionManager(NULL, NULL, NULL, NULL);
+JingleSessionManager* JingleSessionManager::CreateNotSandboxed(
+ base::MessageLoopProxy* message_loop) {
+ return new JingleSessionManager(message_loop, NULL, NULL, NULL, NULL);
}
// static
JingleSessionManager* JingleSessionManager::CreateSandboxed(
+ base::MessageLoopProxy* message_loop,
talk_base::NetworkManager* network_manager,
talk_base::PacketSocketFactory* socket_factory,
HostResolverFactory* host_resolver_factory,
PortAllocatorSessionFactory* port_allocator_session_factory) {
- return new JingleSessionManager(network_manager, socket_factory,
+ return new JingleSessionManager(message_loop, network_manager, socket_factory,
host_resolver_factory,
port_allocator_session_factory);
}
JingleSessionManager::JingleSessionManager(
+ base::MessageLoopProxy* message_loop,
talk_base::NetworkManager* network_manager,
talk_base::PacketSocketFactory* socket_factory,
HostResolverFactory* host_resolver_factory,
PortAllocatorSessionFactory* port_allocator_session_factory)
- : network_manager_(network_manager),
+ : message_loop_(message_loop),
+ network_manager_(network_manager),
socket_factory_(socket_factory),
host_resolver_factory_(host_resolver_factory),
port_allocator_session_factory_(port_allocator_session_factory),
diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h
index 809a3e1..35ad26d 100644
--- a/remoting/protocol/jingle_session_manager.h
+++ b/remoting/protocol/jingle_session_manager.h
@@ -39,8 +39,10 @@ class JingleSessionManager
public:
virtual ~JingleSessionManager();
- static JingleSessionManager* CreateNotSandboxed();
+ static JingleSessionManager* CreateNotSandboxed(
+ base::MessageLoopProxy* message_loop);
static JingleSessionManager* CreateSandboxed(
+ base::MessageLoopProxy* message_loop,
talk_base::NetworkManager* network_manager,
talk_base::PacketSocketFactory* socket_factory,
HostResolverFactory* host_resolver_factory,
@@ -81,6 +83,7 @@ class JingleSessionManager
friend class JingleSession;
JingleSessionManager(
+ base::MessageLoopProxy* message_loop,
talk_base::NetworkManager* network_manager,
talk_base::PacketSocketFactory* socket_factory,
HostResolverFactory* host_resolver_factory,
@@ -109,6 +112,8 @@ class JingleSessionManager
const CandidateSessionConfig* candidate_config,
const std::string& certificate);
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
+
scoped_ptr<talk_base::NetworkManager> network_manager_;
scoped_ptr<talk_base::PacketSocketFactory> socket_factory_;
scoped_ptr<HostResolverFactory> host_resolver_factory_;
diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc
index aab1df8..074e7c60 100644
--- a/remoting/protocol/jingle_session_unittest.cc
+++ b/remoting/protocol/jingle_session_unittest.cc
@@ -5,6 +5,7 @@
#include "base/bind.h"
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/message_loop_proxy.h"
#include "base/path_service.h"
#include "base/time.h"
#include "base/test/test_timeouts.h"
@@ -176,7 +177,8 @@ class JingleSessionTest : public testing::Test {
EXPECT_CALL(host_server_listener_, OnSessionManagerInitialized())
.Times(1);
- host_server_.reset(JingleSessionManager::CreateNotSandboxed());
+ host_server_.reset(JingleSessionManager::CreateNotSandboxed(
+ base::MessageLoopProxy::CreateForCurrentThread()));
host_server_->set_allow_local_ips(true);
host_server_->Init(
kHostJid, host_signal_strategy_.get(), &host_server_listener_,
@@ -184,7 +186,8 @@ class JingleSessionTest : public testing::Test {
EXPECT_CALL(client_server_listener_, OnSessionManagerInitialized())
.Times(1);
- client_server_.reset(JingleSessionManager::CreateNotSandboxed());
+ client_server_.reset(JingleSessionManager::CreateNotSandboxed(
+ base::MessageLoopProxy::CreateForCurrentThread()));
client_server_->set_allow_local_ips(true);
client_server_->Init(
kClientJid, client_signal_strategy_.get(), &client_server_listener_,
diff --git a/remoting/protocol/message_reader.cc b/remoting/protocol/message_reader.cc
index d8324be..e5825b1 100644
--- a/remoting/protocol/message_reader.cc
+++ b/remoting/protocol/message_reader.cc
@@ -4,7 +4,6 @@
#include "remoting/protocol/message_reader.h"
-#include "base/message_loop.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/socket/socket.h"
@@ -18,7 +17,6 @@ static const int kReadBufferSize = 4096;
MessageReader::MessageReader()
: socket_(NULL),
- message_loop_(NULL),
read_pending_(false),
pending_messages_(0),
closed_(false),
@@ -35,7 +33,6 @@ void MessageReader::Init(net::Socket* socket,
message_received_callback_.reset(callback);
DCHECK(socket);
socket_ = socket;
- message_loop_ = MessageLoop::current();
DoRead();
}
@@ -105,12 +102,6 @@ void MessageReader::OnMessageDone(CompoundBuffer* message) {
}
void MessageReader::ProcessDoneEvent() {
- if (MessageLoop::current() != message_loop_) {
- message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &MessageReader::ProcessDoneEvent));
- return;
- }
-
pending_messages_--;
DCHECK_GE(pending_messages_, 0);
diff --git a/remoting/protocol/message_reader.h b/remoting/protocol/message_reader.h
index 984cc1a..bf8aae4 100644
--- a/remoting/protocol/message_reader.h
+++ b/remoting/protocol/message_reader.h
@@ -59,9 +59,6 @@ class MessageReader : public base::RefCountedThreadSafe<MessageReader> {
net::Socket* socket_;
- // The network message loop this object runs on.
- MessageLoop* message_loop_;
-
// Set to true, when we have a socket read pending, and expecting
// OnRead() to be called when new data is received.
bool read_pending_;
diff --git a/remoting/protocol/message_reader_unittest.cc b/remoting/protocol/message_reader_unittest.cc
index 3237cb5..84e2e31 100644
--- a/remoting/protocol/message_reader_unittest.cc
+++ b/remoting/protocol/message_reader_unittest.cc
@@ -4,7 +4,6 @@
#include <string>
-#include "base/message_loop.h"
#include "net/socket/socket.h"
#include "remoting/protocol/fake_session.h"
#include "remoting/protocol/message_reader.h"
@@ -64,9 +63,6 @@ class MessageReaderTest : public testing::Test {
delete task;
}
- // MessageLoop must be first here, so that is is destroyed the last.
- MessageLoop message_loop_;
-
scoped_refptr<MessageReader> reader_;
FakeSocket socket_;
MockMessageReceivedCallback callback_;
diff --git a/remoting/protocol/protobuf_video_writer.cc b/remoting/protocol/protobuf_video_writer.cc
index 0b1705a..cb4399b 100644
--- a/remoting/protocol/protobuf_video_writer.cc
+++ b/remoting/protocol/protobuf_video_writer.cc
@@ -16,7 +16,9 @@
namespace remoting {
namespace protocol {
-ProtobufVideoWriter::ProtobufVideoWriter() { }
+ProtobufVideoWriter::ProtobufVideoWriter(base::MessageLoopProxy* message_loop)
+ : buffered_writer_(new BufferedSocketWriter(message_loop)) {
+}
ProtobufVideoWriter::~ProtobufVideoWriter() { }
@@ -37,7 +39,6 @@ void ProtobufVideoWriter::OnChannelReady(net::StreamSocket* socket) {
DCHECK(!channel_.get());
channel_.reset(socket);
- buffered_writer_ = new BufferedSocketWriter();
// TODO(sergeyu): Provide WriteFailedCallback for the buffered writer.
buffered_writer_->Init(socket, NULL);
diff --git a/remoting/protocol/protobuf_video_writer.h b/remoting/protocol/protobuf_video_writer.h
index 5c69c61..587ceab 100644
--- a/remoting/protocol/protobuf_video_writer.h
+++ b/remoting/protocol/protobuf_video_writer.h
@@ -12,6 +12,10 @@
#include "base/memory/scoped_ptr.h"
#include "remoting/protocol/video_writer.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace net {
class StreamSocket;
} // namespace net
@@ -24,7 +28,7 @@ class Session;
class ProtobufVideoWriter : public VideoWriter {
public:
- ProtobufVideoWriter();
+ ProtobufVideoWriter(base::MessageLoopProxy* message_loop);
virtual ~ProtobufVideoWriter();
// VideoWriter interface.
diff --git a/remoting/protocol/protocol_mock_objects.cc b/remoting/protocol/protocol_mock_objects.cc
index 316dd01..34766c3 100644
--- a/remoting/protocol/protocol_mock_objects.cc
+++ b/remoting/protocol/protocol_mock_objects.cc
@@ -4,14 +4,17 @@
#include "remoting/protocol/protocol_mock_objects.h"
+#include "base/message_loop_proxy.h"
+
namespace remoting {
namespace protocol {
-MockConnectionToClient::MockConnectionToClient(MessageLoop* message_loop,
- EventHandler* handler,
- HostStub* host_stub,
- InputStub* input_stub)
- : ConnectionToClient(message_loop, handler) {
+MockConnectionToClient::MockConnectionToClient(
+ EventHandler* handler,
+ HostStub* host_stub,
+ InputStub* input_stub)
+ : ConnectionToClient(base::MessageLoopProxy::CreateForCurrentThread(),
+ handler) {
set_host_stub(host_stub);
set_input_stub(input_stub);
}
diff --git a/remoting/protocol/protocol_mock_objects.h b/remoting/protocol/protocol_mock_objects.h
index 716a3b4..948fdec 100644
--- a/remoting/protocol/protocol_mock_objects.h
+++ b/remoting/protocol/protocol_mock_objects.h
@@ -21,8 +21,7 @@ class ChromotocolConnection;
class MockConnectionToClient : public ConnectionToClient {
public:
- MockConnectionToClient(MessageLoop* message_loop,
- EventHandler* handler,
+ MockConnectionToClient(EventHandler* handler,
HostStub* host_stub,
InputStub* input_stub);
virtual ~MockConnectionToClient();
@@ -120,7 +119,6 @@ class MockSession : public Session {
MOCK_METHOD0(video_rtp_channel, net::Socket*());
MOCK_METHOD0(video_rtcp_channel, net::Socket*());
MOCK_METHOD0(jid, const std::string&());
- MOCK_METHOD0(message_loop, MessageLoop*());
MOCK_METHOD0(candidate_config, const CandidateSessionConfig*());
MOCK_METHOD0(config, const SessionConfig*());
MOCK_METHOD1(set_config, void(const SessionConfig* config));
diff --git a/remoting/protocol/protocol_test_client.cc b/remoting/protocol/protocol_test_client.cc
index f9b0010..b9d8d0a 100644
--- a/remoting/protocol/protocol_test_client.cc
+++ b/remoting/protocol/protocol_test_client.cc
@@ -16,6 +16,7 @@ extern "C" {
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/command_line.h"
+#include "base/message_loop_proxy.h"
#include "base/test/mock_chrome_application_mac.h"
#include "base/time.h"
#include "crypto/nss_util.h"
@@ -222,7 +223,8 @@ void ProtocolTestClient::Run(const std::string& username,
new XmppSignalStrategy(&jingle_thread, username, auth_token,
auth_service));
signal_strategy_->Init(this);
- session_manager_.reset(JingleSessionManager::CreateNotSandboxed());
+ session_manager_.reset(JingleSessionManager::CreateNotSandboxed(
+ jingle_thread.message_loop_proxy()));
host_jid_ = host_jid;
diff --git a/remoting/protocol/rtcp_writer.cc b/remoting/protocol/rtcp_writer.cc
index 5ccf748..f8b8b76 100644
--- a/remoting/protocol/rtcp_writer.cc
+++ b/remoting/protocol/rtcp_writer.cc
@@ -13,7 +13,8 @@
namespace remoting {
namespace protocol {
-RtcpWriter::RtcpWriter() {
+RtcpWriter::RtcpWriter(base::MessageLoopProxy* message_loop)
+ : buffered_rtcp_writer_(new BufferedDatagramWriter(message_loop)) {
}
RtcpWriter::~RtcpWriter() {
@@ -26,7 +27,6 @@ void RtcpWriter::Close() {
// Initializes the writer. Must be called on the thread the sockets
// belong to.
void RtcpWriter::Init(net::Socket* socket) {
- buffered_rtcp_writer_ = new BufferedDatagramWriter();
buffered_rtcp_writer_->Init(socket, NULL);
}
diff --git a/remoting/protocol/rtcp_writer.h b/remoting/protocol/rtcp_writer.h
index e4a7226..7ae49dd 100644
--- a/remoting/protocol/rtcp_writer.h
+++ b/remoting/protocol/rtcp_writer.h
@@ -7,6 +7,10 @@
#include "net/socket/socket.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
class CompoundBuffer;
@@ -18,7 +22,7 @@ struct RtcpReceiverReport;
class RtcpWriter {
public:
- RtcpWriter();
+ RtcpWriter(base::MessageLoopProxy* message_loop);
virtual ~RtcpWriter();
// Initializes the writer. Must be called on the thread the socket
diff --git a/remoting/protocol/rtp_video_reader.cc b/remoting/protocol/rtp_video_reader.cc
index 19bf2fb..28babd8 100644
--- a/remoting/protocol/rtp_video_reader.cc
+++ b/remoting/protocol/rtp_video_reader.cc
@@ -23,8 +23,9 @@ RtpVideoReader::PacketsQueueEntry::PacketsQueueEntry()
packet(NULL) {
}
-RtpVideoReader::RtpVideoReader()
+RtpVideoReader::RtpVideoReader(base::MessageLoopProxy* message_loop)
: initialized_(false),
+ rtcp_writer_(message_loop),
last_sequence_number_(0),
video_stub_(NULL) {
}
diff --git a/remoting/protocol/rtp_video_reader.h b/remoting/protocol/rtp_video_reader.h
index e87f677..160bbad 100644
--- a/remoting/protocol/rtp_video_reader.h
+++ b/remoting/protocol/rtp_video_reader.h
@@ -12,6 +12,10 @@
#include "remoting/protocol/rtp_reader.h"
#include "remoting/protocol/video_reader.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
namespace protocol {
@@ -21,7 +25,7 @@ class Session;
class RtpVideoReader : public VideoReader {
public:
- RtpVideoReader();
+ RtpVideoReader(base::MessageLoopProxy* message_loop);
virtual ~RtpVideoReader();
// VideoReader interface.
diff --git a/remoting/protocol/rtp_video_reader_unittest.cc b/remoting/protocol/rtp_video_reader_unittest.cc
index 3c6d5ef..da5b5ca 100644
--- a/remoting/protocol/rtp_video_reader_unittest.cc
+++ b/remoting/protocol/rtp_video_reader_unittest.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "base/string_number_conversions.h"
#include "net/base/io_buffer.h"
#include "remoting/proto/video.pb.h"
@@ -65,7 +66,8 @@ class RtpVideoReaderTest : public testing::Test,
void Reset() {
session_.reset(new FakeSession());
- reader_.reset(new RtpVideoReader());
+ reader_.reset(new RtpVideoReader(
+ base::MessageLoopProxy::CreateForCurrentThread()));
reader_->Init(session_.get(), this,
base::Bind(&RtpVideoReaderTest::OnReaderInitialized,
base::Unretained(this)));
diff --git a/remoting/protocol/rtp_video_writer.cc b/remoting/protocol/rtp_video_writer.cc
index 54b3ff0..ae85f83 100644
--- a/remoting/protocol/rtp_video_writer.cc
+++ b/remoting/protocol/rtp_video_writer.cc
@@ -20,8 +20,9 @@ namespace {
const int kMtu = 1200;
} // namespace
-RtpVideoWriter::RtpVideoWriter()
- : initialized_(false) {
+RtpVideoWriter::RtpVideoWriter(base::MessageLoopProxy* message_loop)
+ : initialized_(false),
+ rtp_writer_(message_loop) {
}
RtpVideoWriter::~RtpVideoWriter() {
diff --git a/remoting/protocol/rtp_video_writer.h b/remoting/protocol/rtp_video_writer.h
index f048254..bb8ddc7 100644
--- a/remoting/protocol/rtp_video_writer.h
+++ b/remoting/protocol/rtp_video_writer.h
@@ -9,6 +9,10 @@
#include "remoting/protocol/rtp_writer.h"
#include "remoting/protocol/video_writer.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
namespace protocol {
@@ -16,7 +20,7 @@ class Session;
class RtpVideoWriter : public VideoWriter {
public:
- RtpVideoWriter();
+ RtpVideoWriter(base::MessageLoopProxy* message_loop);
virtual ~RtpVideoWriter();
// VideoWriter interface.
diff --git a/remoting/protocol/rtp_video_writer_unittest.cc b/remoting/protocol/rtp_video_writer_unittest.cc
index 118c300..0fe86e4c 100644
--- a/remoting/protocol/rtp_video_writer_unittest.cc
+++ b/remoting/protocol/rtp_video_writer_unittest.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
#include "base/string_number_conversions.h"
#include "remoting/base/constants.h"
#include "remoting/proto/video.pb.h"
@@ -57,6 +58,10 @@ class RtpVideoWriterTest : public testing::Test {
bool last;
};
+ RtpVideoWriterTest()
+ : writer_(base::MessageLoopProxy::CreateForCurrentThread()) {
+ }
+
virtual void SetUp() {
session_.reset(new FakeSession());
writer_.Init(session_.get(),
diff --git a/remoting/protocol/rtp_writer.cc b/remoting/protocol/rtp_writer.cc
index fb1e1f8..a672c1e 100644
--- a/remoting/protocol/rtp_writer.cc
+++ b/remoting/protocol/rtp_writer.cc
@@ -16,8 +16,9 @@ namespace {
const uint8 kRtpPayloadTypePrivate = 96;
} // namespace
-RtpWriter::RtpWriter()
- : last_packet_number_(0) {
+RtpWriter::RtpWriter(base::MessageLoopProxy* message_loop)
+ : last_packet_number_(0),
+ buffered_rtp_writer_(new BufferedDatagramWriter(message_loop)) {
}
RtpWriter::~RtpWriter() { }
@@ -25,7 +26,6 @@ RtpWriter::~RtpWriter() { }
// Initializes the writer. Must be called on the thread the sockets belong
// to.
void RtpWriter::Init(net::Socket* rtp_socket) {
- buffered_rtp_writer_ = new BufferedDatagramWriter();
buffered_rtp_writer_->Init(rtp_socket, NULL);
}
diff --git a/remoting/protocol/rtp_writer.h b/remoting/protocol/rtp_writer.h
index dbf5bdd..8ce626b 100644
--- a/remoting/protocol/rtp_writer.h
+++ b/remoting/protocol/rtp_writer.h
@@ -17,7 +17,7 @@ namespace protocol {
class RtpWriter {
public:
- RtpWriter();
+ RtpWriter(base::MessageLoopProxy* message_loop);
virtual ~RtpWriter();
// Initializes the writer. Must be called on the thread the socket
diff --git a/remoting/protocol/video_reader.cc b/remoting/protocol/video_reader.cc
index b3bc5ed..d48daaa 100644
--- a/remoting/protocol/video_reader.cc
+++ b/remoting/protocol/video_reader.cc
@@ -14,17 +14,19 @@ namespace protocol {
VideoReader::~VideoReader() { }
// static
-VideoReader* VideoReader::Create(const SessionConfig* config) {
+VideoReader* VideoReader::Create(base::MessageLoopProxy* message_loop,
+ const SessionConfig* config) {
const ChannelConfig& video_config = config->video_config();
if (video_config.transport == ChannelConfig::TRANSPORT_SRTP) {
- return new RtpVideoReader();
+ return new RtpVideoReader(message_loop);
} else if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) {
- if (video_config.codec == ChannelConfig::CODEC_VP8)
+ if (video_config.codec == ChannelConfig::CODEC_VP8) {
return new ProtobufVideoReader(VideoPacketFormat::ENCODING_VP8);
- else if (video_config.codec == ChannelConfig::CODEC_ZIP)
+ } else if (video_config.codec == ChannelConfig::CODEC_ZIP) {
return new ProtobufVideoReader(VideoPacketFormat::ENCODING_ZLIB);
- else if (video_config.codec == ChannelConfig::CODEC_VERBATIM)
+ } else if (video_config.codec == ChannelConfig::CODEC_VERBATIM) {
return new ProtobufVideoReader(VideoPacketFormat::ENCODING_VERBATIM);
+ }
}
NOTREACHED();
return NULL;
diff --git a/remoting/protocol/video_reader.h b/remoting/protocol/video_reader.h
index e539c0d..986216e 100644
--- a/remoting/protocol/video_reader.h
+++ b/remoting/protocol/video_reader.h
@@ -12,6 +12,10 @@
#include "base/callback.h"
#include "remoting/protocol/video_stub.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
class ChromotocolConnection;
@@ -23,7 +27,8 @@ class SessionConfig;
class VideoReader {
public:
- static VideoReader* Create(const SessionConfig* config);
+ static VideoReader* Create(base::MessageLoopProxy* message_loop,
+ const SessionConfig* config);
// The callback is called when initialization is finished. The
// parameter is set to true on success.
diff --git a/remoting/protocol/video_writer.cc b/remoting/protocol/video_writer.cc
index 2336fe3..f0d4a53 100644
--- a/remoting/protocol/video_writer.cc
+++ b/remoting/protocol/video_writer.cc
@@ -14,12 +14,13 @@ namespace protocol {
VideoWriter::~VideoWriter() { }
// static
-VideoWriter* VideoWriter::Create(const SessionConfig* config) {
+VideoWriter* VideoWriter::Create(base::MessageLoopProxy* message_loop,
+ const SessionConfig* config) {
const ChannelConfig& video_config = config->video_config();
if (video_config.transport == ChannelConfig::TRANSPORT_SRTP) {
- return new RtpVideoWriter();
+ return new RtpVideoWriter(message_loop);
} else if (video_config.transport == ChannelConfig::TRANSPORT_STREAM) {
- return new ProtobufVideoWriter();
+ return new ProtobufVideoWriter(message_loop);
}
return NULL;
}
diff --git a/remoting/protocol/video_writer.h b/remoting/protocol/video_writer.h
index 68b19fd..2b5a7be 100644
--- a/remoting/protocol/video_writer.h
+++ b/remoting/protocol/video_writer.h
@@ -14,6 +14,10 @@
#include "base/callback.h"
#include "remoting/protocol/video_stub.h"
+namespace base {
+class MessageLoopProxy;
+} // namespace base
+
namespace remoting {
namespace protocol {
@@ -28,7 +32,8 @@ class VideoWriter : public VideoStub {
// parameter is set to true on success.
typedef base::Callback<void(bool)> InitializedCallback;
- static VideoWriter* Create(const SessionConfig* config);
+ static VideoWriter* Create(base::MessageLoopProxy* message_loop,
+ const SessionConfig* config);
// Initializes the writer.
virtual void Init(Session* session, const InitializedCallback& callback) = 0;