Commit ea94040c authored by Ke He's avatar Ke He Committed by Commit Bot

Remove the condition check on GetForProcess() in cast_transport_host_filter.

Remove the "if(ServiceManagerConnection::GetForProcess())", use the DCHECK()
instead to make sure the ServiceManagerConnection is always initialized in
production code.

BUG=689415

Change-Id: I85dc481a80ddbef9faa0b5c99d8da8991d4f85be
Reviewed-on: https://chromium-review.googlesource.com/545436Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Ke He <ke.he@intel.com>
Cr-Commit-Position: refs/heads/master@{#485850}
parent ca6bf7de
......@@ -399,29 +399,33 @@ void CastTransportHostFilter::OnCastRemotingSenderEvents(
device::mojom::WakeLock* CastTransportHostFilter::GetWakeLock() {
// Here is a lazy binding, and will not reconnect after connection error.
if (!wake_lock_) {
device::mojom::WakeLockRequest request = mojo::MakeRequest(&wake_lock_);
// Service manager connection might be not initialized in some testing
// contexts.
if (content::ServiceManagerConnection::GetForProcess()) {
service_manager::mojom::ConnectorRequest connector_request;
auto connector = service_manager::Connector::Create(&connector_request);
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::BindOnce(&BindConnectorRequest, std::move(connector_request)));
device::mojom::WakeLockProviderPtr wake_lock_provider;
connector->BindInterface(device::mojom::kServiceName,
mojo::MakeRequest(&wake_lock_provider));
wake_lock_provider->GetWakeLockWithoutContext(
device::mojom::WakeLockType::PreventAppSuspension,
device::mojom::WakeLockReason::ReasonOther,
"Cast is streaming content to a remote receiver", std::move(request));
}
}
if (wake_lock_)
return wake_lock_.get();
device::mojom::WakeLockRequest request = mojo::MakeRequest(&wake_lock_);
DCHECK(content::ServiceManagerConnection::GetForProcess());
service_manager::mojom::ConnectorRequest connector_request;
auto connector = service_manager::Connector::Create(&connector_request);
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::BindOnce(&BindConnectorRequest, std::move(connector_request)));
device::mojom::WakeLockProviderPtr wake_lock_provider;
connector->BindInterface(device::mojom::kServiceName,
mojo::MakeRequest(&wake_lock_provider));
wake_lock_provider->GetWakeLockWithoutContext(
device::mojom::WakeLockType::PreventAppSuspension,
device::mojom::WakeLockReason::ReasonOther,
"Cast is streaming content to a remote receiver", std::move(request));
return wake_lock_.get();
}
void CastTransportHostFilter::InitializeNoOpWakeLockForTesting() {
// Initializes |wake_lock_| to make GetWakeLock() short-circuit out of its
// own lazy initialization process.
mojo::MakeRequest(&wake_lock_);
}
} // namespace cast
......@@ -27,6 +27,9 @@ class CastTransportHostFilter : public content::BrowserMessageFilter {
public:
CastTransportHostFilter();
// Used by unit test only.
void InitializeNoOpWakeLockForTesting();
private:
~CastTransportHostFilter() override;
......
......@@ -22,6 +22,8 @@ class CastTransportHostFilterTest : public testing::Test {
: browser_thread_bundle_(
content::TestBrowserThreadBundle::IO_MAINLOOP) {
filter_ = new cast::CastTransportHostFilter();
static_cast<cast::CastTransportHostFilter*>(filter_.get())
->InitializeNoOpWakeLockForTesting();
// 127.0.0.1:7 is the local echo service port, which
// is probably not going to respond, but that's ok.
// TODO(hubbe): Open up an UDP port and make sure
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment