Commit 71afb0ec authored by Elliot Glaysher's avatar Elliot Glaysher Committed by Commit Bot

Make the OzonePlatform not a subclass.

This changes how the Ozone system input injector is created so that
OzonePlatform does not subclass an interface; instead added an adapter
in NativeMessageHostChromeos.

Bug: 734671
Change-Id: Ic6077397882f8e30fec861c710e8cb5cf59c56a9
Reviewed-on: https://chromium-review.googlesource.com/671458Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Commit-Queue: Elliot Glaysher <erg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#502961}
parent 4bafa509
......@@ -982,7 +982,8 @@ static_library("extensions") {
"//ui/chromeos",
"//ui/chromeos/events",
"//ui/file_manager",
"//ui/views/",
"//ui/ozone",
"//ui/views",
]
if (enable_nacl) {
deps += [ "//chrome/browser/resources/chromeos/zip_archiver" ]
......
specific_include_rules = {
"native_message_host_chromeos.cc": [
# TODO(erg): This allows us to switch between mus and classic ash/ozone as
# targets. It should be removed when support for classic ash is removed;
# which means that remoting never touches ozone.
"+ui/ozone/public/ozone_platform.h",
]
}
......@@ -12,6 +12,7 @@
#include "base/bind_helpers.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/single_thread_task_runner.h"
......@@ -33,6 +34,10 @@
#include "ui/gfx/native_widget_types.h"
#include "url/gurl.h"
#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace extensions {
namespace {
......@@ -97,6 +102,31 @@ struct BuiltInHost {
std::unique_ptr<NativeMessageHost> (*create_function)();
};
#if defined(USE_OZONE)
class OzoneSystemInputInjectorAdaptor : public ui::SystemInputInjectorFactory {
public:
std::unique_ptr<ui::SystemInputInjector> CreateSystemInputInjector()
override {
return ui::OzonePlatform::GetInstance()->CreateSystemInputInjector();
}
};
base::LazyInstance<OzoneSystemInputInjectorAdaptor>::Leaky
g_ozone_system_input_injector_adaptor = LAZY_INSTANCE_INITIALIZER;
#endif
ui::SystemInputInjectorFactory* GetInputInjector() {
ui::SystemInputInjectorFactory* system = ui::GetSystemInputInjectorFactory();
if (system)
return system;
#if defined(USE_OZONE)
return g_ozone_system_input_injector_adaptor.Pointer();
#endif
return nullptr;
}
std::unique_ptr<NativeMessageHost> CreateIt2MeHost() {
std::unique_ptr<remoting::It2MeHostFactory> host_factory(
new remoting::It2MeHostFactory());
......@@ -109,7 +139,7 @@ std::unique_ptr<NativeMessageHost> CreateIt2MeHost() {
content::BrowserThread::UI),
base::CreateSingleThreadTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND}),
ui::GetSystemInputInjectorFactory());
GetInputInjector());
std::unique_ptr<remoting::PolicyWatcher> policy_watcher =
remoting::PolicyWatcher::CreateWithPolicyService(
g_browser_process->policy_service());
......
......@@ -45,7 +45,7 @@ Env::~Env() {
if (is_os_exchange_data_provider_factory_)
ui::OSExchangeDataProviderFactory::SetFactory(nullptr);
if (is_override_input_injector_factory_)
ui::SetOverrideInputInjectorFactory(nullptr);
ui::SetSystemInputInjectorFactory(nullptr);
#if defined(USE_OZONE)
gfx::ClientNativePixmapFactory::ResetInstance();
......@@ -200,7 +200,7 @@ void Env::EnableMusOSExchangeDataProvider() {
void Env::EnableMusOverrideInputInjector() {
if (!is_override_input_injector_factory_) {
ui::SetOverrideInputInjectorFactory(this);
ui::SetSystemInputInjectorFactory(this);
is_override_input_injector_factory_ = true;
}
}
......
......@@ -10,25 +10,15 @@ namespace ui {
namespace {
SystemInputInjectorFactory* override_factory_ = nullptr;
SystemInputInjectorFactory* native_factory_ = nullptr;
} // namespace
void SetOverrideInputInjectorFactory(SystemInputInjectorFactory* factory) {
void SetSystemInputInjectorFactory(SystemInputInjectorFactory* factory) {
DCHECK(!factory || !override_factory_);
override_factory_ = factory;
}
void SetNativeInputInjectorFactory(SystemInputInjectorFactory* factory) {
DCHECK(!factory || !native_factory_);
native_factory_ = factory;
}
SystemInputInjectorFactory* GetSystemInputInjectorFactory() {
if (override_factory_)
return override_factory_;
if (native_factory_)
return native_factory_;
return nullptr;
return override_factory_;
}
} // namespace ui
......@@ -61,23 +61,15 @@ class EVENTS_EXPORT SystemInputInjectorFactory {
};
// Sets a global SystemInputInjectorFactory which is used in remoting instead
// of requesting the usual Ozone version, as specified in
// SetNativeInputInjectorFactory().
// of requesting the usual Ozone version.
//
// This is placed in //ui/events not just since it's event related, but also
// because its one of the few places that both //remoting/ and //ui/ozone can
// depend on.
EVENTS_EXPORT void SetOverrideInputInjectorFactory(
EVENTS_EXPORT void SetSystemInputInjectorFactory(
SystemInputInjectorFactory* factory);
// Sets a global SystemInputInjectorFactory which is used if there isn't an
// override injector factory. Currently, this is always the ozone
// implementation.
EVENTS_EXPORT void SetNativeInputInjectorFactory(
SystemInputInjectorFactory* factory);
// Returns the override input injector factory, the native one, or null if
// neither are set.
// Returns the override input injector factory, or null if neither are set.
EVENTS_EXPORT SystemInputInjectorFactory* GetSystemInputInjectorFactory();
} // namespace ui
......
......@@ -24,13 +24,11 @@ OzonePlatform::OzonePlatform() {
instance_ = this;
g_platform_initialized_ui = false;
g_platform_initialized_gpu = false;
SetNativeInputInjectorFactory(this);
}
OzonePlatform::~OzonePlatform() {
DCHECK_EQ(instance_, this);
instance_ = NULL;
SetNativeInputInjectorFactory(nullptr);
}
// static
......
......@@ -55,7 +55,7 @@ class SystemInputInjector;
// interface depending on the context. You can, for example, create
// different objects depending on the underlying hardware, command
// line flags, or whatever is appropriate for the platform.
class OZONE_EXPORT OzonePlatform : public SystemInputInjectorFactory {
class OZONE_EXPORT OzonePlatform {
public:
OzonePlatform();
virtual ~OzonePlatform();
......@@ -105,15 +105,13 @@ class OZONE_EXPORT OzonePlatform : public SystemInputInjectorFactory {
virtual ui::InputController* GetInputController() = 0;
virtual IPC::MessageFilter* GetGpuMessageFilter();
virtual ui::GpuPlatformSupportHost* GetGpuPlatformSupportHost() = 0;
virtual std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() = 0;
virtual std::unique_ptr<PlatformWindow> CreatePlatformWindow(
PlatformWindowDelegate* delegate,
const gfx::Rect& bounds) = 0;
virtual std::unique_ptr<display::NativeDisplayDelegate>
CreateNativeDisplayDelegate() = 0;
// Factory getters which come through from SystemInputInjector:
std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() override = 0;
// Returns the message loop type required for OzonePlatform instance that
// will be initialized for the GPU process.
virtual base::MessageLoop::Type GetMessageLoopTypeForGpu();
......
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