Commit 890faece authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

Makes ws2/WindowService a real service

This way it can be responsible for various interfaces that need to be
registered. This also makes it easier to use in consuming code. I
deleted from the README with the expectation that I'll update it later
on once things are further along.

BUG=837689
TEST=none

Change-Id: I07f8f2902d02a6f2a8183bf141855494661a33d3
Reviewed-on: https://chromium-review.googlesource.com/1042879
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555916}
parent 968d171c
......@@ -16,6 +16,7 @@
#include "services/service_manager/public/cpp/service_context.h"
#include "services/service_manager/public/cpp/service_runner.h"
#include "services/ui/public/interfaces/window_tree_host_factory.mojom.h"
#include "services/ui/ws2/gpu_support.h"
#include "services/ui/ws2/window_service.h"
#include "services/ui/ws2/window_service_client.h"
#include "services/ui/ws2/window_service_client_binding.h"
......@@ -138,7 +139,7 @@ class TestWindowService : public service_manager::Service,
gfx::RegisterPathProvider();
ui::RegisterPathProvider();
window_service_ = std::make_unique<ws2::WindowService>(this);
window_service_ = std::make_unique<ws2::WindowService>(this, nullptr);
ui::ContextFactory* context_factory = nullptr;
ui::ContextFactoryPrivate* context_factory_private = nullptr;
......
......@@ -19,6 +19,7 @@ component("lib") {
# TODO: client_root should be internal and moved to a different target.
"client_root.cc",
"client_root.h",
"gpu_support.h",
"ids.h",
# TODO: window_data should be internal and moved to a different target.
......@@ -38,7 +39,9 @@ component("lib") {
]
public_deps = [
"//components/discardable_memory/public/interfaces",
"//components/viz/host",
"//services/service_manager/public/cpp",
"//services/ui/common:mus_common",
"//services/ui/public/interfaces",
"//ui/aura",
......
This directory contains the code for building a Window Service
implementation on top of an existing Aura hierarchy. There are two
distinct ways of attaching clients to the WindowService:
+ With a WindowTreeFactory. This class provides an implementation of
mojom::WindowTreeFactory that internally creates
WindowServiceClientBindings for each mojom::WindowTreeRequest. The
following shows how to do this:
```cpp
WindowService window_service;
WindowTreeFactory window_tree_factory(&window_service);
service_manager::BinderRegistry registry;
registry.AddInterface<mojom::WindowTreeFactory>(
base::BindRepeating(&WindowTreeFactory::AddBinding,
base::Unretained(&window_tree_factory)));
```
+ Create a WindowServiceClientBinding to embed a client in a
Window. This is useful when obtaining mojom::WindowTreeClient
through some other means (perhaps another mojo api):
```cpp
WindowService window_service;
aura::Window* window_to_embed_client_in;
mojom::WindowTreeClientPtr window_tree_client;
WindowServiceClientBinding binding;
// This is Run() when the connection to the client is lost. Typically this
// signal is used to delete the WindowServiceClientBinding.
base::Closure connection_lost_callback;
binding.InitForEmbed(&window_service,
std::move(window_tree_client),
window_to_embed_client_in,
std::move(connection_lost_callback));
```
implementation on top of an existing Aura hierarchy.
Each client is managed by a WindowServiceClient. WindowServiceClient
implements the WindowTree implementation that is passed to the
......@@ -40,4 +8,4 @@ client is embedded in, as well as a ClientRoot for all top-level
window requests.
Clients use the WindowService by configuring Aura with a mode of
mus. See aura::Env::Mode for details.
MUS. See aura::Env::Mode for details.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_UI_WS2_GPU_SUPPORT_H_
#define SERVICES_UI_WS2_GPU_SUPPORT_H_
#include "base/component_export.h"
#include "base/memory/scoped_refptr.h"
#include "components/discardable_memory/public/interfaces/discardable_shared_memory_manager.mojom.h"
#include "services/ui/public/interfaces/gpu.mojom.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace ui {
namespace ws2 {
// GpuSupport provides the functions needed for gpu related functionality. It is
// expected this class is bound to functions in content that do this. Once Viz
// moves out of content, this class can be removed.
class COMPONENT_EXPORT(WINDOW_SERVICE) GpuSupport {
public:
virtual ~GpuSupport() {}
// Returns the task runner used to bind gpu related interfaces on. This is
// typically the io-thread.
virtual scoped_refptr<base::SingleThreadTaskRunner> GetGpuTaskRunner() = 0;
// The Bind functions are called when a client requests a gpu related
// interface.
virtual void BindDiscardableSharedMemoryManagerOnGpuTaskRunner(
discardable_memory::mojom::DiscardableSharedMemoryManagerRequest
request) = 0;
virtual void BindGpuRequestOnGpuTaskRunner(ui::mojom::GpuRequest request) = 0;
};
} // namespace ws2
} // namespace ui
#endif // SERVICES_UI_WS2_GPU_SUPPORT_H_
......@@ -4,14 +4,20 @@
#include "services/ui/ws2/window_service.h"
#include "base/bind.h"
#include "base/single_thread_task_runner.h"
#include "services/ui/ws2/gpu_support.h"
#include "services/ui/ws2/window_data.h"
#include "services/ui/ws2/window_service_client.h"
#include "services/ui/ws2/window_service_delegate.h"
#include "services/ui/ws2/window_tree_factory.h"
namespace ui {
namespace ws2 {
WindowService::WindowService(WindowServiceDelegate* delegate)
: delegate_(delegate) {}
WindowService::WindowService(WindowServiceDelegate* delegate,
std::unique_ptr<GpuSupport> gpu_support)
: delegate_(delegate), gpu_support_(std::move(gpu_support)) {}
WindowService::~WindowService() {}
......@@ -36,5 +42,59 @@ std::unique_ptr<WindowServiceClient> WindowService::CreateWindowServiceClient(
this, client_id, window_tree_client, intercepts_events);
}
void WindowService::OnStart() {
window_tree_factory_ = std::make_unique<WindowTreeFactory>(this);
registry_.AddInterface(base::BindRepeating(
&WindowService::BindClipboardRequest, base::Unretained(this)));
registry_.AddInterface(base::BindRepeating(
&WindowService::BindDisplayManagerRequest, base::Unretained(this)));
registry_.AddInterface(base::BindRepeating(
&WindowService::BindImeDriverRequest, base::Unretained(this)));
registry_.AddInterface(base::BindRepeating(
&WindowService::BindWindowTreeFactoryRequest, base::Unretained(this)));
// |gpu_support_| may be null in tests.
if (gpu_support_) {
registry_.AddInterface(
base::BindRepeating(
&GpuSupport::BindDiscardableSharedMemoryManagerOnGpuTaskRunner,
base::Unretained(gpu_support_.get())),
gpu_support_->GetGpuTaskRunner());
registry_.AddInterface(
base::BindRepeating(&GpuSupport::BindGpuRequestOnGpuTaskRunner,
base::Unretained(gpu_support_.get())),
gpu_support_->GetGpuTaskRunner());
}
}
void WindowService::OnBindInterface(
const service_manager::BindSourceInfo& remote_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle handle) {
registry_.BindInterface(interface_name, std::move(handle));
}
void WindowService::BindClipboardRequest(mojom::ClipboardRequest request) {
// TODO: https://crbug.com/839591.
NOTIMPLEMENTED();
}
void WindowService::BindDisplayManagerRequest(
mojom::DisplayManagerRequest request) {
// TODO: https://crbug.com/839592.
NOTIMPLEMENTED();
}
void WindowService::BindImeDriverRequest(mojom::IMEDriverRequest request) {
// TODO: https://crbug.com/837710.
NOTIMPLEMENTED();
}
void WindowService::BindWindowTreeFactoryRequest(
ui::mojom::WindowTreeFactoryRequest request) {
window_tree_factory_->AddBinding(std::move(request));
}
} // namespace ws2
} // namespace ui
......@@ -9,6 +9,12 @@
#include "base/component_export.h"
#include "base/macros.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/service.h"
#include "services/ui/public/interfaces/clipboard.mojom.h"
#include "services/ui/public/interfaces/display_manager.mojom.h"
#include "services/ui/public/interfaces/ime/ime.mojom.h"
#include "services/ui/public/interfaces/window_tree.mojom.h"
#include "services/ui/ws2/ids.h"
namespace aura {
......@@ -23,19 +29,23 @@ class WindowTreeClient;
namespace ws2 {
class GpuSupport;
class WindowData;
class WindowServiceClient;
class WindowServiceDelegate;
class WindowTreeFactory;
// WindowService is the entry point into providing an implementation of
// the ui::mojom::WindowTree related mojoms on top of an aura Window hierarchy.
// A WindowServiceClient is created for each client. Typically you'll
// also create a WindowTreeFactory to handle incoming
// mojom::WindowTreeFactoryRequests.
class COMPONENT_EXPORT(WINDOW_SERVICE) WindowService {
class COMPONENT_EXPORT(WINDOW_SERVICE) WindowService
: public service_manager::Service {
public:
explicit WindowService(WindowServiceDelegate* delegate);
~WindowService();
WindowService(WindowServiceDelegate* delegate,
std::unique_ptr<GpuSupport> gpu_support);
~WindowService() override;
// Gets the WindowData for |window|, creating if necessary.
WindowData* GetWindowDataForWindowCreateIfNecessary(aura::Window* window);
......@@ -48,15 +58,33 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowService {
WindowServiceDelegate* delegate() { return delegate_; }
// service_manager::Service:
void OnStart() override;
void OnBindInterface(const service_manager::BindSourceInfo& remote_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle handle) override;
private:
void BindClipboardRequest(mojom::ClipboardRequest request);
void BindDisplayManagerRequest(mojom::DisplayManagerRequest request);
void BindImeDriverRequest(mojom::IMEDriverRequest request);
void BindWindowTreeFactoryRequest(
ui::mojom::WindowTreeFactoryRequest request);
WindowServiceDelegate* delegate_;
std::unique_ptr<GpuSupport> gpu_support_;
service_manager::BinderRegistry registry_;
std::unique_ptr<WindowTreeFactory> window_tree_factory_;
// Id for the next WindowServiceClient.
ClientSpecificId next_client_id_ = kWindowServerClientId + 1;
// Id used for the next window created locally that is exposed to clients.
ClientSpecificId next_window_id_ = 1;
WindowServiceDelegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(WindowService);
};
......
......@@ -8,6 +8,7 @@
#include <stdint.h>
#include "base/test/scoped_task_environment.h"
#include "services/ui/ws2/gpu_support.h"
#include "services/ui/ws2/test_window_service_delegate.h"
#include "services/ui/ws2/test_window_tree_client.h"
#include "services/ui/ws2/window_service.h"
......@@ -49,7 +50,7 @@ class WindowServiceTestHelper {
base::test::ScopedTaskEnvironment::MainThreadType::UI};
aura::test::AuraTestHelper aura_test_helper_;
TestWindowServiceDelegate delegate_;
WindowService service_{&delegate_};
WindowService service_{&delegate_, nullptr};
DISALLOW_COPY_AND_ASSIGN(WindowServiceTestHelper);
};
......
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