Commit 3279d13e authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Migrate drivefs.mojom to the new Mojo types

Convert the implementation and all users of the
drivefs::mojom::DriveFsBootstrap, DriveFs, DriveFsDelegate and
SearchQuery interfaces.

Bug: 955171
Change-Id: I3881ee40feba2aaae7659398cd100dd90bbfd53b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847332Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Cr-Commit-Position: refs/heads/master@{#705921}
parent 342530e6
...@@ -15,10 +15,13 @@ ...@@ -15,10 +15,13 @@
#include "chrome/browser/chromeos/file_manager/file_tasks_observer.h" #include "chrome/browser/chromeos/file_manager/file_tasks_observer.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom-test-utils.h" #include "chromeos/components/drivefs/mojom/drivefs.mojom-test-utils.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "components/drive/file_errors.h" #include "components/drive/file_errors.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "content/public/test/fake_download_item.h" #include "content/public/test/fake_download_item.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "storage/browser/fileapi/external_mount_points.h" #include "storage/browser/fileapi/external_mount_points.h"
#include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/file_system_url.h"
#include "storage/common/fileapi/file_system_types.h" #include "storage/common/fileapi/file_system_types.h"
...@@ -97,7 +100,8 @@ class MockFileTasksObserver : public file_tasks::FileTasksObserver { ...@@ -97,7 +100,8 @@ class MockFileTasksObserver : public file_tasks::FileTasksObserver {
class FileTasksNotifierForTest : public FileTasksNotifier { class FileTasksNotifierForTest : public FileTasksNotifier {
public: public:
FileTasksNotifierForTest(Profile* profile, drivefs::mojom::DriveFsPtr drivefs) FileTasksNotifierForTest(Profile* profile,
mojo::PendingRemote<drivefs::mojom::DriveFs> drivefs)
: FileTasksNotifier(profile), drivefs_(std::move(drivefs)) {} : FileTasksNotifier(profile), drivefs_(std::move(drivefs)) {}
drivefs::mojom::DriveFs* GetDriveFsInterface() override { drivefs::mojom::DriveFs* GetDriveFsInterface() override {
...@@ -115,21 +119,19 @@ class FileTasksNotifierForTest : public FileTasksNotifier { ...@@ -115,21 +119,19 @@ class FileTasksNotifierForTest : public FileTasksNotifier {
void set_is_offline(bool is_offline) { is_offline_ = is_offline; } void set_is_offline(bool is_offline) { is_offline_ = is_offline; }
private: private:
const drivefs::mojom::DriveFsPtr drivefs_; const mojo::Remote<drivefs::mojom::DriveFs> drivefs_;
bool is_offline_ = false; bool is_offline_ = false;
}; };
class FileTasksNotifierTest : public testing::Test { class FileTasksNotifierTest : public testing::Test {
protected: protected:
FileTasksNotifierTest() : drivefs_binding_(&fake_drivefs_) {} FileTasksNotifierTest() = default;
void SetUp() override { void SetUp() override {
profile_ = std::make_unique<TestingProfile>(); profile_ = std::make_unique<TestingProfile>();
drivefs::mojom::DriveFsPtr fake_drivefs_ptr;
drivefs_binding_.Bind(mojo::MakeRequest(&fake_drivefs_ptr));
notifier_ = std::make_unique<FileTasksNotifierForTest>( notifier_ = std::make_unique<FileTasksNotifierForTest>(
profile_.get(), std::move(fake_drivefs_ptr)); profile_.get(), drivefs_receiver_.BindNewPipeAndPassRemote());
observer_ = std::make_unique<MockFileTasksObserver>(notifier_.get()); observer_ = std::make_unique<MockFileTasksObserver>(notifier_.get());
auto* mount_points = storage::ExternalMountPoints::GetSystemInstance(); auto* mount_points = storage::ExternalMountPoints::GetSystemInstance();
...@@ -175,7 +177,7 @@ class FileTasksNotifierTest : public testing::Test { ...@@ -175,7 +177,7 @@ class FileTasksNotifierTest : public testing::Test {
private: private:
content::BrowserTaskEnvironment task_environment_; content::BrowserTaskEnvironment task_environment_;
FakeDriveFs fake_drivefs_; FakeDriveFs fake_drivefs_;
mojo::Binding<drivefs::mojom::DriveFs> drivefs_binding_; mojo::Receiver<drivefs::mojom::DriveFs> drivefs_receiver_{&fake_drivefs_};
std::unique_ptr<TestingProfile> profile_; std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<FileTasksNotifierForTest> notifier_; std::unique_ptr<FileTasksNotifierForTest> notifier_;
std::unique_ptr<MockFileTasksObserver> observer_; std::unique_ptr<MockFileTasksObserver> observer_;
......
...@@ -65,7 +65,7 @@ void RecentDriveSource::GetRecentFiles(Params params) { ...@@ -65,7 +65,7 @@ void RecentDriveSource::GetRecentFiles(Params params) {
query_params->sort_direction = query_params->sort_direction =
drivefs::mojom::QueryParameters::SortDirection::kDescending; drivefs::mojom::QueryParameters::SortDirection::kDescending;
integration_service->GetDriveFsInterface()->StartSearchQuery( integration_service->GetDriveFsInterface()->StartSearchQuery(
mojo::MakeRequest(&search_query_), std::move(query_params)); search_query_.BindNewPipeAndPassReceiver(), std::move(query_params));
search_query_->GetNextPage(base::BindOnce( search_query_->GetNextPage(base::BindOnce(
&RecentDriveSource::GotSearchResults, weak_ptr_factory_.GetWeakPtr())); &RecentDriveSource::GotSearchResults, weak_ptr_factory_.GetWeakPtr()));
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/chromeos/fileapi/recent_source.h" #include "chrome/browser/chromeos/fileapi/recent_source.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h" #include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "components/drive/file_errors.h" #include "components/drive/file_errors.h"
#include "mojo/public/cpp/bindings/remote.h"
class Profile; class Profile;
...@@ -55,7 +56,7 @@ class RecentDriveSource : public RecentSource { ...@@ -55,7 +56,7 @@ class RecentDriveSource : public RecentSource {
std::vector<RecentFile> files_; std::vector<RecentFile> files_;
drivefs::mojom::SearchQueryPtr search_query_; mojo::Remote<drivefs::mojom::SearchQuery> search_query_;
base::WeakPtrFactory<RecentDriveSource> weak_ptr_factory_{this}; base::WeakPtrFactory<RecentDriveSource> weak_ptr_factory_{this};
......
...@@ -7,16 +7,18 @@ ...@@ -7,16 +7,18 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "chromeos/components/drivefs/pending_connection_manager.h" #include "chromeos/components/drivefs/pending_connection_manager.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/platform/platform_channel_endpoint.h" #include "mojo/public/cpp/platform/platform_channel_endpoint.h"
#include "mojo/public/cpp/system/invitation.h" #include "mojo/public/cpp/system/invitation.h"
namespace drivefs { namespace drivefs {
DriveFsBootstrapListener::DriveFsBootstrapListener() DriveFsBootstrapListener::DriveFsBootstrapListener()
: bootstrap_(mojo::MakeProxy(mojom::DriveFsBootstrapPtrInfo( : bootstrap_(invitation_.AttachMessagePipe("drivefs-bootstrap"),
invitation_.AttachMessagePipe("drivefs-bootstrap"), mojom::DriveFsBootstrap::Version_),
mojom::DriveFsBootstrap::Version_))),
pending_token_(base::UnguessableToken::Create()) { pending_token_(base::UnguessableToken::Create()) {
PendingConnectionManager::Get().ExpectOpenIpcChannel( PendingConnectionManager::Get().ExpectOpenIpcChannel(
pending_token_, pending_token_,
...@@ -32,7 +34,8 @@ DriveFsBootstrapListener::~DriveFsBootstrapListener() { ...@@ -32,7 +34,8 @@ DriveFsBootstrapListener::~DriveFsBootstrapListener() {
} }
} }
mojom::DriveFsBootstrapPtr DriveFsBootstrapListener::bootstrap() { mojo::PendingRemote<mojom::DriveFsBootstrap>
DriveFsBootstrapListener::bootstrap() {
return std::move(bootstrap_); return std::move(bootstrap_);
} }
...@@ -61,22 +64,20 @@ class DriveFsConnectionImpl : public DriveFsConnection { ...@@ -61,22 +64,20 @@ class DriveFsConnectionImpl : public DriveFsConnection {
base::UnguessableToken Connect(mojom::DriveFsDelegate* delegate, base::UnguessableToken Connect(mojom::DriveFsDelegate* delegate,
base::OnceClosure on_disconnected) override { base::OnceClosure on_disconnected) override {
delegate_binding_ = delegate_receiver_ =
std::make_unique<mojo::Binding<mojom::DriveFsDelegate>>(delegate); std::make_unique<mojo::Receiver<mojom::DriveFsDelegate>>(delegate);
on_disconnected_ = std::move(on_disconnected); on_disconnected_ = std::move(on_disconnected);
auto bootstrap = bootstrap_listener_->bootstrap(); auto bootstrap =
mojo::Remote<mojom::DriveFsBootstrap>(bootstrap_listener_->bootstrap());
auto token = bootstrap_listener_->pending_token(); auto token = bootstrap_listener_->pending_token();
mojom::DriveFsDelegatePtr delegate_ptr; bootstrap->Init(std::move(config_), drivefs_.BindNewPipeAndPassReceiver(),
delegate_binding_->Bind(mojo::MakeRequest(&delegate_ptr)); delegate_receiver_->BindNewPipeAndPassRemote());
delegate_binding_->set_connection_error_handler(base::BindOnce(
&DriveFsConnectionImpl::OnMojoConnectionError, base::Unretained(this)));
bootstrap->Init(std::move(config_), mojo::MakeRequest(&drivefs_),
std::move(delegate_ptr));
drivefs_.set_connection_error_handler(base::BindOnce( delegate_receiver_->set_disconnect_handler(base::BindOnce(
&DriveFsConnectionImpl::OnMojoConnectionError, base::Unretained(this)));
drivefs_.set_disconnect_handler(base::BindOnce(
&DriveFsConnectionImpl::OnMojoConnectionError, base::Unretained(this))); &DriveFsConnectionImpl::OnMojoConnectionError, base::Unretained(this)));
return token; return token;
...@@ -97,8 +98,8 @@ class DriveFsConnectionImpl : public DriveFsConnection { ...@@ -97,8 +98,8 @@ class DriveFsConnectionImpl : public DriveFsConnection {
const std::unique_ptr<DriveFsBootstrapListener> bootstrap_listener_; const std::unique_ptr<DriveFsBootstrapListener> bootstrap_listener_;
mojom::DriveFsConfigurationPtr config_; mojom::DriveFsConfigurationPtr config_;
std::unique_ptr<mojo::Binding<mojom::DriveFsDelegate>> delegate_binding_; std::unique_ptr<mojo::Receiver<mojom::DriveFsDelegate>> delegate_receiver_;
mojom::DriveFsPtr drivefs_; mojo::Remote<mojom::DriveFs> drivefs_;
base::OnceClosure on_disconnected_; base::OnceClosure on_disconnected_;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/unguessable_token.h" #include "base/unguessable_token.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h" #include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/system/invitation.h" #include "mojo/public/cpp/system/invitation.h"
namespace drivefs { namespace drivefs {
...@@ -24,7 +24,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsBootstrapListener { ...@@ -24,7 +24,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsBootstrapListener {
virtual ~DriveFsBootstrapListener(); virtual ~DriveFsBootstrapListener();
const base::UnguessableToken& pending_token() const { return pending_token_; } const base::UnguessableToken& pending_token() const { return pending_token_; }
virtual mojom::DriveFsBootstrapPtr bootstrap(); virtual mojo::PendingRemote<mojom::DriveFsBootstrap> bootstrap();
bool is_connected() const { return connected_; } bool is_connected() const { return connected_; }
protected: protected:
...@@ -35,7 +35,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsBootstrapListener { ...@@ -35,7 +35,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsBootstrapListener {
void AcceptMojoConnection(base::ScopedFD handle); void AcceptMojoConnection(base::ScopedFD handle);
mojo::OutgoingInvitation invitation_; mojo::OutgoingInvitation invitation_;
mojom::DriveFsBootstrapPtr bootstrap_; mojo::PendingRemote<mojom::DriveFsBootstrap> bootstrap_;
// The token passed to DriveFS as part of 'source path' used to match it to // The token passed to DriveFS as part of 'source path' used to match it to
// this instance. // this instance.
......
...@@ -5,12 +5,18 @@ ...@@ -5,12 +5,18 @@
#include "chromeos/components/drivefs/drivefs_bootstrap.h" #include "chromeos/components/drivefs/drivefs_bootstrap.h"
#include <memory> #include <memory>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom-test-utils.h" #include "chromeos/components/drivefs/mojom/drivefs.mojom-test-utils.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "chromeos/components/drivefs/pending_connection_manager.h" #include "chromeos/components/drivefs/pending_connection_manager.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -38,17 +44,17 @@ class MockDriveFsDelegate : public mojom::DriveFsDelegateInterceptorForTesting { ...@@ -38,17 +44,17 @@ class MockDriveFsDelegate : public mojom::DriveFsDelegateInterceptorForTesting {
class DriveFsBootstrapListenerForTest : public DriveFsBootstrapListener { class DriveFsBootstrapListenerForTest : public DriveFsBootstrapListener {
public: public:
DriveFsBootstrapListenerForTest( DriveFsBootstrapListenerForTest(
mojom::DriveFsBootstrapPtrInfo available_bootstrap) mojo::PendingRemote<mojom::DriveFsBootstrap> available_bootstrap)
: available_bootstrap_(std::move(available_bootstrap)) {} : available_bootstrap_(std::move(available_bootstrap)) {}
mojom::DriveFsBootstrapPtr bootstrap() override { mojo::PendingRemote<mojom::DriveFsBootstrap> bootstrap() override {
return mojo::MakeProxy(std::move(available_bootstrap_)); return std::move(available_bootstrap_);
} }
void SendInvitationOverPipe(base::ScopedFD) override {} void SendInvitationOverPipe(base::ScopedFD) override {}
private: private:
mojom::DriveFsBootstrapPtrInfo available_bootstrap_; mojo::PendingRemote<mojom::DriveFsBootstrap> available_bootstrap_;
DISALLOW_COPY_AND_ASSIGN(DriveFsBootstrapListenerForTest); DISALLOW_COPY_AND_ASSIGN(DriveFsBootstrapListenerForTest);
}; };
...@@ -56,27 +62,24 @@ class DriveFsBootstrapListenerForTest : public DriveFsBootstrapListener { ...@@ -56,27 +62,24 @@ class DriveFsBootstrapListenerForTest : public DriveFsBootstrapListener {
class DriveFsBootstrapTest : public testing::Test, class DriveFsBootstrapTest : public testing::Test,
public mojom::DriveFsBootstrap { public mojom::DriveFsBootstrap {
public: public:
DriveFsBootstrapTest() : bootstrap_binding_(this), binding_(&mock_drivefs_) {} DriveFsBootstrapTest() = default;
protected: protected:
MOCK_CONST_METHOD0(OnDisconnect, void()); MOCK_CONST_METHOD0(OnDisconnect, void());
MOCK_CONST_METHOD0(OnInit, void()); MOCK_CONST_METHOD0(OnInit, void());
void Init(mojom::DriveFsConfigurationPtr config, void Init(mojom::DriveFsConfigurationPtr config,
mojom::DriveFsRequest drive_fs_request, mojo::PendingReceiver<mojom::DriveFs> drive_fs_receiver,
mojom::DriveFsDelegatePtr delegate) override { mojo::PendingRemote<mojom::DriveFsDelegate> delegate) override {
binding_.Bind(std::move(drive_fs_request)); receiver_.Bind(std::move(drive_fs_receiver));
mojo::FuseInterface(std::move(pending_delegate_request_), mojo::FusePipes(std::move(pending_delegate_receiver_), std::move(delegate));
delegate.PassInterface());
OnInit(); OnInit();
} }
std::unique_ptr<DriveFsBootstrapListener> CreateListener() { std::unique_ptr<DriveFsBootstrapListener> CreateListener() {
mojom::DriveFsBootstrapPtrInfo pending_bootstrap; pending_delegate_receiver_ = delegate_.BindNewPipeAndPassReceiver();
bootstrap_binding_.Bind(mojo::MakeRequest(&pending_bootstrap));
pending_delegate_request_ = mojo::MakeRequest(&delegate_ptr_);
return std::make_unique<DriveFsBootstrapListenerForTest>( return std::make_unique<DriveFsBootstrapListenerForTest>(
std::move(pending_bootstrap)); bootstrap_receiver_.BindNewPipeAndPassRemote());
} }
base::UnguessableToken ListenForConnection() { base::UnguessableToken ListenForConnection() {
...@@ -91,7 +94,7 @@ class DriveFsBootstrapTest : public testing::Test, ...@@ -91,7 +94,7 @@ class DriveFsBootstrapTest : public testing::Test,
ASSERT_TRUE( ASSERT_TRUE(
PendingConnectionManager::Get().OpenIpcChannel(token.ToString(), {})); PendingConnectionManager::Get().OpenIpcChannel(token.ToString(), {}));
base::RunLoop run_loop; base::RunLoop run_loop;
bootstrap_binding_.set_connection_error_handler(run_loop.QuitClosure()); bootstrap_receiver_.set_disconnect_handler(run_loop.QuitClosure());
run_loop.Run(); run_loop.Run();
} }
...@@ -99,11 +102,11 @@ class DriveFsBootstrapTest : public testing::Test, ...@@ -99,11 +102,11 @@ class DriveFsBootstrapTest : public testing::Test,
MockDriveFs mock_drivefs_; MockDriveFs mock_drivefs_;
MockDriveFsDelegate mock_delegate_; MockDriveFsDelegate mock_delegate_;
mojo::Binding<mojom::DriveFsBootstrap> bootstrap_binding_; mojo::Receiver<mojom::DriveFsBootstrap> bootstrap_receiver_{this};
mojo::Binding<mojom::DriveFs> binding_; mojo::Receiver<mojom::DriveFs> receiver_{&mock_drivefs_};
std::unique_ptr<DriveFsConnection> connection_; std::unique_ptr<DriveFsConnection> connection_;
mojom::DriveFsDelegatePtr delegate_ptr_; mojo::Remote<mojom::DriveFsDelegate> delegate_;
mojom::DriveFsDelegateRequest pending_delegate_request_; mojo::PendingReceiver<mojom::DriveFsDelegate> pending_delegate_receiver_;
std::string email_; std::string email_;
DISALLOW_COPY_AND_ASSIGN(DriveFsBootstrapTest); DISALLOW_COPY_AND_ASSIGN(DriveFsBootstrapTest);
...@@ -116,7 +119,7 @@ TEST_F(DriveFsBootstrapTest, Listen_Connect_Disconnect) { ...@@ -116,7 +119,7 @@ TEST_F(DriveFsBootstrapTest, Listen_Connect_Disconnect) {
EXPECT_CALL(*this, OnInit()); EXPECT_CALL(*this, OnInit());
WaitForConnection(token); WaitForConnection(token);
EXPECT_CALL(*this, OnDisconnect()); EXPECT_CALL(*this, OnDisconnect());
binding_.Close(); receiver_.reset();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_FALSE( ASSERT_FALSE(
PendingConnectionManager::Get().OpenIpcChannel(token.ToString(), {})); PendingConnectionManager::Get().OpenIpcChannel(token.ToString(), {}));
...@@ -127,7 +130,7 @@ TEST_F(DriveFsBootstrapTest, Listen_Connect_DisconnectDelegate) { ...@@ -127,7 +130,7 @@ TEST_F(DriveFsBootstrapTest, Listen_Connect_DisconnectDelegate) {
EXPECT_CALL(*this, OnInit()); EXPECT_CALL(*this, OnInit());
WaitForConnection(token); WaitForConnection(token);
EXPECT_CALL(*this, OnDisconnect()); EXPECT_CALL(*this, OnDisconnect());
delegate_ptr_.reset(); delegate_.reset();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ASSERT_FALSE( ASSERT_FALSE(
PendingConnectionManager::Get().OpenIpcChannel(token.ToString(), {})); PendingConnectionManager::Get().OpenIpcChannel(token.ToString(), {}));
...@@ -156,7 +159,7 @@ TEST_F(DriveFsBootstrapTest, Listen_Destroy) { ...@@ -156,7 +159,7 @@ TEST_F(DriveFsBootstrapTest, Listen_Destroy) {
TEST_F(DriveFsBootstrapTest, Listen_DisconnectDelegate) { TEST_F(DriveFsBootstrapTest, Listen_DisconnectDelegate) {
EXPECT_CALL(*this, OnDisconnect()).Times(0); EXPECT_CALL(*this, OnDisconnect()).Times(0);
ListenForConnection(); ListenForConnection();
delegate_ptr_.reset(); delegate_.reset();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
......
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
#include "chromeos/components/drivefs/drivefs_search.h" #include "chromeos/components/drivefs/drivefs_search.h"
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/cpp/network_connection_tracker.h" #include "services/network/public/cpp/network_connection_tracker.h"
namespace drivefs { namespace drivefs {
...@@ -44,7 +48,7 @@ mojom::QueryParameters::QuerySource DriveFsSearch::PerformSearch( ...@@ -44,7 +48,7 @@ mojom::QueryParameters::QuerySource DriveFsSearch::PerformSearch(
} }
} }
drivefs::mojom::SearchQueryPtr search; mojo::Remote<drivefs::mojom::SearchQuery> search;
drivefs::mojom::QueryParameters::QuerySource source = query->query_source; drivefs::mojom::QueryParameters::QuerySource source = query->query_source;
if (network_connection_tracker_->IsOffline() && if (network_connection_tracker_->IsOffline() &&
source != drivefs::mojom::QueryParameters::QuerySource::kLocalOnly) { source != drivefs::mojom::QueryParameters::QuerySource::kLocalOnly) {
...@@ -53,7 +57,8 @@ mojom::QueryParameters::QuerySource DriveFsSearch::PerformSearch( ...@@ -53,7 +57,8 @@ mojom::QueryParameters::QuerySource DriveFsSearch::PerformSearch(
OnSearchDriveFs(std::move(search), std::move(query), std::move(callback), OnSearchDriveFs(std::move(search), std::move(query), std::move(callback),
drive::FILE_ERROR_NO_CONNECTION, {}); drive::FILE_ERROR_NO_CONNECTION, {});
} else { } else {
drivefs_->StartSearchQuery(mojo::MakeRequest(&search), query.Clone()); drivefs_->StartSearchQuery(search.BindNewPipeAndPassReceiver(),
query.Clone());
auto* raw_search = search.get(); auto* raw_search = search.get();
raw_search->GetNextPage(base::BindOnce( raw_search->GetNextPage(base::BindOnce(
&DriveFsSearch::OnSearchDriveFs, weak_ptr_factory_.GetWeakPtr(), &DriveFsSearch::OnSearchDriveFs, weak_ptr_factory_.GetWeakPtr(),
...@@ -63,7 +68,7 @@ mojom::QueryParameters::QuerySource DriveFsSearch::PerformSearch( ...@@ -63,7 +68,7 @@ mojom::QueryParameters::QuerySource DriveFsSearch::PerformSearch(
} }
void DriveFsSearch::OnSearchDriveFs( void DriveFsSearch::OnSearchDriveFs(
drivefs::mojom::SearchQueryPtr search, mojo::Remote<drivefs::mojom::SearchQuery> search,
drivefs::mojom::QueryParametersPtr query, drivefs::mojom::QueryParametersPtr query,
mojom::SearchQuery::GetNextPageCallback callback, mojom::SearchQuery::GetNextPageCallback callback,
drive::FileError error, drive::FileError error,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/time/clock.h" #include "base/time/clock.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h" #include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace network { namespace network {
class NetworkConnectionTracker; class NetworkConnectionTracker;
...@@ -37,7 +38,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsSearch { ...@@ -37,7 +38,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsSearch {
private: private:
void OnSearchDriveFs( void OnSearchDriveFs(
drivefs::mojom::SearchQueryPtr search, mojo::Remote<drivefs::mojom::SearchQuery> search,
drivefs::mojom::QueryParametersPtr query, drivefs::mojom::QueryParametersPtr query,
mojom::SearchQuery::GetNextPageCallback callback, mojom::SearchQuery::GetNextPageCallback callback,
drive::FileError error, drive::FileError error,
......
...@@ -4,12 +4,16 @@ ...@@ -4,12 +4,16 @@
#include "chromeos/components/drivefs/drivefs_search.h" #include "chromeos/components/drivefs/drivefs_search.h"
#include <utility>
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/simple_test_clock.h" #include "base/test/simple_test_clock.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom-test-utils.h" #include "chromeos/components/drivefs/mojom/drivefs.mojom-test-utils.h"
#include "mojo/public/cpp/bindings/binding.h" #include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/network/test/test_network_connection_tracker.h" #include "services/network/test/test_network_connection_tracker.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -22,7 +26,7 @@ using testing::_; ...@@ -22,7 +26,7 @@ using testing::_;
class MockDriveFs : public mojom::DriveFsInterceptorForTesting, class MockDriveFs : public mojom::DriveFsInterceptorForTesting,
public mojom::SearchQuery { public mojom::SearchQuery {
public: public:
MockDriveFs() : search_binding_(this) {} MockDriveFs() = default;
DriveFs* GetForwardingInterface() override { DriveFs* GetForwardingInterface() override {
NOTREACHED(); NOTREACHED();
...@@ -30,12 +34,11 @@ class MockDriveFs : public mojom::DriveFsInterceptorForTesting, ...@@ -30,12 +34,11 @@ class MockDriveFs : public mojom::DriveFsInterceptorForTesting,
} }
MOCK_CONST_METHOD1(OnStartSearchQuery, void(const mojom::QueryParameters&)); MOCK_CONST_METHOD1(OnStartSearchQuery, void(const mojom::QueryParameters&));
void StartSearchQuery(mojom::SearchQueryRequest query, void StartSearchQuery(mojo::PendingReceiver<mojom::SearchQuery> receiver,
mojom::QueryParametersPtr query_params) override { mojom::QueryParametersPtr query_params) override {
if (search_binding_.is_bound()) search_receiver_.reset();
search_binding_.Unbind();
OnStartSearchQuery(*query_params); OnStartSearchQuery(*query_params);
search_binding_.Bind(std::move(query)); search_receiver_.Bind(std::move(receiver));
} }
MOCK_METHOD1(OnGetNextPage, MOCK_METHOD1(OnGetNextPage,
...@@ -49,7 +52,7 @@ class MockDriveFs : public mojom::DriveFsInterceptorForTesting, ...@@ -49,7 +52,7 @@ class MockDriveFs : public mojom::DriveFsInterceptorForTesting,
} }
private: private:
mojo::Binding<mojom::SearchQuery> search_binding_; mojo::Receiver<mojom::SearchQuery> search_receiver_{this};
DISALLOW_COPY_AND_ASSIGN(MockDriveFs); DISALLOW_COPY_AND_ASSIGN(MockDriveFs);
}; };
......
...@@ -20,9 +20,12 @@ ...@@ -20,9 +20,12 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "chromeos/components/drivefs/drivefs_util.h" #include "chromeos/components/drivefs/drivefs_util.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cros_disks_client.h" #include "chromeos/dbus/fake_cros_disks_client.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
namespace drivefs { namespace drivefs {
namespace { namespace {
...@@ -70,15 +73,16 @@ base::FilePath MaybeMountDriveFs( ...@@ -70,15 +73,16 @@ base::FilePath MaybeMountDriveFs(
} // namespace } // namespace
FakeDriveFsBootstrapListener::FakeDriveFsBootstrapListener( FakeDriveFsBootstrapListener::FakeDriveFsBootstrapListener(
drivefs::mojom::DriveFsBootstrapPtrInfo bootstrap) mojo::PendingRemote<drivefs::mojom::DriveFsBootstrap> bootstrap)
: bootstrap_(std::move(bootstrap)) {} : bootstrap_(std::move(bootstrap)) {}
FakeDriveFsBootstrapListener::~FakeDriveFsBootstrapListener() = default; FakeDriveFsBootstrapListener::~FakeDriveFsBootstrapListener() = default;
void FakeDriveFsBootstrapListener::SendInvitationOverPipe(base::ScopedFD) {} void FakeDriveFsBootstrapListener::SendInvitationOverPipe(base::ScopedFD) {}
mojom::DriveFsBootstrapPtr FakeDriveFsBootstrapListener::bootstrap() { mojo::PendingRemote<mojom::DriveFsBootstrap>
return mojo::MakeProxy(std::move(bootstrap_)); FakeDriveFsBootstrapListener::bootstrap() {
return std::move(bootstrap_);
} }
struct FakeDriveFs::FileMetadata { struct FakeDriveFs::FileMetadata {
...@@ -227,7 +231,7 @@ class FakeDriveFs::SearchQuery : public mojom::SearchQuery { ...@@ -227,7 +231,7 @@ class FakeDriveFs::SearchQuery : public mojom::SearchQuery {
}; };
FakeDriveFs::FakeDriveFs(const base::FilePath& mount_path) FakeDriveFs::FakeDriveFs(const base::FilePath& mount_path)
: mount_path_(mount_path), binding_(this), bootstrap_binding_(this) { : mount_path_(mount_path) {
CHECK(mount_path.IsAbsolute()); CHECK(mount_path.IsAbsolute());
CHECK(!mount_path.ReferencesParent()); CHECK(!mount_path.ReferencesParent());
} }
...@@ -248,13 +252,13 @@ void FakeDriveFs::RegisterMountingForAccountId( ...@@ -248,13 +252,13 @@ void FakeDriveFs::RegisterMountingForAccountId(
std::unique_ptr<drivefs::DriveFsBootstrapListener> std::unique_ptr<drivefs::DriveFsBootstrapListener>
FakeDriveFs::CreateMojoListener() { FakeDriveFs::CreateMojoListener() {
drivefs::mojom::DriveFsBootstrapPtrInfo bootstrap; delegate_.reset();
if (bootstrap_binding_.is_bound()) pending_delegate_receiver_ = delegate_.BindNewPipeAndPassReceiver();
bootstrap_binding_.Unbind();
bootstrap_binding_.Bind(mojo::MakeRequest(&bootstrap));
pending_delegate_request_ = mojo::MakeRequest(&delegate_);
delegate_->OnMounted(); delegate_->OnMounted();
return std::make_unique<FakeDriveFsBootstrapListener>(std::move(bootstrap));
bootstrap_receiver_.reset();
return std::make_unique<FakeDriveFsBootstrapListener>(
bootstrap_receiver_.BindNewPipeAndPassRemote());
} }
void FakeDriveFs::SetMetadata(const base::FilePath& path, void FakeDriveFs::SetMetadata(const base::FilePath& path,
...@@ -278,18 +282,17 @@ void FakeDriveFs::SetMetadata(const base::FilePath& path, ...@@ -278,18 +282,17 @@ void FakeDriveFs::SetMetadata(const base::FilePath& path,
} }
} }
void FakeDriveFs::Init(drivefs::mojom::DriveFsConfigurationPtr config, void FakeDriveFs::Init(
drivefs::mojom::DriveFsRequest drive_fs_request, drivefs::mojom::DriveFsConfigurationPtr config,
drivefs::mojom::DriveFsDelegatePtr delegate) { mojo::PendingReceiver<drivefs::mojom::DriveFs> receiver,
mojo::PendingRemote<drivefs::mojom::DriveFsDelegate> delegate) {
{ {
base::ScopedAllowBlockingForTesting allow_io; base::ScopedAllowBlockingForTesting allow_io;
CHECK(base::CreateDirectory(mount_path_.Append(".Trash"))); CHECK(base::CreateDirectory(mount_path_.Append(".Trash")));
} }
mojo::FuseInterface(std::move(pending_delegate_request_), mojo::FusePipes(std::move(pending_delegate_receiver_), std::move(delegate));
delegate.PassInterface()); receiver_.reset();
if (binding_.is_bound()) receiver_.Bind(std::move(receiver));
binding_.Unbind();
binding_.Bind(std::move(drive_fs_request));
} }
void FakeDriveFs::GetMetadata(const base::FilePath& path, void FakeDriveFs::GetMetadata(const base::FilePath& path,
...@@ -401,11 +404,11 @@ void FakeDriveFs::CopyFile(const base::FilePath& source, ...@@ -401,11 +404,11 @@ void FakeDriveFs::CopyFile(const base::FilePath& source,
} }
void FakeDriveFs::StartSearchQuery( void FakeDriveFs::StartSearchQuery(
drivefs::mojom::SearchQueryRequest query, mojo::PendingReceiver<drivefs::mojom::SearchQuery> receiver,
drivefs::mojom::QueryParametersPtr query_params) { drivefs::mojom::QueryParametersPtr query_params) {
auto search_query = std::make_unique<SearchQuery>(weak_factory_.GetWeakPtr(), auto search_query = std::make_unique<SearchQuery>(weak_factory_.GetWeakPtr(),
std::move(query_params)); std::move(query_params));
mojo::MakeStrongBinding(std::move(search_query), std::move(query)); mojo::MakeSelfOwnedReceiver(std::move(search_query), std::move(receiver));
} }
void FakeDriveFs::FetchAllChangeLogs() {} void FakeDriveFs::FetchAllChangeLogs() {}
......
...@@ -16,21 +16,24 @@ ...@@ -16,21 +16,24 @@
#include "chromeos/components/drivefs/drivefs_bootstrap.h" #include "chromeos/components/drivefs/drivefs_bootstrap.h"
#include "chromeos/components/drivefs/drivefs_host.h" #include "chromeos/components/drivefs/drivefs_host.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h" #include "chromeos/components/drivefs/mojom/drivefs.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/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace drivefs { namespace drivefs {
class FakeDriveFsBootstrapListener : public DriveFsBootstrapListener { class FakeDriveFsBootstrapListener : public DriveFsBootstrapListener {
public: public:
explicit FakeDriveFsBootstrapListener( explicit FakeDriveFsBootstrapListener(
drivefs::mojom::DriveFsBootstrapPtrInfo bootstrap); mojo::PendingRemote<drivefs::mojom::DriveFsBootstrap> bootstrap);
~FakeDriveFsBootstrapListener() override; ~FakeDriveFsBootstrapListener() override;
private: private:
void SendInvitationOverPipe(base::ScopedFD) override; void SendInvitationOverPipe(base::ScopedFD) override;
mojom::DriveFsBootstrapPtr bootstrap() override; mojo::PendingRemote<mojom::DriveFsBootstrap> bootstrap() override;
drivefs::mojom::DriveFsBootstrapPtrInfo bootstrap_; mojo::PendingRemote<drivefs::mojom::DriveFsBootstrap> bootstrap_;
DISALLOW_COPY_AND_ASSIGN(FakeDriveFsBootstrapListener); DISALLOW_COPY_AND_ASSIGN(FakeDriveFsBootstrapListener);
}; };
...@@ -61,9 +64,10 @@ class FakeDriveFs : public drivefs::mojom::DriveFs, ...@@ -61,9 +64,10 @@ class FakeDriveFs : public drivefs::mojom::DriveFs,
class SearchQuery; class SearchQuery;
// drivefs::mojom::DriveFsBootstrap: // drivefs::mojom::DriveFsBootstrap:
void Init(drivefs::mojom::DriveFsConfigurationPtr config, void Init(
drivefs::mojom::DriveFsRequest drive_fs_request, drivefs::mojom::DriveFsConfigurationPtr config,
drivefs::mojom::DriveFsDelegatePtr delegate) override; mojo::PendingReceiver<drivefs::mojom::DriveFs> receiver,
mojo::PendingRemote<drivefs::mojom::DriveFsDelegate> delegate) override;
// drivefs::mojom::DriveFs: // drivefs::mojom::DriveFs:
void GetMetadata(const base::FilePath& path, void GetMetadata(const base::FilePath& path,
...@@ -86,7 +90,7 @@ class FakeDriveFs : public drivefs::mojom::DriveFs, ...@@ -86,7 +90,7 @@ class FakeDriveFs : public drivefs::mojom::DriveFs,
CopyFileCallback callback) override; CopyFileCallback callback) override;
void StartSearchQuery( void StartSearchQuery(
drivefs::mojom::SearchQueryRequest query, mojo::PendingReceiver<drivefs::mojom::SearchQuery> receiver,
drivefs::mojom::QueryParametersPtr query_params) override; drivefs::mojom::QueryParametersPtr query_params) override;
void FetchAllChangeLogs() override; void FetchAllChangeLogs() override;
...@@ -98,10 +102,11 @@ class FakeDriveFs : public drivefs::mojom::DriveFs, ...@@ -98,10 +102,11 @@ class FakeDriveFs : public drivefs::mojom::DriveFs,
std::map<base::FilePath, FileMetadata> metadata_; std::map<base::FilePath, FileMetadata> metadata_;
mojo::Binding<drivefs::mojom::DriveFs> binding_; mojo::Receiver<drivefs::mojom::DriveFs> receiver_{this};
drivefs::mojom::DriveFsDelegatePtr delegate_; mojo::Remote<drivefs::mojom::DriveFsDelegate> delegate_;
mojo::Binding<drivefs::mojom::DriveFsBootstrap> bootstrap_binding_; mojo::Receiver<drivefs::mojom::DriveFsBootstrap> bootstrap_receiver_{this};
drivefs::mojom::DriveFsDelegateRequest pending_delegate_request_; mojo::PendingReceiver<drivefs::mojom::DriveFsDelegate>
pending_delegate_receiver_;
base::WeakPtrFactory<FakeDriveFs> weak_factory_{this}; base::WeakPtrFactory<FakeDriveFs> weak_factory_{this};
......
...@@ -14,8 +14,8 @@ import "mojo/public/mojom/base/time.mojom"; ...@@ -14,8 +14,8 @@ import "mojo/public/mojom/base/time.mojom";
interface DriveFsBootstrap { interface DriveFsBootstrap {
// Initialize a DriveFS instance with its configuration and mojo connections // Initialize a DriveFS instance with its configuration and mojo connections
// to the browser. // to the browser.
Init(DriveFsConfiguration config, DriveFs& drive_fs, Init(DriveFsConfiguration config, pending_receiver<DriveFs> drive_fs,
DriveFsDelegate delegate); pending_remote<DriveFsDelegate> delegate);
}; };
// Implemented by DriveFS, used from Chrome. // Implemented by DriveFS, used from Chrome.
...@@ -49,7 +49,8 @@ interface DriveFs { ...@@ -49,7 +49,8 @@ interface DriveFs {
(FileError error); (FileError error);
// Start a search query with given parameters. // Start a search query with given parameters.
StartSearchQuery(SearchQuery& query, QueryParameters query_params); StartSearchQuery(pending_receiver<SearchQuery> query,
QueryParameters query_params);
// Fetches all changelogs, i.e. for My Drive and all Team Drives. // Fetches all changelogs, i.e. for My Drive and all Team Drives.
FetchAllChangeLogs(); FetchAllChangeLogs();
......
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