Commit b56f5252 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Update DesktopMediaListAsh to show only windows or only screens

Windows and Screens are shown in separate views in the desktop capture
picker UI, so we no longer need both types of sources in a single list.

Bug: 728866
Change-Id: I96df72f2920b0b5b9ebc3bbc6adef1ef939a1a64
Reviewed-on: https://chromium-review.googlesource.com/527772
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarZijie He <zijiehe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478385}
parent cdaa8aee
......@@ -149,8 +149,8 @@ bool DesktopCaptureChooseDesktopMediaFunctionBase::Execute(
// Create a screens list.
if (show_screens) {
#if defined(USE_ASH)
screen_list =
base::MakeUnique<DesktopMediaListAsh>(DesktopMediaListAsh::SCREENS);
screen_list = base::MakeUnique<DesktopMediaListAsh>(
content::DesktopMediaID::TYPE_SCREEN);
#else // !defined(USE_ASH)
screen_list = base::MakeUnique<NativeDesktopMediaList>(
content::DesktopMediaID::TYPE_SCREEN,
......@@ -161,8 +161,8 @@ bool DesktopCaptureChooseDesktopMediaFunctionBase::Execute(
// Create a windows list.
if (show_windows) {
#if defined(USE_ASH)
window_list =
base::MakeUnique<DesktopMediaListAsh>(DesktopMediaListAsh::WINDOWS);
window_list = base::MakeUnique<DesktopMediaListAsh>(
content::DesktopMediaID::TYPE_WINDOW);
#else // !defined(USE_ASH)
window_list = base::MakeUnique<NativeDesktopMediaList>(
content::DesktopMediaID::TYPE_WINDOW,
......
......@@ -15,6 +15,7 @@
#include "ui/snapshot/snapshot.h"
using content::BrowserThread;
using content::DesktopMediaID;
namespace {
......@@ -23,12 +24,15 @@ const int kDefaultUpdatePeriod = 500;
} // namespace
DesktopMediaListAsh::DesktopMediaListAsh(int source_types)
DesktopMediaListAsh::DesktopMediaListAsh(content::DesktopMediaID::Type type)
: DesktopMediaListBase(
base::TimeDelta::FromMilliseconds(kDefaultUpdatePeriod)),
source_types_(source_types),
type_(type),
pending_window_capture_requests_(0),
weak_factory_(this) {}
weak_factory_(this) {
DCHECK(type == content::DesktopMediaID::TYPE_SCREEN ||
type == content::DesktopMediaID::TYPE_WINDOW);
}
DesktopMediaListAsh::~DesktopMediaListAsh() {}
......@@ -70,7 +74,7 @@ void DesktopMediaListAsh::EnumerateSources(
aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
for (size_t i = 0; i < root_windows.size(); ++i) {
if (source_types_ & SCREENS) {
if (type_ == content::DesktopMediaID::TYPE_SCREEN) {
SourceDescription screen_source(
content::DesktopMediaID::RegisterAuraWindow(
content::DesktopMediaID::TYPE_SCREEN, root_windows[i]),
......@@ -98,9 +102,7 @@ void DesktopMediaListAsh::EnumerateSources(
}
CaptureThumbnail(screen_source.id, root_windows[i]);
}
if (source_types_ & WINDOWS) {
} else {
EnumerateWindowsForRoot(
sources, root_windows[i], ash::kShellWindowId_DefaultContainer);
EnumerateWindowsForRoot(
......
......@@ -21,12 +21,7 @@ class Image;
// native windows.
class DesktopMediaListAsh : public DesktopMediaListBase {
public:
enum SourceTypes {
SCREENS = 1,
WINDOWS = 2,
};
explicit DesktopMediaListAsh(int source_types);
explicit DesktopMediaListAsh(content::DesktopMediaID::Type type);
~DesktopMediaListAsh() override;
private:
......@@ -42,7 +37,7 @@ class DesktopMediaListAsh : public DesktopMediaListBase {
void OnThumbnailCaptured(content::DesktopMediaID id,
const gfx::Image& image);
int source_types_;
const content::DesktopMediaID::Type type_;
int pending_window_capture_requests_;
......
......@@ -44,8 +44,8 @@ class DesktopMediaListAshTest : public ash::test::AshTestBase {
ash::test::AshTestBase::TearDown();
}
void CreateList(int source_types) {
list_.reset(new DesktopMediaListAsh(source_types));
void CreateList(content::DesktopMediaID::Type type) {
list_.reset(new DesktopMediaListAsh(type));
list_->SetThumbnailSize(gfx::Size(kThumbnailSize, kThumbnailSize));
// Set update period to reduce the time it takes to run tests.
......@@ -63,40 +63,8 @@ ACTION(QuitMessageLoop) {
FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
}
TEST_F(DesktopMediaListAshTest, Screen) {
CreateList(DesktopMediaListAsh::SCREENS | DesktopMediaListAsh::WINDOWS);
EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 0));
EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0))
.WillOnce(QuitMessageLoop())
.WillRepeatedly(DoDefault());
list_->StartUpdating(&observer_);
base::RunLoop().Run();
}
TEST_F(DesktopMediaListAshTest, OneWindow) {
CreateList(DesktopMediaListAsh::SCREENS | DesktopMediaListAsh::WINDOWS);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 0));
EXPECT_CALL(observer_, OnSourceAdded(list_.get(), 1));
EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 0))
.Times(AtLeast(1));
EXPECT_CALL(observer_, OnSourceThumbnailChanged(list_.get(), 1))
.WillOnce(QuitMessageLoop())
.WillRepeatedly(DoDefault());
EXPECT_CALL(observer_, OnSourceRemoved(list_.get(), 1))
.WillOnce(QuitMessageLoop());
list_->StartUpdating(&observer_);
base::RunLoop().Run();
window.reset();
base::RunLoop().Run();
}
TEST_F(DesktopMediaListAshTest, ScreenOnly) {
CreateList(DesktopMediaListAsh::SCREENS);
CreateList(content::DesktopMediaID::TYPE_SCREEN);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
......@@ -110,7 +78,7 @@ TEST_F(DesktopMediaListAshTest, ScreenOnly) {
}
TEST_F(DesktopMediaListAshTest, WindowOnly) {
CreateList(DesktopMediaListAsh::WINDOWS);
CreateList(content::DesktopMediaID::TYPE_WINDOW);
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
......
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