Commit 01364538 authored by Erik Chen's avatar Erik Chen Committed by Chromium LUCI CQ

Lacros: Remove deprecated ScreenManager methods.

This CL is a refactor with no intended behavior changes.

The new ScreenManager interface was landed in M88. Ash beta is now M88,
and Lacros is not available on Ash stable M87, so Lacros can always
assume that the new ScreenManager interfaces exist.

Removing this dead code is a prerequisite to refactoring the test code,
which itself is a prerequisite for other lacros_chrome_browsertests.

Change-Id: Ia5311010c8003f763409b2dc556a7dd6a99fc80d
Bug: 1155662, 1156872, 1094460
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580107Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835254}
parent 3904e0fe
...@@ -206,34 +206,17 @@ void ScreenManagerAsh::BindReceiver( ...@@ -206,34 +206,17 @@ void ScreenManagerAsh::BindReceiver(
void ScreenManagerAsh::DeprecatedTakeScreenSnapshot( void ScreenManagerAsh::DeprecatedTakeScreenSnapshot(
DeprecatedTakeScreenSnapshotCallback callback) { DeprecatedTakeScreenSnapshotCallback callback) {
GetScreenCapturerImpl()->TakeSnapshot( NOTIMPLEMENTED();
GetScreenCapturerImpl()->GetPrimaryRootWindowId(),
base::BindOnce(
[](DeprecatedTakeScreenSnapshotCallback callback, bool success,
const SkBitmap& bitmap) {
// Ignore |success| param.
std::move(callback).Run(BitmapFromSkBitmap(bitmap));
},
std::move(callback)));
} }
void ScreenManagerAsh::DeprecatedListWindows( void ScreenManagerAsh::DeprecatedListWindows(
DeprecatedListWindowsCallback callback) { DeprecatedListWindowsCallback callback) {
GetWindowCapturerImpl()->ListSources(std::move(callback)); NOTIMPLEMENTED();
} }
void ScreenManagerAsh::DeprecatedTakeWindowSnapshot( void ScreenManagerAsh::DeprecatedTakeWindowSnapshot(
uint64_t id, uint64_t id,
DeprecatedTakeWindowSnapshotCallback callback) { DeprecatedTakeWindowSnapshotCallback callback) {
GetWindowCapturerImpl()->TakeSnapshot( NOTIMPLEMENTED();
id, base::BindOnce(
[](DeprecatedTakeWindowSnapshotCallback callback, bool success,
const SkBitmap& bitmap) {
std::move(callback).Run(success, BitmapFromSkBitmap(bitmap));
},
std::move(callback)));
} }
void ScreenManagerAsh::GetScreenCapturer( void ScreenManagerAsh::GetScreenCapturer(
mojo::PendingReceiver<mojom::SnapshotCapturer> receiver) { mojo::PendingReceiver<mojom::SnapshotCapturer> receiver) {
GetScreenCapturerImpl()->BindReceiver(std::move(receiver)); GetScreenCapturerImpl()->BindReceiver(std::move(receiver));
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chromeos/crosapi/cpp/bitmap.h"
#include "chromeos/crosapi/mojom/screen_manager.mojom.h" #include "chromeos/crosapi/mojom/screen_manager.mojom.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
...@@ -80,65 +79,6 @@ class ScreenManagerAshBrowserTest : public InProcessBrowserTest { ...@@ -80,65 +79,6 @@ class ScreenManagerAshBrowserTest : public InProcessBrowserTest {
std::unique_ptr<SMRemote> screen_manager_remote_; std::unique_ptr<SMRemote> screen_manager_remote_;
}; };
// Tests that taking a screen snapshot works.
IN_PROC_BROWSER_TEST_F(ScreenManagerAshBrowserTest,
DeprecatedTakeScreenSnapshot) {
base::RunLoop run_loop;
Bitmap snapshot;
// Take a snapshot on a background sequence. The call is blocking, so when it
// finishes, we can also unblock the main thread.
auto take_snapshot_background = base::BindOnce(
[](SMRemote* remote, Bitmap* snapshot) {
mojo::ScopedAllowSyncCallForTesting allow_sync;
(*remote)->DeprecatedTakeScreenSnapshot(snapshot);
},
screen_manager_remote_.get(), &snapshot);
background_sequence_->PostTaskAndReply(
FROM_HERE, std::move(take_snapshot_background), run_loop.QuitClosure());
run_loop.Run();
// Check that the screenshot has the right dimensions.
aura::Window* primary_window =
browser()->window()->GetNativeWindow()->GetRootWindow();
EXPECT_EQ(int{snapshot.width}, primary_window->bounds().width());
EXPECT_EQ(int{snapshot.height}, primary_window->bounds().height());
}
IN_PROC_BROWSER_TEST_F(ScreenManagerAshBrowserTest,
DeprecatedTakeWindowSnapshot) {
base::RunLoop run_loop;
bool success;
Bitmap snapshot;
// Take a snapshot on a background sequence. The call is blocking, so when it
// finishes, we can also unblock the main thread.
auto take_snapshot_background = base::BindOnce(
[](SMRemote* remote, bool* success, Bitmap* snapshot) {
mojo::ScopedAllowSyncCallForTesting allow_sync;
std::vector<mojom::SnapshotSourcePtr> windows;
(*remote)->DeprecatedListWindows(&windows);
// There should be exactly 1 window.
ASSERT_EQ(1u, windows.size());
(*remote)->DeprecatedTakeWindowSnapshot(windows[0]->id, success,
snapshot);
},
screen_manager_remote_.get(), &success, &snapshot);
background_sequence_->PostTaskAndReply(
FROM_HERE, std::move(take_snapshot_background), run_loop.QuitClosure());
run_loop.Run();
// Check that the IPC succeeded.
ASSERT_TRUE(success);
// Check that the screenshot has the right dimensions.
aura::Window* window = browser()->window()->GetNativeWindow();
EXPECT_EQ(int{snapshot.width}, window->bounds().width());
EXPECT_EQ(int{snapshot.height}, window->bounds().height());
}
IN_PROC_BROWSER_TEST_F(ScreenManagerAshBrowserTest, ScreenCapturer) { IN_PROC_BROWSER_TEST_F(ScreenManagerAshBrowserTest, ScreenCapturer) {
base::RunLoop run_loop; base::RunLoop run_loop;
bool success; bool success;
......
...@@ -108,60 +108,6 @@ class ScreenManagerLacrosBrowserTest : public InProcessBrowserTest { ...@@ -108,60 +108,6 @@ class ScreenManagerLacrosBrowserTest : public InProcessBrowserTest {
mojo::Remote<crosapi::mojom::ScreenManager> screen_manager_; mojo::Remote<crosapi::mojom::ScreenManager> screen_manager_;
}; };
// Tests that taking a screen snapshot via crosapi works.
IN_PROC_BROWSER_TEST_F(ScreenManagerLacrosBrowserTest,
DeprecatedTakeScreenSnapshot) {
BindScreenManager();
crosapi::Bitmap snapshot;
{
mojo::ScopedAllowSyncCallForTesting allow_sync_call;
screen_manager_->DeprecatedTakeScreenSnapshot(&snapshot);
}
// Verify the snapshot is non-empty.
EXPECT_GT(snapshot.height, 0u);
EXPECT_GT(snapshot.width, 0u);
EXPECT_GT(snapshot.pixels.size(), 0u);
}
// Tests that taking a screen snapshot via crosapi works.
// This test makes the browser load a page with specific title, and then scans
// through a list of windows to look for the window with the expected title.
// This test cannot simply assert exactly 1 window is present because currently
// in lacros_chrome_browsertests, different browser tests share the same
// ash-chrome, so a window could come from any one of them.
IN_PROC_BROWSER_TEST_F(ScreenManagerLacrosBrowserTest,
DeprecatedTakeWindowSnapshot) {
GURL url(std::string("data:text/html,") + kLacrosPageTitleHTML);
ui_test_utils::NavigateToURL(browser(), url);
BindScreenManager();
auto list_windows = base::BindRepeating(
[](mojo::Remote<crosapi::mojom::ScreenManager>* screen_manager,
std::vector<crosapi::mojom::SnapshotSourcePtr>* windows) {
mojo::ScopedAllowSyncCallForTesting allow_sync_call;
(*screen_manager)->DeprecatedListWindows(windows);
},
&screen_manager_);
uint64_t window_id;
bool found_window = FindTestWindow(std::move(list_windows), &window_id);
ASSERT_TRUE(found_window);
bool success = false;
crosapi::Bitmap snapshot;
{
mojo::ScopedAllowSyncCallForTesting allow_sync_call;
screen_manager_->DeprecatedTakeWindowSnapshot(window_id, &success,
&snapshot);
}
ASSERT_TRUE(success);
// Verify the snapshot is non-empty.
EXPECT_GT(snapshot.height, 0u);
EXPECT_GT(snapshot.width, 0u);
EXPECT_GT(snapshot.pixels.size(), 0u);
}
// Tests that taking a screen snapshot via crosapi works. // Tests that taking a screen snapshot via crosapi works.
IN_PROC_BROWSER_TEST_F(ScreenManagerLacrosBrowserTest, ScreenCapturer) { IN_PROC_BROWSER_TEST_F(ScreenManagerLacrosBrowserTest, ScreenCapturer) {
BindScreenManager(); BindScreenManager();
......
...@@ -6,7 +6,7 @@ module crosapi.mojom; ...@@ -6,7 +6,7 @@ module crosapi.mojom;
// Each pixel is represented by 4 bytes [RGBA]. // Each pixel is represented by 4 bytes [RGBA].
// NOTE: For UI images prefer gfx.mojom.ImageSkia, which supports high-DPI. // NOTE: For UI images prefer gfx.mojom.ImageSkia, which supports high-DPI.
// TODO(https://crbug.com/1094460): Use a more performant transport mechanism. // TODO(https://crbug.com/1156872): This struct is unused and should be deleted.
[Stable] [Stable]
struct Bitmap { struct Bitmap {
uint32 width@0; uint32 width@0;
......
...@@ -46,27 +46,12 @@ interface SnapshotCapturer { ...@@ -46,27 +46,12 @@ interface SnapshotCapturer {
// interface in the future. // interface in the future.
[Stable, Uuid="95c3035c-5c63-45e3-8ec8-dd2a344c7dc2"] [Stable, Uuid="95c3035c-5c63-45e3-8ec8-dd2a344c7dc2"]
interface ScreenManager { interface ScreenManager {
// DEPRECATED. Use |GetScreenCapturer| instead. // DEPRECATED. Unimplemented and unused. Delete this once deletion is
// // supported. https://crbug.com/1156872.
// This method assumes that there's exactly one screen. The implementation
// of this method takes a screenshot and converts it into a bitmap. Each
// pixel is represented by 4 bytes [RGBA].
//
// The media screen capture implementation assumes that every platform
// provides a synchronous method to take a snapshot of the screen.
[Sync] [Sync]
DeprecatedTakeScreenSnapshot@0() => (Bitmap snapshot); DeprecatedTakeScreenSnapshot@0() => (Bitmap snapshot);
// DEPRECATED. Use |GetWindowCapturer| instead.
//
// Returns a list of visible, focusable top-level windows.
[Sync] [Sync]
DeprecatedListWindows@1() => (array<SnapshotSource> windows); DeprecatedListWindows@1() => (array<SnapshotSource> windows);
// DEPRECATED. Use |GetWindowCapturer| instead.
//
// Take a screenshot of a window with an id from ListWindows. If |success|
// is false, then the window no longer exists.
[Sync] [Sync]
DeprecatedTakeWindowSnapshot@2(uint64 id) => (bool success, Bitmap snapshot); DeprecatedTakeWindowSnapshot@2(uint64 id) => (bool success, Bitmap snapshot);
......
...@@ -4,13 +4,9 @@ ...@@ -4,13 +4,9 @@
#include "content/browser/media/capture/desktop_capturer_lacros.h" #include "content/browser/media/capture/desktop_capturer_lacros.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "chromeos/crosapi/cpp/bitmap.h"
#include "chromeos/lacros/lacros_chrome_service_impl.h" #include "chromeos/lacros/lacros_chrome_service_impl.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
namespace content { namespace content {
namespace { namespace {
...@@ -55,20 +51,9 @@ bool DesktopCapturerLacros::GetSourceList(SourceList* result) { ...@@ -55,20 +51,9 @@ bool DesktopCapturerLacros::GetSourceList(SourceList* result) {
std::vector<crosapi::mojom::SnapshotSourcePtr> sources; std::vector<crosapi::mojom::SnapshotSourcePtr> sources;
if (snapshot_capturer_) { {
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call;
snapshot_capturer_->ListSources(&sources); snapshot_capturer_->ListSources(&sources);
} else {
if (capture_type_ == kScreen) {
// TODO(https://crbug.com/1094460): Implement this source list
// appropriately.
Source w;
w.id = 1;
result->push_back(w);
return true;
}
mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call;
screen_manager_->DeprecatedListWindows(&sources);
} }
for (auto& source : sources) { for (auto& source : sources) {
...@@ -105,25 +90,17 @@ void DesktopCapturerLacros::Start(Callback* callback) { ...@@ -105,25 +90,17 @@ void DesktopCapturerLacros::Start(Callback* callback) {
lacros_chrome_service->BindScreenManagerReceiver( lacros_chrome_service->BindScreenManagerReceiver(
screen_manager_.BindNewPipeAndPassReceiver()); screen_manager_.BindNewPipeAndPassReceiver());
// Do a round-trip to make sure we know what version of the screen manager we // Lacros can assume that Ash is at least M88.
// are talking to. It is safe to run a nested loop here because we are on a int version = lacros_chrome_service->GetInterfaceVersion(
// dedicated thread (see DesktopCaptureDevice) with nothing else happening. crosapi::mojom::ScreenManager::Uuid_);
// TODO(crbug/1094460): Avoid this nested event loop. CHECK_GE(version, 1);
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
screen_manager_.QueryVersion( if (capture_type_ == kScreen) {
base::BindOnce([](base::OnceClosure quit_closure, screen_manager_->GetScreenCapturer(
uint32_t version) { std::move(quit_closure).Run(); }, snapshot_capturer_.BindNewPipeAndPassReceiver());
run_loop.QuitClosure())); } else {
run_loop.Run(); screen_manager_->GetWindowCapturer(
snapshot_capturer_.BindNewPipeAndPassReceiver());
if (screen_manager_.version() >= 1) {
if (capture_type_ == kScreen) {
screen_manager_->GetScreenCapturer(
snapshot_capturer_.BindNewPipeAndPassReceiver());
} else {
screen_manager_->GetWindowCapturer(
snapshot_capturer_.BindNewPipeAndPassReceiver());
}
} }
} }
...@@ -135,23 +112,9 @@ void DesktopCapturerLacros::CaptureFrame() { ...@@ -135,23 +112,9 @@ void DesktopCapturerLacros::CaptureFrame() {
capturing_frame_ = true; capturing_frame_ = true;
#endif #endif
if (snapshot_capturer_) { snapshot_capturer_->TakeSnapshot(
snapshot_capturer_->TakeSnapshot( selected_source_, base::BindOnce(&DesktopCapturerLacros::DidTakeSnapshot,
selected_source_, weak_factory_.GetWeakPtr()));
base::BindOnce(&DesktopCapturerLacros::DidTakeSnapshot,
weak_factory_.GetWeakPtr()));
} else {
if (capture_type_ == kScreen) {
screen_manager_->DeprecatedTakeScreenSnapshot(
base::BindOnce(&DesktopCapturerLacros::DeprecatedDidTakeSnapshot,
weak_factory_.GetWeakPtr(), /*success*/ true));
} else {
screen_manager_->DeprecatedTakeWindowSnapshot(
selected_source_,
base::BindOnce(&DesktopCapturerLacros::DeprecatedDidTakeSnapshot,
weak_factory_.GetWeakPtr()));
}
}
} }
bool DesktopCapturerLacros::IsOccluded(const webrtc::DesktopVector& pos) { bool DesktopCapturerLacros::IsOccluded(const webrtc::DesktopVector& pos) {
...@@ -181,32 +144,4 @@ void DesktopCapturerLacros::DidTakeSnapshot(bool success, ...@@ -181,32 +144,4 @@ void DesktopCapturerLacros::DidTakeSnapshot(bool success,
std::make_unique<DesktopFrameSkia>(snapshot)); std::make_unique<DesktopFrameSkia>(snapshot));
} }
void DesktopCapturerLacros::DeprecatedDidTakeSnapshot(
bool success,
crosapi::Bitmap snapshot) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if DCHECK_IS_ON()
capturing_frame_ = false;
#endif
if (!success) {
callback_->OnCaptureResult(Result::ERROR_PERMANENT,
std::unique_ptr<webrtc::DesktopFrame>());
return;
}
std::unique_ptr<webrtc::DesktopFrame> frame =
std::make_unique<webrtc::BasicDesktopFrame>(
webrtc::DesktopSize(snapshot.width, snapshot.height));
// This code assumes that the stride is 4 * width. This relies on the
// assumption that there's no padding and each pixel is 4 bytes.
frame->CopyPixelsFrom(
snapshot.pixels.data(), 4 * snapshot.width,
webrtc::DesktopRect::MakeWH(snapshot.width, snapshot.height));
callback_->OnCaptureResult(Result::SUCCESS, std::move(frame));
}
} // namespace content } // namespace content
...@@ -12,10 +12,6 @@ ...@@ -12,10 +12,6 @@
#include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h" #include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
namespace crosapi {
struct Bitmap;
} // namespace crosapi
namespace content { namespace content {
// This class is responsible for communicating with ash-chrome to get snapshots // This class is responsible for communicating with ash-chrome to get snapshots
...@@ -50,7 +46,6 @@ class DesktopCapturerLacros : public webrtc::DesktopCapturer { ...@@ -50,7 +46,6 @@ class DesktopCapturerLacros : public webrtc::DesktopCapturer {
// Callback for when ash-chrome returns a snapshot of the screen or window as // Callback for when ash-chrome returns a snapshot of the screen or window as
// a bitmap. // a bitmap.
void DidTakeSnapshot(bool success, const SkBitmap& snapshot); void DidTakeSnapshot(bool success, const SkBitmap& snapshot);
void DeprecatedDidTakeSnapshot(bool success, crosapi::Bitmap snapshot);
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
...@@ -76,8 +71,8 @@ class DesktopCapturerLacros : public webrtc::DesktopCapturer { ...@@ -76,8 +71,8 @@ class DesktopCapturerLacros : public webrtc::DesktopCapturer {
// The remote connection to the screen manager. // The remote connection to the screen manager.
mojo::Remote<crosapi::mojom::ScreenManager> screen_manager_; mojo::Remote<crosapi::mojom::ScreenManager> screen_manager_;
// Only set if we are using a newer screen manager. Otherwise, we fallback to // A remote for an ash interface that is responsible for either capturing
// the deprecated methods. // screen snapshots or window snapshots.
mojo::Remote<crosapi::mojom::SnapshotCapturer> snapshot_capturer_; mojo::Remote<crosapi::mojom::SnapshotCapturer> snapshot_capturer_;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
......
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