Commit 10119600 authored by mark a. foltz's avatar mark a. foltz Committed by Commit Bot

[Media Router] Don't wake the MR event page without an extension ID.

It's possible for the extension ID to be unset on the
EventPageRequestManager while requests are incoming for the event page.
In that case, avoid calling into extensions::ProcessManager to wake the
event page with an empty extension ID.

Bug: 1105702
Change-Id: I9017c0c6af7697fb0ac3d82fcb4e49d261993884
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2446712Reviewed-by: default avatarTakumi Fujimoto <takumif@chromium.org>
Commit-Queue: mark a. foltz <mfoltz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814331}
parent 4cabff3a
...@@ -30,7 +30,6 @@ void EventPageRequestManager::RunOrDefer( ...@@ -30,7 +30,6 @@ void EventPageRequestManager::RunOrDefer(
base::OnceClosure request, base::OnceClosure request,
MediaRouteProviderWakeReason wake_reason) { MediaRouteProviderWakeReason wake_reason) {
if (mojo_connections_ready_) { if (mojo_connections_ready_) {
DCHECK(!media_route_provider_extension_id_.empty());
std::move(request).Run(); std::move(request).Run();
} else { } else {
EnqueueRequest(std::move(request)); EnqueueRequest(std::move(request));
...@@ -75,7 +74,7 @@ void EventPageRequestManager::OnMojoConnectionError() { ...@@ -75,7 +74,7 @@ void EventPageRequestManager::OnMojoConnectionError() {
} }
content::WebContents* EventPageRequestManager::GetEventPageWebContents() { content::WebContents* EventPageRequestManager::GetEventPageWebContents() {
if (!extension_process_manager_) if (!extension_process_manager_ || media_route_provider_extension_id_.empty())
return nullptr; return nullptr;
extensions::ExtensionHost* extension_host = extensions::ExtensionHost* extension_host =
...@@ -111,11 +110,17 @@ void EventPageRequestManager::SetWakeReason( ...@@ -111,11 +110,17 @@ void EventPageRequestManager::SetWakeReason(
bool EventPageRequestManager::IsEventPageSuspended() const { bool EventPageRequestManager::IsEventPageSuspended() const {
return !extension_process_manager_ || return !extension_process_manager_ ||
media_route_provider_extension_id_.empty() ||
extension_process_manager_->IsEventPageSuspended( extension_process_manager_->IsEventPageSuspended(
media_route_provider_extension_id_); media_route_provider_extension_id_);
} }
void EventPageRequestManager::AttemptWakeEventPage() { void EventPageRequestManager::AttemptWakeEventPage() {
if (!extension_process_manager_ ||
media_route_provider_extension_id_.empty()) {
return;
}
++wakeup_attempt_count_; ++wakeup_attempt_count_;
if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) { if (wakeup_attempt_count_ > kMaxWakeupAttemptCount) {
DrainPendingRequests(); DrainPendingRequests();
...@@ -125,10 +130,6 @@ void EventPageRequestManager::AttemptWakeEventPage() { ...@@ -125,10 +130,6 @@ void EventPageRequestManager::AttemptWakeEventPage() {
return; return;
} }
if (!extension_process_manager_) {
return;
}
// This return false if the extension is already awake. // This return false if the extension is already awake.
// Callback is bound using WeakPtr because |extension_process_manager_| // Callback is bound using WeakPtr because |extension_process_manager_|
// outlives |this|. // outlives |this|.
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
using testing::_; using testing::_;
using testing::Invoke; using testing::Invoke;
using testing::Mock;
using testing::Return; using testing::Return;
using testing::SaveArg; using testing::SaveArg;
using testing::StrictMock; using testing::StrictMock;
...@@ -164,6 +165,58 @@ TEST_F(EventPageRequestManagerTest, RunRequestsOnConnectionsReady) { ...@@ -164,6 +165,58 @@ TEST_F(EventPageRequestManagerTest, RunRequestsOnConnectionsReady) {
ExpectWakeupBucketCount(MediaRouteProviderWakeup::SUCCESS, 1); ExpectWakeupBucketCount(MediaRouteProviderWakeup::SUCCESS, 1);
} }
TEST_F(EventPageRequestManagerTest, RunRequestsAfterExtensionIdIsSet) {
// Unset the extension ID.
request_manager_->SetExtensionId("");
StrictMock<MockRequest> request1;
StrictMock<MockRequest> request2;
request_manager_->RunOrDefer(
base::BindOnce(&MockRequest::Run, base::Unretained(&request1)),
MediaRouteProviderWakeReason::DETACH_ROUTE);
request_manager_->RunOrDefer(
base::BindOnce(&MockRequest::Run, base::Unretained(&request2)),
MediaRouteProviderWakeReason::DETACH_ROUTE);
EXPECT_CALL(request1, Run()).Times(0);
EXPECT_CALL(request2, Run()).Times(0);
// Nothing will happen until the extension ID is set.
request_manager_->OnMojoConnectionsReady();
EXPECT_TRUE(Mock::VerifyAndClearExpectations(&request1));
EXPECT_TRUE(Mock::VerifyAndClearExpectations(&request2));
// Set the extension ID.
request_manager_->SetExtensionId(kExtensionId);
// Next request wakes the event page.
ON_CALL(*process_manager_, IsEventPageSuspended(kExtensionId))
.WillByDefault(Return(true));
EXPECT_CALL(*process_manager_, WakeEventPage(kExtensionId, _))
.WillOnce([](const std::string& extension_id,
base::OnceCallback<void(bool)> callback) {
std::move(callback).Run(true);
return true;
});
StrictMock<MockRequest> request3;
request_manager_->RunOrDefer(
base::BindOnce(&MockRequest::Run, base::Unretained(&request3)),
MediaRouteProviderWakeReason::DETACH_ROUTE);
EXPECT_CALL(request1, Run());
EXPECT_CALL(request2, Run());
EXPECT_CALL(request3, Run());
// Now requests will run.
ON_CALL(*process_manager_, IsEventPageSuspended(kExtensionId))
.WillByDefault(Return(false));
request_manager_->OnMojoConnectionsReady();
ExpectWakeReasonBucketCount(MediaRouteProviderWakeReason::DETACH_ROUTE, 1);
ExpectWakeupBucketCount(MediaRouteProviderWakeup::SUCCESS, 1);
}
TEST_F(EventPageRequestManagerTest, DropOldestPendingRequest) { TEST_F(EventPageRequestManagerTest, DropOldestPendingRequest) {
StrictMock<MockRequest> request1; StrictMock<MockRequest> request1;
MockRequest request2; MockRequest request2;
......
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