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