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

Convert MtpManager to new Mojo types

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

Bug: 955171
Change-Id: Iac8e22b1b2b40b3c8417fe3b66628626b349b287
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1806167Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#697219}
parent b5ed2435
......@@ -121,8 +121,8 @@ void StorageMonitorCros::Init() {
if (!mtp_device_manager_) {
// Set up the connection with mojofied MtpManager.
DCHECK(GetConnector());
GetConnector()->BindInterface(device::mojom::kServiceName,
mojo::MakeRequest(&mtp_device_manager_));
GetConnector()->Connect(device::mojom::kServiceName,
mtp_device_manager_.BindNewPipeAndPassReceiver());
}
// |mtp_manager_client_| needs to be initialized for both tests and
// production code, so keep it out of the if condition.
......@@ -237,9 +237,9 @@ void StorageMonitorCros::OnMountEvent(
}
void StorageMonitorCros::SetMediaTransferProtocolManagerForTest(
device::mojom::MtpManagerPtr test_manager) {
mojo::PendingRemote<device::mojom::MtpManager> test_manager) {
DCHECK(!mtp_device_manager_);
mtp_device_manager_ = std::move(test_manager);
mtp_device_manager_.Bind(std::move(test_manager));
}
bool StorageMonitorCros::GetStorageInfoForPath(
......
......@@ -23,6 +23,8 @@
#include "build/build_config.h"
#include "chromeos/disks/disk_mount_manager.h"
#include "components/storage_monitor/storage_monitor.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/mtp_manager.mojom.h"
namespace storage_monitor {
......@@ -43,7 +45,7 @@ class StorageMonitorCros : public StorageMonitor,
protected:
void SetMediaTransferProtocolManagerForTest(
device::mojom::MtpManagerPtr test_manager);
mojo::PendingRemote<device::mojom::MtpManager> test_manager);
// chromeos::disks::DiskMountManager::Observer implementation.
void OnBootDeviceDiskEvent(chromeos::disks::DiskMountManager::DiskEvent event,
......@@ -86,7 +88,7 @@ class StorageMonitorCros : public StorageMonitor,
// Mapping of relevant mount points and their corresponding mount devices.
MountMap mount_map_;
device::mojom::MtpManagerPtr mtp_device_manager_;
mojo::Remote<device::mojom::MtpManager> mtp_device_manager_;
std::unique_ptr<MtpManagerClientChromeOS> mtp_manager_client_;
......
......@@ -26,6 +26,7 @@
#include "components/storage_monitor/test_media_transfer_protocol_manager_chromeos.h"
#include "components/storage_monitor/test_storage_monitor.h"
#include "content/public/test/browser_task_environment.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace storage_monitor {
......@@ -71,11 +72,12 @@ class TestStorageMonitorCros : public StorageMonitorCros {
~TestStorageMonitorCros() override {}
void Init() override {
device::mojom::MtpManagerPtr fake_mtp_manager_ptr;
mojo::PendingRemote<device::mojom::MtpManager> pending_fake_mtp_manager;
auto* fake_mtp_manager =
TestMediaTransferProtocolManagerChromeOS::GetFakeMtpManager();
fake_mtp_manager->AddBinding(mojo::MakeRequest(&fake_mtp_manager_ptr));
SetMediaTransferProtocolManagerForTest(std::move(fake_mtp_manager_ptr));
fake_mtp_manager->AddReceiver(
pending_fake_mtp_manager.InitWithNewPipeAndPassReceiver());
SetMediaTransferProtocolManagerForTest(std::move(pending_fake_mtp_manager));
StorageMonitorCros::Init();
}
......
......@@ -28,9 +28,9 @@ TestMediaTransferProtocolManagerChromeOS::
TestMediaTransferProtocolManagerChromeOS::
~TestMediaTransferProtocolManagerChromeOS() {}
void TestMediaTransferProtocolManagerChromeOS::AddBinding(
device::mojom::MtpManagerRequest request) {
bindings_.AddBinding(this, std::move(request));
void TestMediaTransferProtocolManagerChromeOS::AddReceiver(
mojo::PendingReceiver<device::mojom::MtpManager> receiver) {
receivers_.Add(this, std::move(receiver));
}
void TestMediaTransferProtocolManagerChromeOS::EnumerateStoragesAndSetClient(
......
......@@ -11,7 +11,8 @@
#include <string>
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/device/public/mojom/mtp_manager.mojom.h"
namespace storage_monitor {
......@@ -24,7 +25,7 @@ class TestMediaTransferProtocolManagerChromeOS
TestMediaTransferProtocolManagerChromeOS();
~TestMediaTransferProtocolManagerChromeOS() override;
void AddBinding(device::mojom::MtpManagerRequest request);
void AddReceiver(mojo::PendingReceiver<device::mojom::MtpManager> receiver);
private:
// device::mojom::MtpManager implementation.
......@@ -69,7 +70,7 @@ class TestMediaTransferProtocolManagerChromeOS
uint32_t object_id,
DeleteObjectCallback callback) override;
mojo::BindingSet<device::mojom::MtpManager> bindings_;
mojo::ReceiverSet<device::mojom::MtpManager> receivers_;
DISALLOW_COPY_AND_ASSIGN(TestMediaTransferProtocolManagerChromeOS);
};
......
......@@ -22,8 +22,8 @@ TestStorageMonitor::TestStorageMonitor() : init_called_(false) {
#if defined(OS_CHROMEOS)
auto* fake_mtp_manager =
TestMediaTransferProtocolManagerChromeOS::GetFakeMtpManager();
fake_mtp_manager->AddBinding(
mojo::MakeRequest(&media_transfer_protocol_manager_));
fake_mtp_manager->AddReceiver(
media_transfer_protocol_manager_.BindNewPipeAndPassReceiver());
#endif
}
......
......@@ -13,6 +13,7 @@
#include "components/storage_monitor/storage_monitor.h"
#if defined(OS_CHROMEOS)
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/mtp_manager.mojom.h"
#endif
......@@ -78,7 +79,7 @@ class TestStorageMonitor : public StorageMonitor {
std::vector<base::FilePath> removable_paths_;
#if defined(OS_CHROMEOS)
device::mojom::MtpManagerPtr media_transfer_protocol_manager_;
mojo::Remote<device::mojom::MtpManager> media_transfer_protocol_manager_;
#endif
};
......
......@@ -213,7 +213,7 @@ void DeviceService::OnStart() {
base::BindRepeating(&DeviceService::BindBluetoothSystemFactoryReceiver,
base::Unretained(this)));
registry_.AddInterface<mojom::MtpManager>(base::BindRepeating(
&DeviceService::BindMtpManagerRequest, base::Unretained(this)));
&DeviceService::BindMtpManagerReceiver, base::Unretained(this)));
#endif
#if defined(OS_LINUX) && defined(USE_UDEV)
......@@ -260,10 +260,11 @@ void DeviceService::BindBluetoothSystemFactoryReceiver(
BluetoothSystemFactory::CreateFactory(std::move(receiver));
}
void DeviceService::BindMtpManagerRequest(mojom::MtpManagerRequest request) {
void DeviceService::BindMtpManagerReceiver(
mojo::PendingReceiver<mojom::MtpManager> receiver) {
if (!mtp_device_manager_)
mtp_device_manager_ = MtpDeviceManager::Initialize();
mtp_device_manager_->AddBinding(std::move(request));
mtp_device_manager_->AddReceiver(std::move(receiver));
}
#endif
......
......@@ -163,7 +163,8 @@ class DeviceService : public service_manager::Service {
#if defined(OS_CHROMEOS)
void BindBluetoothSystemFactoryReceiver(
mojo::PendingReceiver<mojom::BluetoothSystemFactory> receiver);
void BindMtpManagerRequest(mojom::MtpManagerRequest request);
void BindMtpManagerReceiver(
mojo::PendingReceiver<mojom::MtpManager> receiver);
#endif
void BindPowerMonitorRequest(mojom::PowerMonitorRequest request);
......
......@@ -50,8 +50,9 @@ MtpDeviceManager::~MtpDeviceManager() {
VLOG(1) << "MtpDeviceManager Shutdown completed";
}
void MtpDeviceManager::AddBinding(mojom::MtpManagerRequest request) {
bindings_.AddBinding(this, std::move(request));
void MtpDeviceManager::AddReceiver(
mojo::PendingReceiver<mojom::MtpManager> receiver) {
receivers_.Add(this, std::move(receiver));
}
void MtpDeviceManager::EnumerateStoragesAndSetClient(
......
......@@ -17,8 +17,9 @@
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "base/threading/thread_checker.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/device/media_transfer_protocol/media_transfer_protocol_daemon_client.h"
#include "services/device/public/mojom/mtp_manager.mojom.h"
......@@ -39,7 +40,7 @@ class MtpDeviceManager : public mojom::MtpManager {
MtpDeviceManager();
~MtpDeviceManager() override;
void AddBinding(mojom::MtpManagerRequest request);
void AddReceiver(mojo::PendingReceiver<mojom::MtpManager> receiver);
// Implements mojom::MtpManager.
void EnumerateStoragesAndSetClient(
......@@ -167,7 +168,7 @@ class MtpDeviceManager : public mojom::MtpManager {
// DBusThreadManager to provide a bus in unit tests.
scoped_refptr<dbus::Bus> const bus_;
mojo::BindingSet<mojom::MtpManager> bindings_;
mojo::ReceiverSet<mojom::MtpManager> receivers_;
// MtpManager client who keeps tuned on attachment / detachment events.
// Currently, storage_monitor::StorageMonitorCros is supposed to be the
// only client.
......
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