1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/multi_user/test_multi_user_window_manager.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_helper.h"
#include "chrome/browser/ui/browser_window.h"
#include "components/account_id/account_id.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"
TestMultiUserWindowManager::~TestMultiUserWindowManager() {
// This object is owned by the MultiUserWindowManager since the
// SetInstanceForTest call. As such no uninstall is required.
}
// static
TestMultiUserWindowManager* TestMultiUserWindowManager::Create(
Browser* visiting_browser,
const AccountId& desktop_owner) {
// Must use WrapUnique() as constructor is private.
std::unique_ptr<TestMultiUserWindowManager> window_manager = base::WrapUnique(
new TestMultiUserWindowManager(visiting_browser, desktop_owner));
TestMultiUserWindowManager* raw_window_manager = window_manager.get();
MultiUserWindowManagerHelper::CreateInstanceForTest(
std::move(window_manager));
return raw_window_manager;
}
void TestMultiUserWindowManager::SetWindowOwner(aura::Window* window,
const AccountId& account_id) {
NOTREACHED();
}
const AccountId& TestMultiUserWindowManager::GetWindowOwner(
const aura::Window* window) const {
// No matter which window will get queried - all browsers belong to the
// original browser's user.
return browser_owner_;
}
void TestMultiUserWindowManager::ShowWindowForUser(
aura::Window* window,
const AccountId& account_id) {
// This class is only able to handle one additional window <-> user
// association beside the creation parameters.
// If no association has yet been requested remember it now.
if (browser_owner_ != account_id) {
DCHECK(!created_window_);
}
created_window_ = window;
created_window_shown_for_ = account_id;
if (browser_window_ == window) {
desktop_owner_ = account_id;
}
if (account_id == current_account_id_) {
return;
}
// Change the visibility of the window to update the view recursively.
views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
widget->Hide();
widget->Show();
current_account_id_ = account_id;
}
bool TestMultiUserWindowManager::AreWindowsSharedAmongUsers() const {
return browser_owner_ != desktop_owner_;
}
std::set<AccountId> TestMultiUserWindowManager::GetOwnersOfVisibleWindows()
const {
return {};
}
const AccountId& TestMultiUserWindowManager::GetUserPresentingWindow(
const aura::Window* window) const {
if (window == browser_window_) {
return desktop_owner_;
}
if (created_window_ && window == created_window_) {
return created_window_shown_for_;
}
// We can come here before the window gets registered.
return browser_owner_;
}
const AccountId& TestMultiUserWindowManager::CurrentAccountId() const {
return current_account_id_;
}
TestMultiUserWindowManager::TestMultiUserWindowManager(
Browser* visiting_browser,
const AccountId& desktop_owner)
: browser_window_(visiting_browser->window()->GetNativeWindow()),
browser_owner_(multi_user_util::GetAccountIdFromProfile(
visiting_browser->profile())),
desktop_owner_(desktop_owner),
created_window_shown_for_(browser_owner_),
current_account_id_(desktop_owner) {}
|