Skip to content

Commit

Permalink
chromeos: more MultiUserWindowManager refactoring
Browse files Browse the repository at this point in the history
This ends up promoting most of what was in MultiUserWindowManagerClientImpl
into MultiUserWindowManagerImpl. This is still a work in progress. I'll send
around a separate email with where I think this should go.

BUG=958168
TEST=covered by tests


Change-Id: Ia7283756624f3156e5ada587c9e0659aed953483
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1591193
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#656178}
  • Loading branch information
Scott Violet authored and Commit Bot committed May 2, 2019
1 parent a01cbcf commit a0f15cb
Show file tree
Hide file tree
Showing 21 changed files with 234 additions and 852 deletions.
5 changes: 2 additions & 3 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ component("ash") {
"frame/non_client_frame_view_ash.h",
"frame/wide_frame_view.h",
"magnifier/magnification_controller.h",
"multi_user/multi_user_window_manager_delegate_classic.h",

# TODO: move MultiUserWindowManager (and delegate) to sources:
# https://crbug.com/756085
"multi_user/multi_user_window_manager_impl.h",
"new_window_controller.h",
"public/cpp/multi_user_window_manager.h",
"public/cpp/multi_user_window_manager_delegate.h",
"root_window_controller.h",
"screenshot_delegate.h",
"session/session_controller.h",
Expand Down Expand Up @@ -1269,8 +1270,6 @@ component("ash") {
"ws/ash_gpu_interface_provider.h",
"ws/ash_window_manager.cc",
"ws/ash_window_manager.h",
"ws/multi_user_window_manager_bridge.cc",
"ws/multi_user_window_manager_bridge.h",
"ws/window_lookup.cc",
"ws/window_service_delegate_impl.cc",
"ws/window_service_delegate_impl.h",
Expand Down
41 changes: 0 additions & 41 deletions ash/multi_user/multi_user_window_manager_delegate_classic.h

This file was deleted.

96 changes: 49 additions & 47 deletions ash/multi_user/multi_user_window_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
#include <vector>

#include "ash/media/media_controller.h"
#include "ash/multi_user/multi_user_window_manager_delegate_classic.h"
#include "ash/multi_user/user_switch_animator.h"
#include "ash/public/cpp/multi_user_window_manager_delegate.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/auto_reset.h"
#include "base/macros.h"
#include "ui/aura/mus/window_mus.h"
#include "ui/aura/mus/window_tree_client.h"
#include "ui/aura/window.h"
#include "ui/base/ui_base_types.h"
#include "ui/events/event.h"
Expand Down Expand Up @@ -116,22 +114,16 @@ class AnimationSetter {
};

MultiUserWindowManagerImpl::WindowEntry::WindowEntry(
const AccountId& account_id,
base::Optional<ws::Id> window_id)
: owner_(account_id),
show_for_user_(account_id),
window_id_(std::move(window_id)),
from_window_service_(window_id.has_value()) {}
const AccountId& account_id)
: owner_(account_id), show_for_user_(account_id) {}

MultiUserWindowManagerImpl::WindowEntry::~WindowEntry() = default;

MultiUserWindowManagerImpl::MultiUserWindowManagerImpl(
mojom::MultiUserWindowManagerClient* client,
MultiUserWindowManagerDelegateClassic* classic_delegate,
MultiUserWindowManagerDelegate* delegate,
const AccountId& account_id)
: client_(client),
classic_delegate_(classic_delegate),
current_account_id_(account_id) {
: delegate_(delegate), current_account_id_(account_id) {
DCHECK(delegate_);
g_instance = this;
Shell::Get()->tablet_mode_controller()->AddObserver(this);
Shell::Get()->session_controller()->AddObserver(this);
Expand Down Expand Up @@ -163,21 +155,9 @@ MultiUserWindowManagerImpl* MultiUserWindowManagerImpl::Get() {
return g_instance;
}

void MultiUserWindowManagerImpl::SetClient(
mojom::MultiUserWindowManagerClient* client) {
client_ = client;

// Window ids are unique to a particular client. If the client changes, drop
// any existing ids.
for (auto& pair : window_to_entry_)
pair.second->reset_window_id();
}

void MultiUserWindowManagerImpl::SetWindowOwner(
aura::Window* window,
const AccountId& account_id,
bool show_for_current_user,
base::Optional<ws::Id> window_id) {
void MultiUserWindowManagerImpl::SetWindowOwner(aura::Window* window,
const AccountId& account_id,
bool show_for_current_user) {
// Make sure the window is valid and there was no owner yet.
DCHECK(window);
DCHECK(account_id.is_valid());
Expand All @@ -191,7 +171,7 @@ void MultiUserWindowManagerImpl::SetWindowOwner(

DCHECK(GetWindowOwner(window).empty());
std::unique_ptr<WindowEntry> window_entry_ptr =
std::make_unique<WindowEntry>(account_id, std::move(window_id));
std::make_unique<WindowEntry>(account_id);
WindowEntry* window_entry = window_entry_ptr.get();
window_to_entry_[window] = std::move(window_entry_ptr);

Expand All @@ -215,12 +195,6 @@ void MultiUserWindowManagerImpl::SetWindowOwner(
SetWindowVisibility(window, false);
}

const AccountId& MultiUserWindowManagerImpl::GetWindowOwner(
aura::Window* window) const {
WindowToEntryMap::const_iterator it = window_to_entry_.find(window);
return it != window_to_entry_.end() ? it->second->owner() : EmptyAccountId();
}

void MultiUserWindowManagerImpl::ShowWindowForUser(
aura::Window* window,
const AccountId& account_id) {
Expand All @@ -237,6 +211,13 @@ void MultiUserWindowManagerImpl::ShowWindowForUser(
Shell::Get()->session_controller()->SwitchActiveUser(account_id);
}

const AccountId& MultiUserWindowManagerImpl::GetWindowOwner(
const aura::Window* window) const {
WindowToEntryMap::const_iterator it =
window_to_entry_.find(const_cast<aura::Window*>(window));
return it != window_to_entry_.end() ? it->second->owner() : EmptyAccountId();
}

bool MultiUserWindowManagerImpl::AreWindowsSharedAmongUsers() const {
for (auto& window_pair : window_to_entry_) {
if (window_pair.second->owner() != window_pair.second->show_for_user())
Expand All @@ -245,6 +226,29 @@ bool MultiUserWindowManagerImpl::AreWindowsSharedAmongUsers() const {
return false;
}

std::set<AccountId> MultiUserWindowManagerImpl::GetOwnersOfVisibleWindows()
const {
std::set<AccountId> result;
for (auto& window_pair : window_to_entry_) {
if (window_pair.first->IsVisible())
result.insert(window_pair.second->owner());
}
return result;
}

const AccountId& MultiUserWindowManagerImpl::GetUserPresentingWindow(
const aura::Window* window) const {
auto iter = window_to_entry_.find(const_cast<aura::Window*>(window));
// If the window is not owned by anyone it is shown on all desktops and we
// return the empty string.
return (iter == window_to_entry_.end()) ? EmptyAccountId()
: iter->second->show_for_user();
}

const AccountId& MultiUserWindowManagerImpl::CurrentAccountId() const {
return current_account_id_;
}

bool MultiUserWindowManagerImpl::IsWindowOnDesktopOfUser(
aura::Window* window,
const AccountId& account_id) const {
Expand Down Expand Up @@ -277,9 +281,6 @@ void MultiUserWindowManagerImpl::OnActiveUserSessionChanged(
// This needs to be set before the animation starts.
current_account_id_ = account_id;

if (client_)
client_->OnWillSwitchActiveAccount(current_account_id_);

// Here to avoid a very nasty race condition, we must destruct any previously
// created animation before creating a new one. Otherwise, the newly
// constructed will hide all windows of the old user in the first step of the
Expand Down Expand Up @@ -420,14 +421,8 @@ bool MultiUserWindowManagerImpl::ShowWindowForUserIntern(
SetWindowVisibility(window, false, kTeleportAnimationTime);
}

// Notify entry change.
if (!window_entry->from_window_service()) {
classic_delegate_->OnOwnerEntryChanged(window, account_id, minimized,
teleported);
} else if (client_ && window_entry->window_id().has_value()) {
client_->OnWindowOwnerEntryChanged(*window_entry->window_id(), account_id,
minimized, teleported);
}
delegate_->OnWindowOwnerEntryChanged(window, account_id, minimized,
teleported);
return true;
}

Expand Down Expand Up @@ -576,4 +571,11 @@ base::TimeDelta MultiUserWindowManagerImpl::GetAdjustedAnimationTime(
: base::TimeDelta());
}

// static
std::unique_ptr<MultiUserWindowManager> MultiUserWindowManager::Create(
MultiUserWindowManagerDelegate* delegate,
const AccountId& account_id) {
return std::make_unique<MultiUserWindowManagerImpl>(delegate, account_id);
}

} // namespace ash
Loading

0 comments on commit a0f15cb

Please sign in to comment.