Commit 523bf0eb authored by kylechar's avatar kylechar Committed by Commit bot

Enable InputDeviceServer/InputDeviceClient in mash.

Remove the stub version of DeviceDataManager that is created in the
browser and ash processes when running under mash. The stub version
never has any input-device information because the real
DeviceDataManager is in the mus process.

Create InputDeviceClient inside ash and chrome which connects to mus and
receives input-device updates via Mojo IPC.

The mus process starts InputDeviceServer to listen for observers and
update them when new input-device information is available.

BUG=601981

Review-Url: https://codereview.chromium.org/2058853002
Cr-Commit-Position: refs/heads/master@{#400746}
parent 811c31fb
......@@ -39,6 +39,7 @@ source_set("lib") {
"//cc/surfaces",
"//components/mus/common:mus_common",
"//components/mus/public/cpp",
"//components/mus/public/cpp/input_devices",
"//components/mus/public/interfaces",
"//components/user_manager",
"//components/wallpaper",
......
......@@ -31,6 +31,7 @@
#include "base/path_service.h"
#include "base/threading/sequenced_worker_pool.h"
#include "components/mus/public/cpp/property_type_converters.h"
#include "components/mus/public/interfaces/input_devices/input_device_server.mojom.h"
#include "services/catalog/public/cpp/resource_loader.h"
#include "services/shell/public/cpp/connector.h"
#include "ui/aura/env.h"
......@@ -49,7 +50,6 @@
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "ui/events/devices/device_data_manager.h"
#endif
using views::ViewsDelegate;
......@@ -282,7 +282,6 @@ class AshInit {
message_center::MessageCenter::Initialize();
#if defined(OS_CHROMEOS)
ui::DeviceDataManager::CreateInstance();
chromeos::DBusThreadManager::Initialize();
bluez::BluezDBusManager::Initialize(
chromeos::DBusThreadManager::Get()->GetSystemBus(),
......@@ -311,6 +310,10 @@ void SysUIApplication::Initialize(::shell::Connector* connector,
uint32_t id) {
ash_init_.reset(new AshInit());
ash_init_->Initialize(connector, identity);
mus::mojom::InputDeviceServerPtr server;
connector->ConnectToInterface("mojo:mus", &server);
input_device_client_.Connect(std::move(server));
}
bool SysUIApplication::AcceptConnection(::shell::Connection* connection) {
......
......@@ -9,6 +9,7 @@
#include "ash/sysui/public/interfaces/wallpaper.mojom.h"
#include "base/macros.h"
#include "components/mus/public/cpp/input_devices/input_device_client.h"
#include "mash/shelf/public/interfaces/shelf.mojom.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/shell/public/cpp/shell_client.h"
......@@ -49,6 +50,9 @@ class SysUIApplication
shelf_controller_bindings_;
mojo::BindingSet<mojom::WallpaperController> wallpaper_controller_bindings_;
// Subscribes to updates about input-devices.
::mus::InputDeviceClient input_device_client_;
DISALLOW_COPY_AND_ASSIGN(SysUIApplication);
};
......
......@@ -622,6 +622,7 @@ target(chrome_browser_target_type, "browser") {
]
deps += [
"//components/mus/public/cpp",
"//components/mus/public/cpp/input_devices",
"//content/public/common",
"//ui/aura",
"//ui/compositor",
......
......@@ -15,7 +15,10 @@
#endif
#if defined(USE_AURA) && defined(MOJO_SHELL_CLIENT)
#include "components/mus/public/cpp/input_devices/input_device_client.h"
#include "components/mus/public/interfaces/input_devices/input_device_server.mojom.h"
#include "content/public/common/mojo_shell_connection.h"
#include "services/shell/public/cpp/connector.h"
#include "services/shell/runner/common/client_util.h"
#include "ui/views/mus/window_manager_connection.h"
#endif
......@@ -51,6 +54,12 @@ void ChromeBrowserMainExtraPartsViews::PreProfileInit() {
content::MojoShellConnection* mojo_shell_connection =
content::MojoShellConnection::GetForProcess();
if (mojo_shell_connection && shell::ShellIsRemote()) {
input_device_client_.reset(new mus::InputDeviceClient());
mus::mojom::InputDeviceServerPtr server;
mojo_shell_connection->GetConnector()->ConnectToInterface("mojo:mus",
&server);
input_device_client_->Connect(std::move(server));
window_manager_connection_ = views::WindowManagerConnection::Create(
mojo_shell_connection->GetConnector(),
mojo_shell_connection->GetIdentity());
......
......@@ -10,6 +10,10 @@
#include "base/macros.h"
#include "chrome/browser/chrome_browser_main_extra_parts.h"
namespace mus {
class InputDeviceClient;
}
namespace views {
class ViewsDelegate;
class WindowManagerConnection;
......@@ -39,6 +43,9 @@ class ChromeBrowserMainExtraPartsViews : public ChromeBrowserMainExtraParts {
#endif
#if defined(USE_AURA) && defined(MOJO_SHELL_CLIENT)
std::unique_ptr<views::WindowManagerConnection> window_manager_connection_;
// Subscribes to updates about input-devices.
std::unique_ptr<mus::InputDeviceClient> input_device_client_;
#endif
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsViews);
......
......@@ -86,6 +86,7 @@ source_set("lib") {
"//components/mus/gles2",
"//components/mus/gpu",
"//components/mus/gpu/display_compositor",
"//components/mus/input_devices",
"//components/mus/public/interfaces",
"//components/mus/surfaces",
"//components/mus/ws:lib",
......
......@@ -23,13 +23,17 @@ InputDeviceServer::~InputDeviceServer() {
}
void InputDeviceServer::RegisterAsObserver() {
if (!manager_) {
if (!manager_ && ui::DeviceDataManager::HasInstance()) {
manager_ = ui::DeviceDataManager::GetInstance();
manager_->AddObserver(this);
}
}
void InputDeviceServer::RegisterInterface(shell::Connection* connection) {
bool InputDeviceServer::IsRegisteredAsObserver() const {
return manager_ != nullptr;
}
void InputDeviceServer::AddInterface(shell::Connection* connection) {
DCHECK(manager_);
connection->AddInterface<mojom::InputDeviceServer>(this);
}
......
......@@ -29,11 +29,13 @@ class InputDeviceServer
// Registers this instance as a local observer with DeviceDataManager.
void RegisterAsObserver();
bool IsRegisteredAsObserver() const;
// Registers interface with the shell connection so remote observers can
// connect. You should have already called RegisterAsObserver() to get
// local input-device event updates.
void RegisterInterface(shell::Connection* connection);
// Adds interface with the shell connection so remote observers can connect.
// You should have already called RegisterAsObserver() to get local
// input-device event updates and checked it was successful by calling
// IsRegisteredAsObserver().
void AddInterface(shell::Connection* connection);
// mojom::InputDeviceServer:
void AddObserver(mojom::InputDeviceObserverMojoPtr observer) override;
......
......@@ -11,6 +11,7 @@
"mus::mojom::DisplayManager",
"mus::mojom::Gpu",
"mus::mojom::GpuService",
"mus::mojom::InputDeviceServer",
"mus::mojom::WindowTreeFactory"
],
"test": [
......
......@@ -180,6 +180,11 @@ void MusApp::Initialize(shell::Connector* connector,
event_source_ = ui::PlatformEventSource::CreateDefault();
#endif
// This needs to happen after DeviceDataManager has been constructed. That
// happens either during OzonePlatform or PlatformEventSource initialization,
// so keep this line below both of those.
input_device_server_.RegisterAsObserver();
if (use_chrome_gpu_command_buffer_) {
GpuServiceMus::GetInstance();
} else {
......@@ -210,6 +215,11 @@ bool MusApp::AcceptConnection(Connection* connection) {
connection->AddInterface<Gpu>(this);
}
// On non-Linux platforms there will be no DeviceDataManager instance and no
// purpose in adding the Mojo interface to connect to.
if (input_device_server_.IsRegisteredAsObserver())
input_device_server_.AddInterface(connection);
return true;
}
......
......@@ -7,12 +7,14 @@
#include <stdint.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/mus/input_devices/input_device_server.h"
#include "components/mus/public/interfaces/clipboard.mojom.h"
#include "components/mus/public/interfaces/display.mojom.h"
#include "components/mus/public/interfaces/gpu.mojom.h"
......@@ -151,6 +153,9 @@ class MusApp
UserIdToUserState user_id_to_user_state_;
// Provides input-device information via Mojo IPC.
InputDeviceServer input_device_server_;
bool test_config_;
bool use_chrome_gpu_command_buffer_;
#if defined(USE_OZONE)
......
......@@ -77,7 +77,6 @@ component("mus") {
"//ui/display/mojo",
"//ui/events",
"//ui/events:events_base",
"//ui/events/devices",
"//ui/gfx",
"//ui/gfx/geometry",
"//ui/gfx/geometry/mojo",
......
......@@ -16,7 +16,6 @@
#include "components/mus/public/interfaces/window_tree.mojom.h"
#include "services/shell/public/cpp/connection.h"
#include "services/shell/public/cpp/connector.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/views/mus/clipboard_mus.h"
#include "ui/views/mus/native_widget_mus.h"
#include "ui/views/mus/screen_mus.h"
......@@ -104,9 +103,7 @@ void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) {
WindowManagerConnection::WindowManagerConnection(
shell::Connector* connector,
const shell::Identity& identity)
: connector_(connector),
identity_(identity),
created_device_data_manager_(false) {
: connector_(connector), identity_(identity) {
lazy_tls_ptr.Pointer()->Set(this);
client_.reset(new mus::WindowTreeClient(this, nullptr, nullptr));
client_->ConnectViaWindowTreeFactory(connector_);
......@@ -118,14 +115,6 @@ WindowManagerConnection::WindowManagerConnection(
clipboard->Init(connector);
ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard));
if (!ui::DeviceDataManager::HasInstance()) {
// TODO(sad): We should have a DeviceDataManager implementation that talks
// to a mojo service to learn about the input-devices on the system.
// http://crbug.com/601981
ui::DeviceDataManager::CreateInstance();
created_device_data_manager_ = true;
}
ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind(
&WindowManagerConnection::CreateNativeWidgetMus,
base::Unretained(this),
......@@ -137,8 +126,6 @@ WindowManagerConnection::~WindowManagerConnection() {
// we are still valid.
client_.reset();
ui::Clipboard::DestroyClipboardForCurrentThread();
if (created_device_data_manager_)
ui::DeviceDataManager::DeleteInstance();
lazy_tls_ptr.Pointer()->Set(nullptr);
if (ViewsDelegate::GetInstance()) {
......
......@@ -7,7 +7,10 @@
#include <stdint.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/observer_list.h"
......@@ -88,7 +91,6 @@ class VIEWS_MUS_EXPORT WindowManagerConnection
std::unique_ptr<mus::WindowTreeClient> client_;
// Must be empty on destruction.
base::ObserverList<PointerWatcher, true> pointer_watchers_;
bool created_device_data_manager_;
DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection);
};
......
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