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