Commit de063bcc authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert VibrationManager to new Mojo types

This CL converts VibrationManager{Ptr, Request} in services and
blink to the new Mojo type.

Bug: 955171, 978694
Change-Id: Idaa3a0cdd1c3feec0868f14df93cd71f93fe9fa0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1810448Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#697968}
parent 0c0f34a2
...@@ -186,7 +186,7 @@ void DeviceService::OnStart() { ...@@ -186,7 +186,7 @@ void DeviceService::OnStart() {
registry_.AddInterface<mojom::NFCProvider>(base::Bind( registry_.AddInterface<mojom::NFCProvider>(base::Bind(
&DeviceService::BindNFCProviderReceiver, base::Unretained(this))); &DeviceService::BindNFCProviderReceiver, base::Unretained(this)));
registry_.AddInterface<mojom::VibrationManager>(base::Bind( registry_.AddInterface<mojom::VibrationManager>(base::Bind(
&DeviceService::BindVibrationManagerRequest, base::Unretained(this))); &DeviceService::BindVibrationManagerReceiver, base::Unretained(this)));
#endif #endif
#if (defined(OS_LINUX) && defined(USE_UDEV)) || defined(OS_WIN) || \ #if (defined(OS_LINUX) && defined(USE_UDEV)) || defined(OS_WIN) || \
...@@ -248,9 +248,9 @@ void DeviceService::BindNFCProviderReceiver( ...@@ -248,9 +248,9 @@ void DeviceService::BindNFCProviderReceiver(
NOTREACHED(); NOTREACHED();
} }
void DeviceService::BindVibrationManagerRequest( void DeviceService::BindVibrationManagerReceiver(
mojom::VibrationManagerRequest request) { mojo::PendingReceiver<mojom::VibrationManager> receiver) {
VibrationManagerImpl::Create(std::move(request)); VibrationManagerImpl::Create(std::move(receiver));
} }
#endif #endif
......
...@@ -158,7 +158,8 @@ class DeviceService : public service_manager::Service { ...@@ -158,7 +158,8 @@ class DeviceService : public service_manager::Service {
mojo::PendingReceiver<mojom::HidManager> receiver); mojo::PendingReceiver<mojom::HidManager> receiver);
void BindNFCProviderReceiver( void BindNFCProviderReceiver(
mojo::PendingReceiver<mojom::NFCProvider> receiver); mojo::PendingReceiver<mojom::NFCProvider> receiver);
void BindVibrationManagerRequest(mojom::VibrationManagerRequest request); void BindVibrationManagerReceiver(
mojo::PendingReceiver<mojom::VibrationManager> receiver);
#endif #endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
......
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
#ifndef SERVICES_DEVICE_VIBRATION_VIBRATION_MANAGER_IMPL_H_ #ifndef SERVICES_DEVICE_VIBRATION_VIBRATION_MANAGER_IMPL_H_
#define SERVICES_DEVICE_VIBRATION_VIBRATION_MANAGER_IMPL_H_ #define SERVICES_DEVICE_VIBRATION_VIBRATION_MANAGER_IMPL_H_
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/device/public/mojom/vibration_manager.mojom.h" #include "services/device/public/mojom/vibration_manager.mojom.h"
namespace device { namespace device {
class VibrationManagerImpl { class VibrationManagerImpl {
public: public:
static void Create(mojo::InterfaceRequest<mojom::VibrationManager> request); static void Create(mojo::PendingReceiver<mojom::VibrationManager> receiver);
static int64_t milli_seconds_for_testing_; static int64_t milli_seconds_for_testing_;
static bool cancelled_for_testing_; static bool cancelled_for_testing_;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <stdint.h> #include <stdint.h>
#include <utility> #include <utility>
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace device { namespace device {
...@@ -35,9 +35,10 @@ class VibrationManagerEmptyImpl : public mojom::VibrationManager { ...@@ -35,9 +35,10 @@ class VibrationManagerEmptyImpl : public mojom::VibrationManager {
} // namespace } // namespace
// static // static
void VibrationManagerImpl::Create(mojom::VibrationManagerRequest request) { void VibrationManagerImpl::Create(
mojo::MakeStrongBinding(std::make_unique<VibrationManagerEmptyImpl>(), mojo::PendingReceiver<mojom::VibrationManager> receiver) {
std::move(request)); mojo::MakeSelfOwnedReceiver(std::make_unique<VibrationManagerEmptyImpl>(),
std::move(receiver));
} }
} // namespace device } // namespace device
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/run_loop.h" #include "base/run_loop.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/device_service_test_base.h" #include "services/device/device_service_test_base.h"
#include "services/device/public/mojom/constants.mojom.h" #include "services/device/public/mojom/constants.mojom.h"
#include "services/device/public/mojom/vibration_manager.mojom.h" #include "services/device/public/mojom/vibration_manager.mojom.h"
...@@ -27,7 +28,8 @@ class VibrationManagerImplTest : public DeviceServiceTestBase { ...@@ -27,7 +28,8 @@ class VibrationManagerImplTest : public DeviceServiceTestBase {
void SetUp() override { void SetUp() override {
DeviceServiceTestBase::SetUp(); DeviceServiceTestBase::SetUp();
connector()->BindInterface(mojom::kServiceName, &vibration_manager_); connector()->Connect(mojom::kServiceName,
vibration_manager_.BindNewPipeAndPassReceiver());
} }
void Vibrate(int64_t milliseconds) { void Vibrate(int64_t milliseconds) {
...@@ -61,7 +63,7 @@ class VibrationManagerImplTest : public DeviceServiceTestBase { ...@@ -61,7 +63,7 @@ class VibrationManagerImplTest : public DeviceServiceTestBase {
} }
private: private:
mojom::VibrationManagerPtr vibration_manager_; mojo::Remote<mojom::VibrationManager> vibration_manager_;
DISALLOW_COPY_AND_ASSIGN(VibrationManagerImplTest); DISALLOW_COPY_AND_ASSIGN(VibrationManagerImplTest);
}; };
......
...@@ -86,7 +86,7 @@ VibrationController::VibrationController(LocalFrame& frame) ...@@ -86,7 +86,7 @@ VibrationController::VibrationController(LocalFrame& frame)
is_calling_cancel_(false), is_calling_cancel_(false),
is_calling_vibrate_(false) { is_calling_vibrate_(false) {
frame.GetInterfaceProvider().GetInterface( frame.GetInterfaceProvider().GetInterface(
mojo::MakeRequest(&vibration_manager_)); vibration_manager_.BindNewPipeAndPassReceiver());
} }
VibrationController::~VibrationController() = default; VibrationController::~VibrationController() = default;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_VIBRATION_VIBRATION_CONTROLLER_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_VIBRATION_VIBRATION_CONTROLLER_H_
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/vibration_manager.mojom-blink.h" #include "services/device/public/mojom/vibration_manager.mojom-blink.h"
#include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h" #include "third_party/blink/renderer/core/execution_context/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/page/page_visibility_observer.h" #include "third_party/blink/renderer/core/page/page_visibility_observer.h"
...@@ -73,9 +74,9 @@ class MODULES_EXPORT VibrationController final ...@@ -73,9 +74,9 @@ class MODULES_EXPORT VibrationController final
// Inherited from PageVisibilityObserver. // Inherited from PageVisibilityObserver.
void PageVisibilityChanged() override; void PageVisibilityChanged() override;
// Ptr to VibrationManager mojo interface. This is reset in |contextDestroyed| // Remote to VibrationManager mojo interface. This is reset in
// and must not be called or recreated after it is reset. // |contextDestroyed| and must not be called or recreated after it is reset.
device::mojom::blink::VibrationManagerPtr vibration_manager_; mojo::Remote<device::mojom::blink::VibrationManager> vibration_manager_;
// Timer for calling |doVibrate| after a delay. It is safe to call // Timer for calling |doVibrate| after a delay. It is safe to call
// |startOneshot| when the timer is already running: it may affect the time // |startOneshot| when the timer is already running: it may affect the time
......
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