Commit b7d0a0d1 authored by leon.han's avatar leon.han Committed by Commit bot

[Device Service] Eliminate content::ScreenOrientationObserver.

This CL lets Blink talk directly with Device Service to consume the
mojo interface device.mojom.ScreenOrientationListener, then removes
content::ScreenOrientationObserver completely.

BUG=678545

Review-Url: https://codereview.chromium.org/2751513007
Cr-Commit-Position: refs/heads/master@{#457713}
parent 6e4c507d
......@@ -339,8 +339,6 @@ target(link_target_type, "renderer") {
"scheduler/resource_dispatch_throttler.h",
"screen_orientation/screen_orientation_dispatcher.cc",
"screen_orientation/screen_orientation_dispatcher.h",
"screen_orientation/screen_orientation_observer.cc",
"screen_orientation/screen_orientation_observer.h",
"service_worker/embedded_worker_devtools_agent.cc",
"service_worker/embedded_worker_devtools_agent.h",
"service_worker/embedded_worker_dispatcher.cc",
......
......@@ -66,7 +66,6 @@
#include "content/renderer/mojo/blink_interface_provider_impl.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/renderer_clipboard_delegate.h"
#include "content/renderer/screen_orientation/screen_orientation_observer.h"
#include "content/renderer/webclipboard_impl.h"
#include "content/renderer/webgraphicscontext3d_provider_impl.h"
#include "content/renderer/webpublicsuffixlist_impl.h"
......@@ -1132,8 +1131,6 @@ RendererBlinkPlatformImpl::CreatePlatformEventObserverFromType(
return base::MakeUnique<DeviceLightEventPump>(thread);
case blink::WebPlatformEventTypeGamepad:
return base::MakeUnique<GamepadSharedMemoryReader>(thread);
case blink::WebPlatformEventTypeScreenOrientation:
return base::MakeUnique<ScreenOrientationObserver>();
default:
// A default statement is required to prevent compilation errors when
// Blink adds a new type.
......
// Copyright 2014 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.
#include "content/renderer/screen_orientation/screen_orientation_observer.h"
#include "content/public/common/service_manager_connection.h"
#include "content/renderer/render_thread_impl.h"
#include "services/device/public/interfaces/constants.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
namespace content {
ScreenOrientationObserver::ScreenOrientationObserver() {
}
ScreenOrientationObserver::~ScreenOrientationObserver() {
StopIfObserving();
}
void ScreenOrientationObserver::Start(
blink::WebPlatformEventListener* listener) {
// This should never be called with a proper listener.
CHECK(listener == 0);
PlatformEventObserver<blink::WebPlatformEventListener>::Start(0);
}
void ScreenOrientationObserver::SendStartMessage() {
GetScreenOrientationListener()->Start();
}
void ScreenOrientationObserver::SendStopMessage() {
GetScreenOrientationListener()->Stop();
}
device::mojom::ScreenOrientationListener*
ScreenOrientationObserver::GetScreenOrientationListener() {
if (!listener_) {
RenderThreadImpl::current()
->GetServiceManagerConnection()
->GetConnector()
->BindInterface(device::mojom::kServiceName, &listener_);
}
return listener_.get();
}
} // namespace content
// Copyright 2014 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.
#include "content/public/renderer/platform_event_observer.h"
#include "device/screen_orientation/public/interfaces/screen_orientation.mojom.h"
namespace content {
// ScreenOrientationObserver is a helper class implementing the
// PlatformEventObserver template with blink::WebPlatformEventListener, which is
// a pure virtual class because it doesn't expect listeners.
// It is implemented on top of PlatformEventObserver to make sure it follows a
// common code path even though it only uses part of this code path: it is not
// expected to receive messages back but should send messages to start/stop
// listening.
// The intent of this class is to make sure that platforms that can't listen for
// display rotations at a marginal cost can be told when to actually do it.
class ScreenOrientationObserver
: public PlatformEventObserver<blink::WebPlatformEventListener> {
public:
ScreenOrientationObserver();
~ScreenOrientationObserver() override;
// Overriding this method just to make sure |listener| is always null.
void Start(blink::WebPlatformEventListener* listener) override;
protected:
void SendStartMessage() override;
void SendStopMessage() override;
private:
device::mojom::ScreenOrientationListener* GetScreenOrientationListener();
device::mojom::ScreenOrientationListenerPtr listener_;
};
}; // namespace content
......@@ -17,4 +17,9 @@ blink_modules_sources("screen_orientation") {
"ScreenScreenOrientation.cpp",
"ScreenScreenOrientation.h",
]
deps = [
"//device/screen_orientation/public/interfaces:interfaces_blink",
"//services/device/public/interfaces:constants_blink",
"//third_party/WebKit/Source/platform",
]
}
include_rules = [
"+bindings",
"+core",
"+device/screen_orientation/public/interfaces/screen_orientation.mojom-blink.h",
"-modules",
"+modules/EventTargetModules.h",
"+modules/ModulesExport.h",
"+modules/screen_orientation",
"+platform",
"+public/platform",
"+services/device/public/interfaces/constants.mojom-blink.h",
"-web",
]
......@@ -4,7 +4,9 @@
#include "modules/screen_orientation/ScreenOrientationDispatcher.h"
#include "platform/ServiceConnector.h"
#include "public/platform/Platform.h"
#include "services/device/public/interfaces/constants.mojom-blink.h"
namespace blink {
......@@ -16,16 +18,27 @@ ScreenOrientationDispatcher& ScreenOrientationDispatcher::instance() {
ScreenOrientationDispatcher::ScreenOrientationDispatcher() {}
ScreenOrientationDispatcher::~ScreenOrientationDispatcher() {
DCHECK(!m_listener);
}
DEFINE_TRACE(ScreenOrientationDispatcher) {
PlatformEventDispatcher::trace(visitor);
}
void ScreenOrientationDispatcher::startListening() {
Platform::current()->startListening(WebPlatformEventTypeScreenOrientation, 0);
DCHECK(!m_listener);
ServiceConnector::instance().connectToInterface(
device::mojom::blink::kServiceName, mojo::MakeRequest(&m_listener));
m_listener->Start();
}
void ScreenOrientationDispatcher::stopListening() {
Platform::current()->stopListening(WebPlatformEventTypeScreenOrientation);
DCHECK(m_listener);
m_listener->Stop();
m_listener.reset();
}
} // namespace blink
......@@ -6,6 +6,7 @@
#define ScreenOrientationDispatcher_h
#include "core/frame/PlatformEventDispatcher.h"
#include "device/screen_orientation/public/interfaces/screen_orientation.mojom-blink.h"
#include "platform/heap/Handle.h"
namespace blink {
......@@ -19,13 +20,16 @@ namespace blink {
// ScreenOrientationDispatcher is listening, that means that the platform should
// be polling if required.
class ScreenOrientationDispatcher final
: public GarbageCollected<ScreenOrientationDispatcher>,
: public GarbageCollectedFinalized<ScreenOrientationDispatcher>,
public PlatformEventDispatcher {
USING_GARBAGE_COLLECTED_MIXIN(ScreenOrientationDispatcher);
WTF_MAKE_NONCOPYABLE(ScreenOrientationDispatcher);
public:
static ScreenOrientationDispatcher& instance();
~ScreenOrientationDispatcher();
DECLARE_VIRTUAL_TRACE();
private:
......@@ -34,6 +38,8 @@ class ScreenOrientationDispatcher final
// Inherited from PlatformEventDispatcher.
void startListening() override;
void stopListening() override;
device::mojom::blink::ScreenOrientationListenerPtr m_listener;
};
} // namespace blink
......
......@@ -13,7 +13,6 @@ enum WebPlatformEventType {
WebPlatformEventTypeDeviceOrientationAbsolute,
WebPlatformEventTypeDeviceLight,
WebPlatformEventTypeGamepad,
WebPlatformEventTypeScreenOrientation
};
} // namespace blink
......
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