Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Unified Diff: remoting/test/protocol_perftest.cc

Issue 414443009: Update ProtocolPerfTest to run host and client on different threads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/signaling/fake_signal_strategy.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/test/protocol_perftest.cc
diff --git a/remoting/test/protocol_perftest.cc b/remoting/test/protocol_perftest.cc
index 2ce73a1c45c2efa6fb481f50ef78a9fb4c991364..1e1c14aaa29ed6f988ee38fb37038a575454fc5a 100644
--- a/remoting/test/protocol_perftest.cc
+++ b/remoting/test/protocol_perftest.cc
@@ -9,6 +9,7 @@
#include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h"
#include "base/thread_task_runner_handle.h"
+#include "jingle/glue/thread_wrapper.h"
#include "net/base/test_data_directory.h"
#include "net/url_request/url_request_context_getter.h"
#include "remoting/base/rsa_key_pair.h"
@@ -44,13 +45,19 @@ class ProtocolPerfTest : public testing::Test,
public HostStatusObserver {
public:
ProtocolPerfTest()
- : capture_thread_("capture"),
+ : host_thread_("host"),
+ capture_thread_("capture"),
encode_thread_("encode") {
VideoScheduler::EnableTimestampsForTests();
+ host_thread_.StartWithOptions(
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
capture_thread_.Start();
encode_thread_.Start();
}
virtual ~ProtocolPerfTest() {
+ host_thread_.message_loop_proxy()->DeleteSoon(FROM_HERE, host_.release());
+ host_thread_.message_loop_proxy()->DeleteSoon(FROM_HERE,
+ host_signaling_.release());
message_loop_.RunUntilIdle();
}
@@ -100,9 +107,10 @@ class ProtocolPerfTest : public testing::Test,
// HostStatusObserver interface.
virtual void OnClientConnected(const std::string& jid) OVERRIDE {
- host_connected_ = true;
- if (client_connected_)
- connecting_loop_->Quit();
+ message_loop_.PostTask(
+ FROM_HERE,
+ base::Bind(&ProtocolPerfTest::OnHostConnectedMainThread,
+ base::Unretained(this)));
}
protected:
@@ -116,6 +124,12 @@ class ProtocolPerfTest : public testing::Test,
ASSERT_TRUE(client_connected_ && host_connected_);
}
+ void OnHostConnectedMainThread() {
+ host_connected_ = true;
+ if (client_connected_)
+ connecting_loop_->Quit();
+ }
+
void ReceiveFrame(base::TimeDelta* latency) {
waiting_frames_loop_.reset(new base::RunLoop());
on_frame_task_ = waiting_frames_loop_->QuitClosure();
@@ -143,21 +157,38 @@ class ProtocolPerfTest : public testing::Test,
}
}
+ // Creates test host and client and starts connection between them. Caller
+ // should call WaitConnected() to wait until connection is established. The
+ // host is started on |host_thread_| while the client works on the main
+ // thread.
void StartHostAndClient(protocol::ChannelConfig::Codec video_codec) {
- host_signaling_.reset(new FakeSignalStrategy(kHostJid));
client_signaling_.reset(new FakeSignalStrategy(kClientJid));
- FakeSignalStrategy::Connect(host_signaling_.get(), client_signaling_.get());
+
+ jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
+
+ protocol_config_ = protocol::CandidateSessionConfig::CreateDefault();
+ protocol_config_->DisableAudioChannel();
+ protocol_config_->mutable_video_configs()->clear();
+ protocol_config_->mutable_video_configs()->push_back(
+ protocol::ChannelConfig(
+ protocol::ChannelConfig::TRANSPORT_STREAM, 2, video_codec));
+
+ host_thread_.message_loop_proxy()->PostTask(
+ FROM_HERE,
+ base::Bind(&ProtocolPerfTest::StartHost, base::Unretained(this)));
+ }
+
+ void StartHost() {
+ DCHECK(host_thread_.message_loop_proxy()->BelongsToCurrentThread());
+
+ jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
+
+ host_signaling_.reset(new FakeSignalStrategy(kHostJid));
+ host_signaling_->ConnectTo(client_signaling_.get());
protocol::NetworkSettings network_settings(
protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING);
- scoped_ptr<protocol::CandidateSessionConfig> protocol_config =
- protocol::CandidateSessionConfig::CreateDefault();
- protocol_config->DisableAudioChannel();
- protocol_config->mutable_video_configs()->clear();
- protocol_config->mutable_video_configs()->push_back(protocol::ChannelConfig(
- protocol::ChannelConfig::TRANSPORT_STREAM, 2, video_codec));
-
// TODO(sergeyu): Replace with a fake port allocator.
scoped_ptr<cricket::HttpPortAllocatorBase> host_port_allocator =
protocol::ChromiumPortAllocator::Create(NULL, network_settings)
@@ -177,12 +208,12 @@ class ProtocolPerfTest : public testing::Test,
host_.reset(new ChromotingHost(host_signaling_.get(),
&desktop_environment_factory_,
session_manager.Pass(),
- message_loop_.message_loop_proxy(),
- message_loop_.message_loop_proxy(),
+ host_thread_.message_loop_proxy(),
+ host_thread_.message_loop_proxy(),
capture_thread_.message_loop_proxy(),
encode_thread_.message_loop_proxy(),
- message_loop_.message_loop_proxy(),
- message_loop_.message_loop_proxy()));
+ host_thread_.message_loop_proxy(),
+ host_thread_.message_loop_proxy()));
base::FilePath certs_dir(net::GetTestCertsDirectory());
@@ -208,9 +239,20 @@ class ProtocolPerfTest : public testing::Test,
host_->SetAuthenticatorFactory(auth_factory.Pass());
host_->AddStatusObserver(this);
- host_->set_protocol_config(protocol_config->Clone());
+ host_->set_protocol_config(protocol_config_->Clone());
host_->Start(kHostOwner);
+ message_loop_.PostTask(FROM_HERE,
+ base::Bind(&ProtocolPerfTest::StartClientAfterHost,
+ base::Unretained(this)));
+ }
+
+ void StartClientAfterHost() {
+ client_signaling_->ConnectTo(host_signaling_.get());
+
+ protocol::NetworkSettings network_settings(
+ protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING);
+
// Initialize client.
client_context_.reset(
new ClientContext(base::ThreadTaskRunnerHandle::Get()));
@@ -238,7 +280,7 @@ class ProtocolPerfTest : public testing::Test,
auth_methods));
client_.reset(new ChromotingClient(
client_context_.get(), this, this, scoped_ptr<AudioPlayer>()));
- client_->SetProtocolConfigForTests(protocol_config->Clone());
+ client_->SetProtocolConfigForTests(protocol_config_->Clone());
client_->Start(
client_signaling_.get(), client_authenticator.Pass(),
client_transport_factory.Pass(), kHostJid, std::string());
@@ -252,9 +294,12 @@ class ProtocolPerfTest : public testing::Test,
base::MessageLoopForIO message_loop_;
- FakeDesktopEnvironmentFactory desktop_environment_factory_;
+ base::Thread host_thread_;
base::Thread capture_thread_;
base::Thread encode_thread_;
+ FakeDesktopEnvironmentFactory desktop_environment_factory_;
+
+ scoped_ptr<protocol::CandidateSessionConfig> protocol_config_;
scoped_ptr<FakeSignalStrategy> host_signaling_;
scoped_ptr<FakeSignalStrategy> client_signaling_;
« no previous file with comments | « remoting/signaling/fake_signal_strategy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698