Commit 691fb5d5 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

Convert CameraModuleCallbacks to new Mojo types

This CL converts CameraModuleCallbacks{Ptr, Request} in media to
the new Mojo type, and uses pending_remote<CameraModuleCallbacks>
in camera_commom.mojom.

Bug: 955171
Change-Id: I3184cb445f9211033af7176c9d97352b2edb849f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862913
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707753}
parent c5d145e9
......@@ -363,9 +363,7 @@ void CameraHalDelegate::SetCameraModuleOnIpcThread(
void CameraHalDelegate::ResetMojoInterfaceOnIpcThread() {
DCHECK(ipc_task_runner_->BelongsToCurrentThread());
camera_module_.reset();
if (camera_module_callbacks_.is_bound()) {
camera_module_callbacks_.Close();
}
camera_module_callbacks_.reset();
vendor_tag_ops_delegate_.Reset();
builtin_camera_info_updated_.Reset();
camera_module_has_been_set_.Reset();
......@@ -416,12 +414,8 @@ void CameraHalDelegate::OnGotNumberOfCamerasOnIpcThread(int32_t num_cameras) {
// Per camera HAL v3 specification SetCallbacks() should be called after the
// first time GetNumberOfCameras() is called, and before other CameraModule
// functions are called.
cros::mojom::CameraModuleCallbacksPtr camera_module_callbacks_ptr;
cros::mojom::CameraModuleCallbacksRequest camera_module_callbacks_request =
mojo::MakeRequest(&camera_module_callbacks_ptr);
camera_module_callbacks_.Bind(std::move(camera_module_callbacks_request));
camera_module_->SetCallbacks(
std::move(camera_module_callbacks_ptr),
camera_module_callbacks_.BindNewPipeAndPassRemote(),
base::BindOnce(&CameraHalDelegate::OnSetCallbacksOnIpcThread, this));
camera_module_->GetVendorTagOps(
......
......@@ -20,7 +20,7 @@
#include "media/capture/video/chromeos/vendor_tag_ops_delegate.h"
#include "media/capture/video/video_capture_device_factory.h"
#include "media/capture/video_capture_types.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace media {
......@@ -176,9 +176,9 @@ class CAPTURE_EXPORT CameraHalDelegate final
// to |ipc_task_runner_|.
cros::mojom::CameraModulePtr camera_module_;
// The Mojo binding serving the camera module callbacks. Bound to
// The Mojo receiver serving the camera module callbacks. Bound to
// |ipc_task_runner_|.
mojo::Binding<cros::mojom::CameraModuleCallbacks> camera_module_callbacks_;
mojo::Receiver<cros::mojom::CameraModuleCallbacks> camera_module_callbacks_;
// An internal delegate to handle VendorTagOps mojo connection and query
// information of vendor tags. Bound to |ipc_task_runner_|.
......
......@@ -18,6 +18,7 @@
#include "media/capture/video/chromeos/video_capture_device_factory_chromeos.h"
#include "media/capture/video/mock_gpu_memory_buffer_manager.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -154,7 +155,7 @@ TEST_F(CameraHalDelegateTest, GetBuiltinCameraInfo) {
};
auto set_callbacks_cb =
[&](cros::mojom::CameraModuleCallbacksPtr& callbacks,
[&](mojo::PendingRemote<cros::mojom::CameraModuleCallbacks>& callbacks,
cros::mojom::CameraModule::SetCallbacksCallback&) {
mock_camera_module_.NotifyCameraDeviceChange(
2, cros::mojom::CameraDeviceStatus::CAMERA_DEVICE_STATUS_PRESENT);
......@@ -163,10 +164,10 @@ TEST_F(CameraHalDelegateTest, GetBuiltinCameraInfo) {
EXPECT_CALL(mock_camera_module_, DoGetNumberOfCameras(_))
.Times(1)
.WillOnce(Invoke(get_number_of_cameras_cb));
EXPECT_CALL(
mock_camera_module_,
DoSetCallbacks(A<cros::mojom::CameraModuleCallbacksPtr&>(),
A<cros::mojom::CameraModule::SetCallbacksCallback&>()))
EXPECT_CALL(mock_camera_module_,
DoSetCallbacks(
A<mojo::PendingRemote<cros::mojom::CameraModuleCallbacks>&>(),
A<cros::mojom::CameraModule::SetCallbacksCallback&>()))
.Times(1)
.WillOnce(Invoke(set_callbacks_cb));
EXPECT_CALL(mock_camera_module_,
......
......@@ -41,10 +41,10 @@ void MockCameraModule::GetCameraInfo(int32_t camera_id,
}
void MockCameraModule::SetCallbacks(
cros::mojom::CameraModuleCallbacksPtr callbacks,
mojo::PendingRemote<cros::mojom::CameraModuleCallbacks> callbacks,
SetCallbacksCallback callback) {
DoSetCallbacks(callbacks, callback);
callbacks_ = std::move(callbacks);
callbacks_.Bind(std::move(callbacks));
std::move(callback).Run(0);
}
......
......@@ -13,6 +13,8 @@
#include "media/capture/video/chromeos/mojom/camera_common.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace media {
......@@ -41,11 +43,13 @@ class MockCameraModule : public cros::mojom::CameraModule {
MOCK_METHOD2(DoGetCameraInfo,
void(int32_t camera_id, GetCameraInfoCallback& callback));
void SetCallbacks(cros::mojom::CameraModuleCallbacksPtr callbacks,
SetCallbacksCallback callback) override;
MOCK_METHOD2(DoSetCallbacks,
void(cros::mojom::CameraModuleCallbacksPtr& callbacks,
SetCallbacksCallback& callback));
void SetCallbacks(
mojo::PendingRemote<cros::mojom::CameraModuleCallbacks> callbacks,
SetCallbacksCallback callback) override;
MOCK_METHOD2(
DoSetCallbacks,
void(mojo::PendingRemote<cros::mojom::CameraModuleCallbacks>& callbacks,
SetCallbacksCallback& callback));
void Init(InitCallback callback) override;
MOCK_METHOD1(DoInit, void(InitCallback& callback));
......@@ -82,7 +86,7 @@ class MockCameraModule : public cros::mojom::CameraModule {
base::Thread mock_module_thread_;
mojo::Binding<cros::mojom::CameraModule> binding_;
cros::mojom::CameraModuleCallbacksPtr callbacks_;
mojo::Remote<cros::mojom::CameraModuleCallbacks> callbacks_;
DISALLOW_COPY_AND_ASSIGN(MockCameraModule);
};
......
......@@ -101,7 +101,8 @@ interface CameraModule {
GetCameraInfo@2(int32 camera_id) => (int32 result, CameraInfo? camera_info);
// Registers the CameraModuleCallbacks interface with the camera HAL.
SetCallbacks@3(CameraModuleCallbacks callbacks) => (int32 result);
SetCallbacks@3(pending_remote<CameraModuleCallbacks> callbacks)
=> (int32 result);
// Turns on or off the torch mode of the flash unit associated with the given
// |camera_id|.
......
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