Commit 8258fb07 authored by John Williams's avatar John Williams Committed by Commit Bot

Reland "[Cast MRP] Stop mirroring immediately when a the tab is closed."

This is a reland of f51b93d7

Original change's description:
> [Cast MRP] Stop mirroring immediately when a the tab is closed.
> 
> Bug: 1095764, b/159154368
> Change-Id: I36829467e3a6477499c76ae0b15e110acba00c89
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346911
> Reviewed-by: Yuri Wiitala <miu@chromium.org>
> Commit-Queue: John Williams <jrw@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#803343}

Bug: 1095764
Bug: b/159154368
Change-Id: Ib3fbf021e10e48b3cb7289427ed130b01109a71d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2388153Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Commit-Queue: Yuri Wiitala <miu@chromium.org>
Auto-Submit: John Williams <jrw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804019}
parent 73857c20
......@@ -20,6 +20,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "media/capture/mojom/video_capture.mojom.h"
#include "media/capture/mojom/video_capture_types.mojom.h"
#include "media/capture/video_capture_types.h"
......@@ -182,6 +183,22 @@ class CastMirroringServiceHostBrowserTest
host_.reset();
}
void CloseWebContents() {
TabStripModel* const tab_strip = browser()->tab_strip_model();
content::WebContents* const web_contents =
tab_strip->GetActiveWebContents();
content::WebContentsDestroyedWatcher watcher(web_contents);
// Add a new tab so the browser doesn't close.
AddBlankTabAndShow(browser());
EXPECT_CALL(*this, DidStop()).Times(1);
tab_strip->CloseWebContentsAt(
tab_strip->GetIndexOfWebContents(web_contents),
TabStripModel::CLOSE_CREATE_HISTORICAL_TAB);
watcher.Wait();
}
void RequestRefreshFrame() {
base::RunLoop run_loop;
EXPECT_CALL(*video_frame_receiver_, OnBufferReadyCall(_))
......@@ -255,6 +272,11 @@ IN_PROC_BROWSER_TEST_F(CastMirroringServiceHostBrowserTest, CaptureTabAudio) {
StopMirroring();
}
IN_PROC_BROWSER_TEST_F(CastMirroringServiceHostBrowserTest, TabClosed) {
StartTabMirroring();
CloseWebContents();
}
IN_PROC_BROWSER_TEST_F(CastMirroringServiceHostBrowserTest, TabIndicator) {
content::WebContents* const contents =
browser()->tab_strip_model()->GetActiveWebContents();
......
......@@ -15,7 +15,10 @@ MirroringService::MirroringService(
mojo::PendingReceiver<mojom::MirroringService> receiver,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
: receiver_(this, std::move(receiver)),
io_task_runner_(std::move(io_task_runner)) {}
io_task_runner_(std::move(io_task_runner)) {
receiver_.set_disconnect_handler(
base::BindOnce(&MirroringService::OnDisconnect, base::Unretained(this)));
}
MirroringService::~MirroringService() = default;
......@@ -33,4 +36,8 @@ void MirroringService::Start(
std::move(inbound_channel), io_task_runner_);
}
void MirroringService::OnDisconnect() {
session_.reset();
}
} // namespace mirroring
......@@ -33,6 +33,8 @@ class COMPONENT_EXPORT(MIRRORING_SERVICE) MirroringService final
mojo::PendingReceiver<mojom::CastMessageChannel> inbound_channel)
override;
void OnDisconnect();
mojo::Receiver<mojom::MirroringService> receiver_;
const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
std::unique_ptr<Session> session_; // Current mirroring session.
......
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