Commit 5647dd6d authored by James Cook's avatar James Cook Committed by Commit Bot

lacros: Rename ScreenManagerCrosapi to ScreenManagerAsh

Also move it into namespace crosapi.

This is more consistent with our current naming conventions.

Bug: none
Test: compiles
Change-Id: I1859bb7f3afde20aca7cf9dd516d06fd62118883
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362732Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799346}
parent c17feb22
......@@ -946,8 +946,8 @@ source_set("chromeos") {
"crosapi/browser_util.h",
"crosapi/message_center_ash.cc",
"crosapi/message_center_ash.h",
"crosapi/screen_manager_crosapi.cc",
"crosapi/screen_manager_crosapi.h",
"crosapi/screen_manager_ash.cc",
"crosapi/screen_manager_ash.h",
"crosapi/select_file_ash.cc",
"crosapi/select_file_ash.h",
"crostini/ansible/ansible_management_service.cc",
......
......@@ -6,7 +6,7 @@ specific_include_rules = {
"+chrome/browser/chromeos/crosapi",
"+ui/message_center/message_center.h",
],
"screen_manager_crosapi\.cc": [
"screen_manager_ash\.cc": [
# For window parenting.
"+ash/shell.h",
],
......
......@@ -11,7 +11,7 @@
#include "base/logging.h"
#include "chrome/browser/chromeos/crosapi/attestation_ash.h"
#include "chrome/browser/chromeos/crosapi/message_center_ash.h"
#include "chrome/browser/chromeos/crosapi/screen_manager_crosapi.h"
#include "chrome/browser/chromeos/crosapi/screen_manager_ash.h"
#include "chrome/browser/chromeos/crosapi/select_file_ash.h"
#include "chromeos/crosapi/mojom/attestation.mojom.h"
#include "chromeos/crosapi/mojom/message_center.mojom.h"
......@@ -23,7 +23,7 @@ namespace crosapi {
AshChromeServiceImpl::AshChromeServiceImpl(
mojo::PendingReceiver<mojom::AshChromeService> pending_receiver)
: receiver_(this, std::move(pending_receiver)),
screen_manager_crosapi_(std::make_unique<ScreenManagerCrosapi>()) {
screen_manager_ash_(std::make_unique<ScreenManagerAsh>()) {
// TODO(hidehiko): Remove non-critical log from here.
// Currently this is the signal that the connection is established.
LOG(WARNING) << "AshChromeService connected.";
......@@ -44,12 +44,12 @@ void AshChromeServiceImpl::BindMessageCenter(
void AshChromeServiceImpl::BindSelectFile(
mojo::PendingReceiver<mojom::SelectFile> receiver) {
select_file_crosapi_ = std::make_unique<SelectFileAsh>(std::move(receiver));
select_file_ash_ = std::make_unique<SelectFileAsh>(std::move(receiver));
}
void AshChromeServiceImpl::BindScreenManager(
mojo::PendingReceiver<mojom::ScreenManager> receiver) {
screen_manager_crosapi_->BindReceiver(std::move(receiver));
screen_manager_ash_->BindReceiver(std::move(receiver));
}
} // namespace crosapi
......@@ -11,12 +11,11 @@
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
class ScreenManagerCrosapi;
namespace crosapi {
class AttestationAsh;
class MessageCenterAsh;
class ScreenManagerAsh;
class SelectFileAsh;
// Implementation of AshChromeService. It provides a set of APIs that
......@@ -42,8 +41,8 @@ class AshChromeServiceImpl : public mojom::AshChromeService {
std::unique_ptr<AttestationAsh> attestation_ash_;
std::unique_ptr<MessageCenterAsh> message_center_ash_;
std::unique_ptr<ScreenManagerCrosapi> screen_manager_crosapi_;
std::unique_ptr<SelectFileAsh> select_file_crosapi_;
std::unique_ptr<ScreenManagerAsh> screen_manager_ash_;
std::unique_ptr<SelectFileAsh> select_file_ash_;
};
} // namespace crosapi
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/crosapi/screen_manager_crosapi.h"
#include "chrome/browser/chromeos/crosapi/screen_manager_ash.h"
#include <utility>
#include <vector>
......@@ -16,32 +16,33 @@
#include "chromeos/crosapi/cpp/bitmap.h"
#include "ui/snapshot/snapshot.h"
ScreenManagerCrosapi::ScreenManagerCrosapi() = default;
namespace crosapi {
ScreenManagerCrosapi::~ScreenManagerCrosapi() {
ScreenManagerAsh::ScreenManagerAsh() = default;
ScreenManagerAsh::~ScreenManagerAsh() {
for (auto pair : window_to_id_) {
pair.first->RemoveObserver(this);
}
}
void ScreenManagerCrosapi::BindReceiver(
mojo::PendingReceiver<crosapi::mojom::ScreenManager> receiver) {
void ScreenManagerAsh::BindReceiver(
mojo::PendingReceiver<mojom::ScreenManager> receiver) {
receivers_.Add(this, std::move(receiver));
}
void ScreenManagerCrosapi::TakeScreenSnapshot(
TakeScreenSnapshotCallback callback) {
void ScreenManagerAsh::TakeScreenSnapshot(TakeScreenSnapshotCallback callback) {
// TODO(https://crbug.com/1094460): Handle display selection and multiple
// displays.
aura::Window* primary_window = ash::Shell::GetPrimaryRootWindow();
ui::GrabWindowSnapshotAsync(
primary_window, primary_window->bounds(),
base::BindOnce(&ScreenManagerCrosapi::DidTakeSnapshot,
base::BindOnce(&ScreenManagerAsh::DidTakeSnapshot,
weak_factory_.GetWeakPtr(), std::move(callback)));
}
void ScreenManagerCrosapi::ListWindows(ListWindowsCallback callback) {
void ScreenManagerAsh::ListWindows(ListWindowsCallback callback) {
// TODO(https://crbug.com/1094460): Handle window selection and multiple
// virtual desktops.
aura::Window* container =
......@@ -49,7 +50,7 @@ void ScreenManagerCrosapi::ListWindows(ListWindowsCallback callback) {
ash::kShellWindowId_DefaultContainerDeprecated);
// We need to create a vector that contains window_id and title.
std::vector<crosapi::mojom::WindowDetailsPtr> windows;
std::vector<mojom::WindowDetailsPtr> windows;
// The |container| has all the top-level windows in reverse order, e.g. the
// most top-level window is at the end. So iterate children reversely to make
......@@ -64,8 +65,7 @@ void ScreenManagerCrosapi::ListWindows(ListWindowsCallback callback) {
if (!window->IsVisible() || !window->CanFocus())
continue;
crosapi::mojom::WindowDetailsPtr details =
crosapi::mojom::WindowDetails::New();
mojom::WindowDetailsPtr details = mojom::WindowDetails::New();
// We are already tracking the window.
auto existing_window_it = window_to_id_.find(window);
......@@ -88,12 +88,11 @@ void ScreenManagerCrosapi::ListWindows(ListWindowsCallback callback) {
std::move(callback).Run(std::move(windows));
}
void ScreenManagerCrosapi::TakeWindowSnapshot(
uint64_t id,
void ScreenManagerAsh::TakeWindowSnapshot(uint64_t id,
TakeWindowSnapshotCallback callback) {
auto it = id_to_window_.find(id);
if (it == id_to_window_.end()) {
std::move(callback).Run(/*success=*/false, crosapi::Bitmap());
std::move(callback).Run(/*success=*/false, Bitmap());
return;
}
......@@ -105,11 +104,11 @@ void ScreenManagerCrosapi::TakeWindowSnapshot(
bounds.set_y(0);
ui::GrabWindowSnapshotAsync(
window, bounds,
base::BindOnce(&ScreenManagerCrosapi::DidTakeSnapshot,
base::BindOnce(&ScreenManagerAsh::DidTakeSnapshot,
weak_factory_.GetWeakPtr(), std::move(snapshot_callback)));
}
void ScreenManagerCrosapi::OnWindowDestroying(aura::Window* window) {
void ScreenManagerAsh::OnWindowDestroying(aura::Window* window) {
auto it = window_to_id_.find(window);
if (it == window_to_id_.end())
return;
......@@ -118,7 +117,7 @@ void ScreenManagerCrosapi::OnWindowDestroying(aura::Window* window) {
id_to_window_.erase(id);
}
void ScreenManagerCrosapi::DidTakeSnapshot(SnapshotCallback callback,
void ScreenManagerAsh::DidTakeSnapshot(SnapshotCallback callback,
gfx::Image image) {
SkBitmap bitmap = image.AsBitmap();
......@@ -132,9 +131,11 @@ void ScreenManagerCrosapi::DidTakeSnapshot(SnapshotCallback callback,
uint8_t* base = static_cast<uint8_t*>(bitmap.getPixels());
std::vector<uint8_t> bytes(base, base + bitmap.computeByteSize());
crosapi::Bitmap snapshot;
Bitmap snapshot;
snapshot.width = bitmap.width();
snapshot.height = bitmap.height();
snapshot.pixels.swap(bytes);
std::move(callback).Run(std::move(snapshot));
}
} // namespace crosapi
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_CROSAPI_SCREEN_MANAGER_CROSAPI_H_
#define CHROME_BROWSER_CHROMEOS_CROSAPI_SCREEN_MANAGER_CROSAPI_H_
#ifndef CHROME_BROWSER_CHROMEOS_CROSAPI_SCREEN_MANAGER_ASH_H_
#define CHROME_BROWSER_CHROMEOS_CROSAPI_SCREEN_MANAGER_ASH_H_
#include <stdint.h>
......@@ -17,21 +17,19 @@
#include "ui/gfx/image/image.h"
namespace crosapi {
struct Bitmap;
} // namespace crosapi
// This class is the ash-chrome implementation of the ScreenManager interface.
// This class must only be used from the main thread.
class ScreenManagerCrosapi : public crosapi::mojom::ScreenManager,
aura::WindowObserver {
class ScreenManagerAsh : public mojom::ScreenManager, aura::WindowObserver {
public:
ScreenManagerCrosapi();
ScreenManagerCrosapi(const ScreenManagerCrosapi&) = delete;
ScreenManagerCrosapi& operator=(const ScreenManagerCrosapi&) = delete;
~ScreenManagerCrosapi() override;
ScreenManagerAsh();
ScreenManagerAsh(const ScreenManagerAsh&) = delete;
ScreenManagerAsh& operator=(const ScreenManagerAsh&) = delete;
~ScreenManagerAsh() override;
void BindReceiver(
mojo::PendingReceiver<crosapi::mojom::ScreenManager> receiver);
void BindReceiver(mojo::PendingReceiver<mojom::ScreenManager> receiver);
// crosapi::mojom::ScreenManager:
void TakeScreenSnapshot(TakeScreenSnapshotCallback callback) override;
......@@ -46,7 +44,7 @@ class ScreenManagerCrosapi : public crosapi::mojom::ScreenManager,
void OnWindowDestroying(aura::Window* window) final;
private:
using SnapshotCallback = base::OnceCallback<void(const crosapi::Bitmap&)>;
using SnapshotCallback = base::OnceCallback<void(const Bitmap&)>;
void DidTakeSnapshot(SnapshotCallback callback, gfx::Image image);
// This class generates unique, non-reused IDs for windows on demand. The IDs
......@@ -63,9 +61,11 @@ class ScreenManagerCrosapi : public crosapi::mojom::ScreenManager,
// This class supports any number of connections. This allows the client to
// have multiple, potentially thread-affine, remotes. This is needed by
// WebRTC.
mojo::ReceiverSet<crosapi::mojom::ScreenManager> receivers_;
mojo::ReceiverSet<mojom::ScreenManager> receivers_;
base::WeakPtrFactory<ScreenManagerCrosapi> weak_factory_{this};
base::WeakPtrFactory<ScreenManagerAsh> weak_factory_{this};
};
#endif // CHROME_BROWSER_CHROMEOS_CROSAPI_SCREEN_MANAGER_CROSAPI_H_
} // namespace crosapi
#endif // CHROME_BROWSER_CHROMEOS_CROSAPI_SCREEN_MANAGER_ASH_H_
......@@ -7,7 +7,7 @@
#include "base/memory/scoped_refptr.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/chromeos/crosapi/screen_manager_crosapi.h"
#include "chrome/browser/chromeos/crosapi/screen_manager_ash.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
......@@ -18,32 +18,31 @@
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "ui/aura/window.h"
namespace crosapi {
namespace {
// This class tests that the ash-chrome implementation of the screen manager
// crosapi works properly.
class ScreenManagerCrosapiBrowserTest : public InProcessBrowserTest {
class ScreenManagerAshBrowserTest : public InProcessBrowserTest {
protected:
using SMRemote = mojo::Remote<crosapi::mojom::ScreenManager>;
using SMPendingRemote = mojo::PendingRemote<crosapi::mojom::ScreenManager>;
using SMPendingReceiver =
mojo::PendingReceiver<crosapi::mojom::ScreenManager>;
using SMRemote = mojo::Remote<mojom::ScreenManager>;
using SMPendingRemote = mojo::PendingRemote<mojom::ScreenManager>;
using SMPendingReceiver = mojo::PendingReceiver<mojom::ScreenManager>;
ScreenManagerCrosapiBrowserTest() = default;
ScreenManagerAshBrowserTest() = default;
ScreenManagerCrosapiBrowserTest(const ScreenManagerCrosapiBrowserTest&) =
ScreenManagerAshBrowserTest(const ScreenManagerAshBrowserTest&) = delete;
ScreenManagerAshBrowserTest& operator=(const ScreenManagerAshBrowserTest&) =
delete;
ScreenManagerCrosapiBrowserTest& operator=(
const ScreenManagerCrosapiBrowserTest&) = delete;
~ScreenManagerCrosapiBrowserTest() override {
~ScreenManagerAshBrowserTest() override {
background_sequence_->DeleteSoon(FROM_HERE,
std::move(screen_manager_remote_));
}
void SetUpOnMainThread() override {
// The implementation of screen manager is affine to this sequence.
screen_manager_ = std::make_unique<ScreenManagerCrosapi>();
screen_manager_ = std::make_unique<ScreenManagerAsh>();
SMPendingRemote pending_remote;
SMPendingReceiver pending_receiver =
......@@ -70,7 +69,7 @@ class ScreenManagerCrosapiBrowserTest : public InProcessBrowserTest {
}
// Affine to main sequence.
std::unique_ptr<ScreenManagerCrosapi> screen_manager_;
std::unique_ptr<ScreenManagerAsh> screen_manager_;
// A sequence that is allowed to block.
scoped_refptr<base::SequencedTaskRunner> background_sequence_;
......@@ -80,14 +79,14 @@ class ScreenManagerCrosapiBrowserTest : public InProcessBrowserTest {
};
// Tests that taking a screen snapshot works.
IN_PROC_BROWSER_TEST_F(ScreenManagerCrosapiBrowserTest, TakeScreenSnapshot) {
IN_PROC_BROWSER_TEST_F(ScreenManagerAshBrowserTest, TakeScreenSnapshot) {
base::RunLoop run_loop;
crosapi::Bitmap snapshot;
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, crosapi::Bitmap* snapshot) {
[](SMRemote* remote, Bitmap* snapshot) {
mojo::ScopedAllowSyncCallForTesting allow_sync;
(*remote)->TakeScreenSnapshot(snapshot);
},
......@@ -103,17 +102,17 @@ IN_PROC_BROWSER_TEST_F(ScreenManagerCrosapiBrowserTest, TakeScreenSnapshot) {
EXPECT_EQ(int{snapshot.height}, primary_window->bounds().height());
}
IN_PROC_BROWSER_TEST_F(ScreenManagerCrosapiBrowserTest, TakeWindowSnapshot) {
IN_PROC_BROWSER_TEST_F(ScreenManagerAshBrowserTest, TakeWindowSnapshot) {
base::RunLoop run_loop;
bool success;
crosapi::Bitmap snapshot;
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, crosapi::Bitmap* snapshot) {
[](SMRemote* remote, bool* success, Bitmap* snapshot) {
mojo::ScopedAllowSyncCallForTesting allow_sync;
std::vector<crosapi::mojom::WindowDetailsPtr> windows;
std::vector<mojom::WindowDetailsPtr> windows;
(*remote)->ListWindows(&windows);
// There should be exactly 1 window.
......@@ -136,3 +135,4 @@ IN_PROC_BROWSER_TEST_F(ScreenManagerCrosapiBrowserTest, TakeWindowSnapshot) {
}
} // namespace
} // namespace crosapi
......@@ -2162,9 +2162,8 @@ if (!is_android) {
# Browser tests for functionality that is only intended to be present in
# ash-chrome, not lacros-chrome.
if (is_chromeos && !chromeos_is_browser_only) {
sources += [
"../browser/chromeos/crosapi/screen_manager_crosapi_browsertest.cc",
]
sources +=
[ "../browser/chromeos/crosapi/screen_manager_ash_browsertest.cc" ]
}
if (is_chromeos) {
......
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