| Index: ash/mus/window_manager_application.cc
|
| diff --git a/ash/mus/window_manager_application.cc b/ash/mus/window_manager_application.cc
|
| index 20bb19be455f15f8d887a5907afa806d9386eb70..a6b85afd2f6b349311765f0afabfe852d8e93acf 100644
|
| --- a/ash/mus/window_manager_application.cc
|
| +++ b/ash/mus/window_manager_application.cc
|
| @@ -7,29 +7,27 @@
|
| #include <utility>
|
|
|
| #include "ash/mus/accelerator_registrar_impl.h"
|
| -#include "ash/mus/bridge/wm_lookup_mus.h"
|
| -#include "ash/mus/bridge/wm_shell_mus.h"
|
| #include "ash/mus/root_window_controller.h"
|
| #include "ash/mus/root_windows_observer.h"
|
| #include "ash/mus/shelf_layout_impl.h"
|
| #include "ash/mus/user_window_controller_impl.h"
|
| +#include "ash/mus/window_manager.h"
|
| #include "base/bind.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "components/mus/common/event_matcher_util.h"
|
| #include "components/mus/public/cpp/window.h"
|
| -#include "components/mus/public/interfaces/window_manager_factory.mojom.h"
|
| +#include "components/mus/public/cpp/window_tree_client.h"
|
| #include "services/shell/public/cpp/connection.h"
|
| #include "services/shell/public/cpp/connector.h"
|
| #include "services/tracing/public/cpp/tracing_impl.h"
|
| #include "ui/events/event.h"
|
| #include "ui/views/mus/aura_init.h"
|
| -#include "ui/views/mus/screen_mus.h"
|
|
|
| namespace ash {
|
| namespace mus {
|
|
|
| WindowManagerApplication::WindowManagerApplication()
|
| - : connector_(nullptr), window_manager_factory_binding_(this) {}
|
| + : connector_(nullptr), screenlock_state_listener_binding_(this) {}
|
|
|
| WindowManagerApplication::~WindowManagerApplication() {
|
| // AcceleratorRegistrarImpl removes an observer in its destructor. Destroy
|
| @@ -39,61 +37,9 @@ WindowManagerApplication::~WindowManagerApplication() {
|
| for (AcceleratorRegistrarImpl* registrar : accelerator_registrars)
|
| registrar->Destroy();
|
|
|
| - std::set<RootWindowController*> controllers(root_controllers_);
|
| - for (RootWindowController* controller : controllers)
|
| - controller->Destroy();
|
| -}
|
| -
|
| -std::set<RootWindowController*> WindowManagerApplication::GetRootControllers() {
|
| - std::set<RootWindowController*> root_controllers;
|
| - for (RootWindowController* controller : root_controllers_) {
|
| - if (controller->root())
|
| - root_controllers.insert(controller);
|
| - }
|
| - return root_controllers;
|
| -}
|
| -
|
| -void WindowManagerApplication::OnRootWindowControllerGotRoot(
|
| - RootWindowController* root_controller) {
|
| - if (shell_)
|
| - return; // |root_controller| is the > 1 root, nothing to do.
|
| -
|
| - if (connector_)
|
| - aura_init_.reset(new views::AuraInit(connector_, "ash_mus_resources.pak"));
|
| -
|
| - shell_.reset(new WmShellMus(root_controller->root()->window_tree()));
|
| - lookup_.reset(new WmLookupMus);
|
| -}
|
| -
|
| -void WindowManagerApplication::OnRootWindowControllerDoneInit(
|
| - RootWindowController* root_controller) {
|
| - if (!screen_) {
|
| - std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr));
|
| - screen->Init(connector_);
|
| - screen_ = std::move(screen);
|
| - }
|
| -
|
| - // TODO(msw): figure out if this should be per display, or global.
|
| - user_window_controller_->Initialize(root_controller);
|
| - for (auto& request : user_window_controller_requests_)
|
| - user_window_controller_bindings_.AddBinding(user_window_controller_.get(),
|
| - std::move(*request));
|
| - user_window_controller_requests_.clear();
|
| -
|
| - // TODO(msw): figure out if this should be per display, or global.
|
| - shelf_layout_->Initialize(root_controller);
|
| - for (auto& request : shelf_layout_requests_)
|
| - shelf_layout_bindings_.AddBinding(shelf_layout_.get(), std::move(*request));
|
| - shelf_layout_requests_.clear();
|
| -
|
| - FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_,
|
| - OnRootWindowControllerAdded(root_controller));
|
| -}
|
| -
|
| -void WindowManagerApplication::OnRootWindowDestroyed(
|
| - RootWindowController* root_controller) {
|
| - root_controllers_.erase(root_controller);
|
| - user_window_controller_.reset(nullptr);
|
| + // Destroy the WindowManager while still valid. This way we ensure
|
| + // OnWillDestroyRootWindowController() is called (if it hasn't been already).
|
| + window_manager_.reset();
|
| }
|
|
|
| void WindowManagerApplication::OnAccelerator(uint32_t id,
|
| @@ -106,49 +52,43 @@ void WindowManagerApplication::OnAccelerator(uint32_t id,
|
| }
|
| }
|
|
|
| -void WindowManagerApplication::AddRootWindowsObserver(
|
| - RootWindowsObserver* observer) {
|
| - root_windows_observers_.AddObserver(observer);
|
| -}
|
| -
|
| -void WindowManagerApplication::RemoveRootWindowsObserver(
|
| - RootWindowsObserver* observer) {
|
| - root_windows_observers_.RemoveObserver(observer);
|
| -}
|
| -
|
| void WindowManagerApplication::OnAcceleratorRegistrarDestroyed(
|
| AcceleratorRegistrarImpl* registrar) {
|
| accelerator_registrars_.erase(registrar);
|
| }
|
|
|
| -void WindowManagerApplication::AddRootWindowController(
|
| - RootWindowController* root_window_controller) {
|
| - root_controllers_.insert(root_window_controller);
|
| +void WindowManagerApplication::InitWindowManager(
|
| + ::mus::WindowTreeClient* window_tree_client) {
|
| + window_manager_->Init(window_tree_client);
|
| + window_manager_->AddRootWindowsObserver(this);
|
| }
|
|
|
| void WindowManagerApplication::Initialize(shell::Connector* connector,
|
| const shell::Identity& identity,
|
| uint32_t id) {
|
| connector_ = connector;
|
| - if (connector) {
|
| - tracing_.Initialize(connector, identity.name());
|
| + window_manager_.reset(new WindowManager(this, connector_));
|
|
|
| - ::mus::mojom::WindowManagerFactoryServicePtr wm_factory_service;
|
| - connector_->ConnectToInterface("mojo:mus", &wm_factory_service);
|
| - wm_factory_service->SetWindowManagerFactory(
|
| - window_manager_factory_binding_.CreateInterfacePtrAndBind());
|
| - }
|
| + aura_init_.reset(new views::AuraInit(connector_, "ash_mus_resources.pak"));
|
|
|
| - shelf_layout_.reset(new ShelfLayoutImpl);
|
| - user_window_controller_.reset(new UserWindowControllerImpl());
|
| + tracing_.Initialize(connector, identity.name());
|
| +
|
| + ::mus::WindowTreeClient* window_tree_client = new ::mus::WindowTreeClient(
|
| + window_manager_.get(), window_manager_.get(), nullptr);
|
| + window_tree_client->ConnectAsWindowManager(connector);
|
| +
|
| + InitWindowManager(window_tree_client);
|
| }
|
|
|
| bool WindowManagerApplication::AcceptConnection(shell::Connection* connection) {
|
| connection->AddInterface<mojom::ShelfLayout>(this);
|
| connection->AddInterface<mojom::UserWindowController>(this);
|
| connection->AddInterface<::mus::mojom::AcceleratorRegistrar>(this);
|
| - if (connection->GetRemoteIdentity().name() == "mojo:mash_session")
|
| + if (connection->GetRemoteIdentity().name() == "mojo:mash_session") {
|
| connection->GetInterface(&session_);
|
| + session_->AddScreenlockStateListener(
|
| + screenlock_state_listener_binding_.CreateInterfacePtrAndBind());
|
| + }
|
| return true;
|
| }
|
|
|
| @@ -156,7 +96,7 @@ void WindowManagerApplication::Create(
|
| shell::Connection* connection,
|
| mojo::InterfaceRequest<mojom::ShelfLayout> request) {
|
| // TODO(msw): Handle multiple shelves (one per display).
|
| - if (!root_controllers_.empty() && (*root_controllers_.begin())->root()) {
|
| + if (!window_manager_->GetRootWindowControllers().empty()) {
|
| shelf_layout_bindings_.AddBinding(shelf_layout_.get(), std::move(request));
|
| } else {
|
| shelf_layout_requests_.push_back(base::WrapUnique(
|
| @@ -167,7 +107,7 @@ void WindowManagerApplication::Create(
|
| void WindowManagerApplication::Create(
|
| shell::Connection* connection,
|
| mojo::InterfaceRequest<mojom::UserWindowController> request) {
|
| - if (!root_controllers_.empty() && (*root_controllers_.begin())->root()) {
|
| + if (!window_manager_->GetRootWindowControllers().empty()) {
|
| user_window_controller_bindings_.AddBinding(user_window_controller_.get(),
|
| std::move(request));
|
| } else {
|
| @@ -190,16 +130,48 @@ void WindowManagerApplication::Create(
|
| accelerator_registrar_count = 0;
|
| }
|
| accelerator_registrars_.insert(new AcceleratorRegistrarImpl(
|
| - this, ++accelerator_registrar_count, std::move(request),
|
| + window_manager_.get(), ++accelerator_registrar_count, std::move(request),
|
| base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed,
|
| base::Unretained(this))));
|
| }
|
|
|
| -void WindowManagerApplication::CreateWindowManager(
|
| - ::mus::mojom::DisplayPtr display,
|
| - mojo::InterfaceRequest<::mus::mojom::WindowTreeClient> client_request) {
|
| - AddRootWindowController(RootWindowController::CreateFromDisplay(
|
| - this, std::move(display), std::move(client_request)));
|
| +void WindowManagerApplication::ScreenlockStateChanged(bool locked) {
|
| + window_manager_->SetScreenLocked(locked);
|
| +}
|
| +
|
| +void WindowManagerApplication::OnRootWindowControllerAdded(
|
| + RootWindowController* controller) {
|
| + if (user_window_controller_)
|
| + return;
|
| +
|
| + // TODO(sky): |shelf_layout_| and |user_window_controller_| should really
|
| + // be owned by WindowManager and/or RootWindowController. But this code is
|
| + // temporary while migrating away from sysui.
|
| +
|
| + shelf_layout_.reset(new ShelfLayoutImpl);
|
| + user_window_controller_.reset(new UserWindowControllerImpl());
|
| +
|
| + // TODO(msw): figure out if this should be per display, or global.
|
| + user_window_controller_->Initialize(controller);
|
| + for (auto& request : user_window_controller_requests_)
|
| + user_window_controller_bindings_.AddBinding(user_window_controller_.get(),
|
| + std::move(*request));
|
| + user_window_controller_requests_.clear();
|
| +
|
| + // TODO(msw): figure out if this should be per display, or global.
|
| + shelf_layout_->Initialize(controller);
|
| + for (auto& request : shelf_layout_requests_)
|
| + shelf_layout_bindings_.AddBinding(shelf_layout_.get(), std::move(*request));
|
| + shelf_layout_requests_.clear();
|
| +}
|
| +
|
| +void WindowManagerApplication::OnWillDestroyRootWindowController(
|
| + RootWindowController* controller) {
|
| + // TODO(msw): this isn't right, ownership should belong in WindowManager
|
| + // and/or RootWindowController. But this is temporary until we get rid of
|
| + // sysui.
|
| + shelf_layout_.reset();
|
| + user_window_controller_.reset();
|
| }
|
|
|
| } // namespace mus
|
|
|