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 @@
#include "chrome/browser/chromeos/file_manager/file_tasks_observer.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.h"
#include "components/drive/file_errors.h"
#include "content/public/test/browser_task_environment.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/file_system_url.h"
#include "storage/common/fileapi/file_system_types.h"
......@@ -97,7 +100,8 @@ class MockFileTasksObserver : public file_tasks::FileTasksObserver {
class FileTasksNotifierForTest : public FileTasksNotifier {
public:
FileTasksNotifierForTest(Profile* profile, drivefs::mojom::DriveFsPtr drivefs)
FileTasksNotifierForTest(Profile* profile,
mojo::PendingRemote<drivefs::mojom::DriveFs> drivefs)
: FileTasksNotifier(profile), drivefs_(std::move(drivefs)) {}
drivefs::mojom::DriveFs* GetDriveFsInterface() override {
......@@ -115,21 +119,19 @@ class FileTasksNotifierForTest : public FileTasksNotifier {
void set_is_offline(bool is_offline) { is_offline_ = is_offline; }
private:
const drivefs::mojom::DriveFsPtr drivefs_;
const mojo::Remote<drivefs::mojom::DriveFs> drivefs_;
bool is_offline_ = false;
};
class FileTasksNotifierTest : public testing::Test {
protected:
FileTasksNotifierTest() : drivefs_binding_(&fake_drivefs_) {}
FileTasksNotifierTest() = default;
void SetUp() override {
profile_ = std::make_unique<TestingProfile>();
drivefs::mojom::DriveFsPtr fake_drivefs_ptr;
drivefs_binding_.Bind(mojo::MakeRequest(&fake_drivefs_ptr));
notifier_ = std::make_unique<FileTasksNotifierForTest>(
profile_.get(), std::move(fake_drivefs_ptr));
profile_.get(), drivefs_receiver_.BindNewPipeAndPassRemote());
observer_ = std::make_unique<MockFileTasksObserver>(notifier_.get());
auto* mount_points = storage::ExternalMountPoints::GetSystemInstance();
......@@ -175,7 +177,7 @@ class FileTasksNotifierTest : public testing::Test {
private:
content::BrowserTaskEnvironment task_environment_;
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<FileTasksNotifierForTest> notifier_;
std::unique_ptr<MockFileTasksObserver> observer_;
......
......@@ -65,7 +65,7 @@ void RecentDriveSource::GetRecentFiles(Params params) {
query_params->sort_direction =
drivefs::mojom::QueryParameters::SortDirection::kDescending;
integration_service->GetDriveFsInterface()->StartSearchQuery(
mojo::MakeRequest(&search_query_), std::move(query_params));
search_query_.BindNewPipeAndPassReceiver(), std::move(query_params));
search_query_->GetNextPage(base::BindOnce(
&RecentDriveSource::GotSearchResults, weak_ptr_factory_.GetWeakPtr()));
}
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/chromeos/fileapi/recent_source.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "components/drive/file_errors.h"
#include "mojo/public/cpp/bindings/remote.h"
class Profile;
......@@ -55,7 +56,7 @@ class RecentDriveSource : public RecentSource {
std::vector<RecentFile> files_;
drivefs::mojom::SearchQueryPtr search_query_;
mojo::Remote<drivefs::mojom::SearchQuery> search_query_;
base::WeakPtrFactory<RecentDriveSource> weak_ptr_factory_{this};
......
......@@ -7,16 +7,18 @@
#include <utility>
#include "base/bind.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.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/system/invitation.h"
namespace drivefs {
DriveFsBootstrapListener::DriveFsBootstrapListener()
: bootstrap_(mojo::MakeProxy(mojom::DriveFsBootstrapPtrInfo(
invitation_.AttachMessagePipe("drivefs-bootstrap"),
mojom::DriveFsBootstrap::Version_))),
: bootstrap_(invitation_.AttachMessagePipe("drivefs-bootstrap"),
mojom::DriveFsBootstrap::Version_),
pending_token_(base::UnguessableToken::Create()) {
PendingConnectionManager::Get().ExpectOpenIpcChannel(
pending_token_,
......@@ -32,7 +34,8 @@ DriveFsBootstrapListener::~DriveFsBootstrapListener() {
}
}
mojom::DriveFsBootstrapPtr DriveFsBootstrapListener::bootstrap() {
mojo::PendingRemote<mojom::DriveFsBootstrap>
DriveFsBootstrapListener::bootstrap() {
return std::move(bootstrap_);
}
......@@ -61,22 +64,20 @@ class DriveFsConnectionImpl : public DriveFsConnection {
base::UnguessableToken Connect(mojom::DriveFsDelegate* delegate,
base::OnceClosure on_disconnected) override {
delegate_binding_ =
std::make_unique<mojo::Binding<mojom::DriveFsDelegate>>(delegate);
delegate_receiver_ =
std::make_unique<mojo::Receiver<mojom::DriveFsDelegate>>(delegate);
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();
mojom::DriveFsDelegatePtr delegate_ptr;
delegate_binding_->Bind(mojo::MakeRequest(&delegate_ptr));
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));
bootstrap->Init(std::move(config_), drivefs_.BindNewPipeAndPassReceiver(),
delegate_receiver_->BindNewPipeAndPassRemote());
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)));
return token;
......@@ -97,8 +98,8 @@ class DriveFsConnectionImpl : public DriveFsConnection {
const std::unique_ptr<DriveFsBootstrapListener> bootstrap_listener_;
mojom::DriveFsConfigurationPtr config_;
std::unique_ptr<mojo::Binding<mojom::DriveFsDelegate>> delegate_binding_;
mojom::DriveFsPtr drivefs_;
std::unique_ptr<mojo::Receiver<mojom::DriveFsDelegate>> delegate_receiver_;
mojo::Remote<mojom::DriveFs> drivefs_;
base::OnceClosure on_disconnected_;
......
......@@ -12,7 +12,7 @@
#include "base/macros.h"
#include "base/unguessable_token.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"
namespace drivefs {
......@@ -24,7 +24,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsBootstrapListener {
virtual ~DriveFsBootstrapListener();
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_; }
protected:
......@@ -35,7 +35,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsBootstrapListener {
void AcceptMojoConnection(base::ScopedFD handle);
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
// this instance.
......
......@@ -5,12 +5,18 @@
#include "chromeos/components/drivefs/drivefs_bootstrap.h"
#include <memory>
#include <utility>
#include "base/bind.h"
#include "base/run_loop.h"
#include "base/test/task_environment.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 "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/gtest/include/gtest/gtest.h"
......@@ -38,17 +44,17 @@ class MockDriveFsDelegate : public mojom::DriveFsDelegateInterceptorForTesting {
class DriveFsBootstrapListenerForTest : public DriveFsBootstrapListener {
public:
DriveFsBootstrapListenerForTest(
mojom::DriveFsBootstrapPtrInfo available_bootstrap)
mojo::PendingRemote<mojom::DriveFsBootstrap> available_bootstrap)
: available_bootstrap_(std::move(available_bootstrap)) {}
mojom::DriveFsBootstrapPtr bootstrap() override {
return mojo::MakeProxy(std::move(available_bootstrap_));
mojo::PendingRemote<mojom::DriveFsBootstrap> bootstrap() override {
return std::move(available_bootstrap_);
}
void SendInvitationOverPipe(base::ScopedFD) override {}
private:
mojom::DriveFsBootstrapPtrInfo available_bootstrap_;
mojo::PendingRemote<mojom::DriveFsBootstrap> available_bootstrap_;
DISALLOW_COPY_AND_ASSIGN(DriveFsBootstrapListenerForTest);
};
......@@ -56,27 +62,24 @@ class DriveFsBootstrapListenerForTest : public DriveFsBootstrapListener {
class DriveFsBootstrapTest : public testing::Test,
public mojom::DriveFsBootstrap {
public:
DriveFsBootstrapTest() : bootstrap_binding_(this), binding_(&mock_drivefs_) {}
DriveFsBootstrapTest() = default;
protected:
MOCK_CONST_METHOD0(OnDisconnect, void());
MOCK_CONST_METHOD0(OnInit, void());
void Init(mojom::DriveFsConfigurationPtr config,
mojom::DriveFsRequest drive_fs_request,
mojom::DriveFsDelegatePtr delegate) override {
binding_.Bind(std::move(drive_fs_request));
mojo::FuseInterface(std::move(pending_delegate_request_),
delegate.PassInterface());
mojo::PendingReceiver<mojom::DriveFs> drive_fs_receiver,
mojo::PendingRemote<mojom::DriveFsDelegate> delegate) override {
receiver_.Bind(std::move(drive_fs_receiver));
mojo::FusePipes(std::move(pending_delegate_receiver_), std::move(delegate));
OnInit();
}
std::unique_ptr<DriveFsBootstrapListener> CreateListener() {
mojom::DriveFsBootstrapPtrInfo pending_bootstrap;
bootstrap_binding_.Bind(mojo::MakeRequest(&pending_bootstrap));
pending_delegate_request_ = mojo::MakeRequest(&delegate_ptr_);
pending_delegate_receiver_ = delegate_.BindNewPipeAndPassReceiver();
return std::make_unique<DriveFsBootstrapListenerForTest>(
std::move(pending_bootstrap));
bootstrap_receiver_.BindNewPipeAndPassRemote());
}
base::UnguessableToken ListenForConnection() {
......@@ -91,7 +94,7 @@ class DriveFsBootstrapTest : public testing::Test,
ASSERT_TRUE(
PendingConnectionManager::Get().OpenIpcChannel(token.ToString(), {}));
base::RunLoop run_loop;
bootstrap_binding_.set_connection_error_handler(run_loop.QuitClosure());
bootstrap_receiver_.set_disconnect_handler(run_loop.QuitClosure());
run_loop.Run();
}
......@@ -99,11 +102,11 @@ class DriveFsBootstrapTest : public testing::Test,
MockDriveFs mock_drivefs_;
MockDriveFsDelegate mock_delegate_;
mojo::Binding<mojom::DriveFsBootstrap> bootstrap_binding_;
mojo::Binding<mojom::DriveFs> binding_;
mojo::Receiver<mojom::DriveFsBootstrap> bootstrap_receiver_{this};
mojo::Receiver<mojom::DriveFs> receiver_{&mock_drivefs_};
std::unique_ptr<DriveFsConnection> connection_;
mojom::DriveFsDelegatePtr delegate_ptr_;
mojom::DriveFsDelegateRequest pending_delegate_request_;
mojo::Remote<mojom::DriveFsDelegate> delegate_;
mojo::PendingReceiver<mojom::DriveFsDelegate> pending_delegate_receiver_;
std::string email_;
DISALLOW_COPY_AND_ASSIGN(DriveFsBootstrapTest);
......@@ -116,7 +119,7 @@ TEST_F(DriveFsBootstrapTest, Listen_Connect_Disconnect) {
EXPECT_CALL(*this, OnInit());
WaitForConnection(token);
EXPECT_CALL(*this, OnDisconnect());
binding_.Close();
receiver_.reset();
base::RunLoop().RunUntilIdle();
ASSERT_FALSE(
PendingConnectionManager::Get().OpenIpcChannel(token.ToString(), {}));
......@@ -127,7 +130,7 @@ TEST_F(DriveFsBootstrapTest, Listen_Connect_DisconnectDelegate) {
EXPECT_CALL(*this, OnInit());
WaitForConnection(token);
EXPECT_CALL(*this, OnDisconnect());
delegate_ptr_.reset();
delegate_.reset();
base::RunLoop().RunUntilIdle();
ASSERT_FALSE(
PendingConnectionManager::Get().OpenIpcChannel(token.ToString(), {}));
......@@ -156,7 +159,7 @@ TEST_F(DriveFsBootstrapTest, Listen_Destroy) {
TEST_F(DriveFsBootstrapTest, Listen_DisconnectDelegate) {
EXPECT_CALL(*this, OnDisconnect()).Times(0);
ListenForConnection();
delegate_ptr_.reset();
delegate_.reset();
base::RunLoop().RunUntilIdle();
}
......
......@@ -21,13 +21,18 @@
#include "chromeos/components/drivefs/drivefs_host_observer.h"
#include "chromeos/components/drivefs/fake_drivefs.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/disks/mock_disk_mount_manager.h"
#include "components/drive/drive_notification_manager.h"
#include "components/drive/drive_notification_observer.h"
#include "components/invalidation/impl/fake_invalidation_service.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/clone_traits.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/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/identity/public/mojom/identity_accessor.mojom-test-utils.h"
#include "services/identity/public/mojom/identity_service.mojom.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
......@@ -43,7 +48,7 @@ using MountFailure = DriveFsHost::MountObserver::MountFailure;
class MockDriveFs : public mojom::DriveFsInterceptorForTesting,
public mojom::SearchQuery {
public:
MockDriveFs() : search_binding_(this) {}
MockDriveFs() = default;
DriveFs* GetForwardingInterface() override {
NOTREACHED();
......@@ -65,12 +70,11 @@ class MockDriveFs : public mojom::DriveFsInterceptorForTesting,
MOCK_METHOD0(FetchAllChangeLogs, void());
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 {
if (search_binding_.is_bound())
search_binding_.Unbind();
search_receiver_.reset();
OnStartSearchQuery(*query_params);
search_binding_.Bind(std::move(query));
search_receiver_.Bind(std::move(receiver));
}
MOCK_METHOD1(OnGetNextPage,
......@@ -84,7 +88,7 @@ class MockDriveFs : public mojom::DriveFsInterceptorForTesting,
}
private:
mojo::Binding<mojom::SearchQuery> search_binding_;
mojo::Receiver<mojom::SearchQuery> search_receiver_{this};
};
class TestingDriveFsHostDelegate : public DriveFsHost::Delegate,
......@@ -100,7 +104,8 @@ class TestingDriveFsHostDelegate : public DriveFsHost::Delegate,
drive_notification_manager_.Shutdown();
}
void set_pending_bootstrap(mojom::DriveFsBootstrapPtrInfo pending_bootstrap) {
void set_pending_bootstrap(
mojo::PendingRemote<mojom::DriveFsBootstrap> pending_bootstrap) {
pending_bootstrap_ = std::move(pending_bootstrap);
}
......@@ -147,7 +152,7 @@ class TestingDriveFsHostDelegate : public DriveFsHost::Delegate,
identity::mojom::IdentityService* const identity_service_;
const AccountId account_id_;
mojom::DriveFsBootstrapPtrInfo pending_bootstrap_;
mojo::PendingRemote<mojom::DriveFsBootstrap> pending_bootstrap_;
invalidation::FakeInvalidationService invalidation_service_;
drive::DriveNotificationManager drive_notification_manager_;
......@@ -257,9 +262,7 @@ class DriveFsHostTest : public ::testing::Test, public mojom::DriveFsBootstrap {
DriveFsHostTest()
: network_connection_tracker_(
network::TestNetworkConnectionTracker::CreateInstance()),
mock_identity_accessor_(&clock_),
bootstrap_binding_(this),
binding_(&mock_drivefs_) {
mock_identity_accessor_(&clock_) {
clock_.SetNow(base::Time::Now());
}
......@@ -306,10 +309,9 @@ class DriveFsHostTest : public ::testing::Test, public mojom::DriveFsBootstrap {
_, chromeos::MOUNT_ACCESS_MODE_READ_WRITE))
.WillOnce(testing::SaveArg<0>(&source));
mojom::DriveFsBootstrapPtrInfo bootstrap;
bootstrap_binding_.Bind(mojo::MakeRequest(&bootstrap));
host_delegate_->set_pending_bootstrap(std::move(bootstrap));
pending_delegate_request_ = mojo::MakeRequest(&delegate_ptr_);
host_delegate_->set_pending_bootstrap(
bootstrap_receiver_.BindNewPipeAndPassRemote());
pending_delegate_receiver_ = delegate_.BindNewPipeAndPassReceiver();
EXPECT_TRUE(host_->Mount());
testing::Mock::VerifyAndClear(&disk_manager_);
......@@ -326,14 +328,14 @@ class DriveFsHostTest : public ::testing::Test, public mojom::DriveFsBootstrap {
{}});
}
void SendOnMounted() { delegate_ptr_->OnMounted(); }
void SendOnMounted() { delegate_->OnMounted(); }
void SendOnUnmounted(base::Optional<base::TimeDelta> delay) {
delegate_ptr_->OnUnmounted(std::move(delay));
delegate_->OnUnmounted(std::move(delay));
}
void SendMountFailed(base::Optional<base::TimeDelta> delay) {
delegate_ptr_->OnMountFailed(std::move(delay));
delegate_->OnMountFailed(std::move(delay));
}
void EstablishConnection() {
......@@ -343,7 +345,7 @@ class DriveFsHostTest : public ::testing::Test, public mojom::DriveFsBootstrap {
ASSERT_TRUE(PendingConnectionManager::Get().OpenIpcChannel(token_, {}));
{
base::RunLoop run_loop;
bootstrap_binding_.set_connection_error_handler(run_loop.QuitClosure());
bootstrap_receiver_.set_disconnect_handler(run_loop.QuitClosure());
run_loop.Run();
}
}
......@@ -366,9 +368,9 @@ class DriveFsHostTest : public ::testing::Test, public mojom::DriveFsBootstrap {
void DoUnmount() {
EXPECT_CALL(*host_delegate_, OnUnmounted(_)).Times(0);
host_->Unmount();
binding_.Unbind();
bootstrap_binding_.Unbind();
delegate_ptr_.reset();
receiver_.reset();
bootstrap_receiver_.reset();
delegate_.reset();
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(disk_manager_.get());
testing::Mock::VerifyAndClearExpectations(host_delegate_.get());
......@@ -378,7 +380,7 @@ class DriveFsHostTest : public ::testing::Test, public mojom::DriveFsBootstrap {
const std::string& expected_token) {
base::RunLoop run_loop;
auto quit_closure = run_loop.QuitClosure();
delegate_ptr_->GetAccessToken(
delegate_->GetAccessToken(
"client ID", "app ID", {"scope1", "scope2"},
base::BindLambdaForTesting(
[&](mojom::AccessTokenStatus status, const std::string& token) {
......@@ -390,15 +392,14 @@ class DriveFsHostTest : public ::testing::Test, public mojom::DriveFsBootstrap {
}
void Init(mojom::DriveFsConfigurationPtr config,
mojom::DriveFsRequest drive_fs_request,
mojom::DriveFsDelegatePtr delegate) override {
mojo::PendingReceiver<mojom::DriveFs> drive_fs_receiver,
mojo::PendingRemote<mojom::DriveFsDelegate> delegate) override {
EXPECT_EQ("test@example.com", config->user_email);
EXPECT_EQ("recovered files",
config->lost_and_found_directory_name.value_or("<None>"));
init_access_token_ = std::move(config->access_token);
binding_.Bind(std::move(drive_fs_request));
mojo::FuseInterface(std::move(pending_delegate_request_),
delegate.PassInterface());
receiver_.Bind(std::move(drive_fs_receiver));
mojo::FusePipes(std::move(pending_delegate_receiver_), std::move(delegate));
}
base::FilePath profile_path_;
......@@ -414,11 +415,11 @@ class DriveFsHostTest : public ::testing::Test, public mojom::DriveFsBootstrap {
std::unique_ptr<DriveFsHost> host_;
base::MockOneShotTimer* timer_;
mojo::Binding<mojom::DriveFsBootstrap> bootstrap_binding_;
mojo::Receiver<mojom::DriveFsBootstrap> bootstrap_receiver_{this};
MockDriveFs mock_drivefs_;
mojo::Binding<mojom::DriveFs> binding_;
mojom::DriveFsDelegatePtr delegate_ptr_;
mojom::DriveFsDelegateRequest pending_delegate_request_;
mojo::Receiver<mojom::DriveFs> receiver_{&mock_drivefs_};
mojo::Remote<mojom::DriveFsDelegate> delegate_;
mojo::PendingReceiver<mojom::DriveFsDelegate> pending_delegate_receiver_;
std::string token_;
base::Optional<std::string> init_access_token_;
......@@ -445,7 +446,7 @@ TEST_F(DriveFsHostTest, Basic) {
EXPECT_CALL(observer, OnUnmounted());
EXPECT_CALL(*host_delegate_, OnUnmounted(_)).Times(0);
base::RunLoop run_loop;
delegate_ptr_.set_connection_error_handler(run_loop.QuitClosure());
delegate_.set_disconnect_handler(run_loop.QuitClosure());
host_->Unmount();
run_loop.Run();
}
......@@ -536,8 +537,8 @@ TEST_F(DriveFsHostTest, GetAccessToken_UnmountDuringMojoRequest) {
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS))));
base::RunLoop run_loop;
delegate_ptr_.set_connection_error_handler(run_loop.QuitClosure());
delegate_ptr_->GetAccessToken(
delegate_.set_disconnect_handler(run_loop.QuitClosure());
delegate_->GetAccessToken(
"client ID", "app ID", {"scope1", "scope2"},
base::BindLambdaForTesting([](mojom::AccessTokenStatus status,
const std::string& token) { FAIL(); }));
......@@ -564,8 +565,8 @@ TEST_F(DriveFsHostTest, OnSyncingStatusUpdate_ForwardToObservers) {
mojom::SyncingStatusPtr observed_status;
EXPECT_CALL(observer, OnSyncingStatusUpdate(_))
.WillOnce(CloneStruct(&observed_status));
delegate_ptr_->OnSyncingStatusUpdate(status.Clone());
delegate_ptr_.FlushForTesting();
delegate_->OnSyncingStatusUpdate(status.Clone());
delegate_.FlushForTesting();
testing::Mock::VerifyAndClear(&observer);
EXPECT_EQ(status, observed_status);
......@@ -592,8 +593,8 @@ TEST_F(DriveFsHostTest, OnFilesChanged_ForwardToObservers) {
std::vector<mojom::FileChangePtr> observed_changes;
EXPECT_CALL(observer, OnFilesChanged(_))
.WillOnce(CloneVectorOfStructs(&observed_changes));
delegate_ptr_->OnFilesChanged(mojo::Clone(changes));
delegate_ptr_.FlushForTesting();
delegate_->OnFilesChanged(mojo::Clone(changes));
delegate_.FlushForTesting();
testing::Mock::VerifyAndClear(&observer);
EXPECT_EQ(changes, observed_changes);
......@@ -608,8 +609,8 @@ TEST_F(DriveFsHostTest, OnError_ForwardToObservers) {
mojom::DriveError::Type::kCantUploadStorageFull, base::FilePath("/foo"));
mojom::DriveErrorPtr observed_error;
EXPECT_CALL(observer, OnError(_)).WillOnce(CloneStruct(&observed_error));
delegate_ptr_->OnError(error.Clone());
delegate_ptr_.FlushForTesting();
delegate_->OnError(error.Clone());
delegate_.FlushForTesting();
testing::Mock::VerifyAndClear(&observer);
EXPECT_EQ(error, observed_error);
......@@ -621,34 +622,34 @@ TEST_F(DriveFsHostTest, OnError_IgnoreUnknownErrorTypes) {
ScopedObserver<DriveFsHost, DriveFsHostObserver> observer_scoper(&observer);
observer_scoper.Add(host_.get());
EXPECT_CALL(observer, OnError(_)).Times(0);
delegate_ptr_->OnError(mojom::DriveError::New(
delegate_->OnError(mojom::DriveError::New(
static_cast<mojom::DriveError::Type>(
static_cast<std::underlying_type_t<mojom::DriveError::Type>>(
mojom::DriveError::Type::kMaxValue) +
1),
base::FilePath("/foo")));
delegate_ptr_.FlushForTesting();
delegate_.FlushForTesting();
}
TEST_F(DriveFsHostTest, TeamDriveTracking) {
ASSERT_NO_FATAL_FAILURE(DoMount());
delegate_ptr_->OnTeamDrivesListReady({"a", "b"});
delegate_ptr_.FlushForTesting();
delegate_->OnTeamDrivesListReady({"a", "b"});
delegate_.FlushForTesting();
EXPECT_EQ(
(std::set<std::string>{"a", "b"}),
host_delegate_->GetDriveNotificationManager().team_drive_ids_for_test());
delegate_ptr_->OnTeamDriveChanged(
delegate_->OnTeamDriveChanged(
"c", mojom::DriveFsDelegate::CreateOrDelete::kCreated);
delegate_ptr_.FlushForTesting();
delegate_.FlushForTesting();
EXPECT_EQ(
(std::set<std::string>{"a", "b", "c"}),
host_delegate_->GetDriveNotificationManager().team_drive_ids_for_test());
delegate_ptr_->OnTeamDriveChanged(
delegate_->OnTeamDriveChanged(
"b", mojom::DriveFsDelegate::CreateOrDelete::kDeleted);
delegate_ptr_.FlushForTesting();
delegate_.FlushForTesting();
EXPECT_EQ(
(std::set<std::string>{"a", "c"}),
host_delegate_->GetDriveNotificationManager().team_drive_ids_for_test());
......@@ -657,8 +658,8 @@ TEST_F(DriveFsHostTest, TeamDriveTracking) {
TEST_F(DriveFsHostTest, Invalidation) {
ASSERT_NO_FATAL_FAILURE(DoMount());
delegate_ptr_->OnTeamDrivesListReady({"a", "b"});
delegate_ptr_.FlushForTesting();
delegate_->OnTeamDrivesListReady({"a", "b"});
delegate_.FlushForTesting();
EXPECT_CALL(mock_drivefs_,
FetchChangeLogImpl(std::vector<std::pair<int64_t, std::string>>{
......@@ -668,14 +669,14 @@ TEST_F(DriveFsHostTest, Invalidation) {
host_delegate_->GetDriveNotificationManager().observers_for_test()) {
observer.OnNotificationReceived({{"", 123}, {"a", 456}});
}
binding_.FlushForTesting();
receiver_.FlushForTesting();
}
TEST_F(DriveFsHostTest, InvalidateAll) {
ASSERT_NO_FATAL_FAILURE(DoMount());
delegate_ptr_->OnTeamDrivesListReady({"a", "b"});
delegate_ptr_.FlushForTesting();
delegate_->OnTeamDrivesListReady({"a", "b"});
delegate_.FlushForTesting();
EXPECT_CALL(mock_drivefs_, FetchAllChangeLogs());
......@@ -683,14 +684,14 @@ TEST_F(DriveFsHostTest, InvalidateAll) {
host_delegate_->GetDriveNotificationManager().observers_for_test()) {
observer.OnNotificationTimerFired();
}
binding_.FlushForTesting();
receiver_.FlushForTesting();
}
TEST_F(DriveFsHostTest, RemoveDriveNotificationObserver) {
ASSERT_NO_FATAL_FAILURE(DoMount());
delegate_ptr_->OnTeamDrivesListReady({"a", "b"});
delegate_ptr_.FlushForTesting();
delegate_->OnTeamDrivesListReady({"a", "b"});
delegate_.FlushForTesting();
EXPECT_TRUE(host_delegate_->GetDriveNotificationManager()
.observers_for_test()
.might_have_observers());
......@@ -732,7 +733,7 @@ TEST_F(DriveFsHostTest, Remount_RequestInflight) {
ASSERT_NO_FATAL_FAILURE(DoMount());
mock_identity_accessor_.set_pause_requests(true);
delegate_ptr_->GetAccessToken(
delegate_->GetAccessToken(
"client ID", "app ID", {"scope1", "scope2"},
base::BindLambdaForTesting([&](mojom::AccessTokenStatus status,
const std::string& token) { FAIL(); }));
......@@ -759,7 +760,7 @@ TEST_F(DriveFsHostTest, Remount_RequestInflightCompleteAfterMount) {
ASSERT_NO_FATAL_FAILURE(DoMount());
mock_identity_accessor_.set_pause_requests(true);
delegate_ptr_->GetAccessToken(
delegate_->GetAccessToken(
"client ID", "app ID", {"scope1", "scope2"},
base::BindLambdaForTesting([&](mojom::AccessTokenStatus status,
const std::string& token) { FAIL(); }));
......
......@@ -4,7 +4,11 @@
#include "chromeos/components/drivefs/drivefs_search.h"
#include <utility>
#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"
namespace drivefs {
......@@ -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;
if (network_connection_tracker_->IsOffline() &&
source != drivefs::mojom::QueryParameters::QuerySource::kLocalOnly) {
......@@ -53,7 +57,8 @@ mojom::QueryParameters::QuerySource DriveFsSearch::PerformSearch(
OnSearchDriveFs(std::move(search), std::move(query), std::move(callback),
drive::FILE_ERROR_NO_CONNECTION, {});
} else {
drivefs_->StartSearchQuery(mojo::MakeRequest(&search), query.Clone());
drivefs_->StartSearchQuery(search.BindNewPipeAndPassReceiver(),
query.Clone());
auto* raw_search = search.get();
raw_search->GetNextPage(base::BindOnce(
&DriveFsSearch::OnSearchDriveFs, weak_ptr_factory_.GetWeakPtr(),
......@@ -63,7 +68,7 @@ mojom::QueryParameters::QuerySource DriveFsSearch::PerformSearch(
}
void DriveFsSearch::OnSearchDriveFs(
drivefs::mojom::SearchQueryPtr search,
mojo::Remote<drivefs::mojom::SearchQuery> search,
drivefs::mojom::QueryParametersPtr query,
mojom::SearchQuery::GetNextPageCallback callback,
drive::FileError error,
......
......@@ -14,6 +14,7 @@
#include "base/memory/weak_ptr.h"
#include "base/time/clock.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace network {
class NetworkConnectionTracker;
......@@ -37,7 +38,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsSearch {
private:
void OnSearchDriveFs(
drivefs::mojom::SearchQueryPtr search,
mojo::Remote<drivefs::mojom::SearchQuery> search,
drivefs::mojom::QueryParametersPtr query,
mojom::SearchQuery::GetNextPageCallback callback,
drive::FileError error,
......
......@@ -4,12 +4,16 @@
#include "chromeos/components/drivefs/drivefs_search.h"
#include <utility>
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/simple_test_clock.h"
#include "base/test/task_environment.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 "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -22,7 +26,7 @@ using testing::_;
class MockDriveFs : public mojom::DriveFsInterceptorForTesting,
public mojom::SearchQuery {
public:
MockDriveFs() : search_binding_(this) {}
MockDriveFs() = default;
DriveFs* GetForwardingInterface() override {
NOTREACHED();
......@@ -30,12 +34,11 @@ class MockDriveFs : public mojom::DriveFsInterceptorForTesting,
}
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 {
if (search_binding_.is_bound())
search_binding_.Unbind();
search_receiver_.reset();
OnStartSearchQuery(*query_params);
search_binding_.Bind(std::move(query));
search_receiver_.Bind(std::move(receiver));
}
MOCK_METHOD1(OnGetNextPage,
......@@ -49,7 +52,7 @@ class MockDriveFs : public mojom::DriveFsInterceptorForTesting,
}
private:
mojo::Binding<mojom::SearchQuery> search_binding_;
mojo::Receiver<mojom::SearchQuery> search_receiver_{this};
DISALLOW_COPY_AND_ASSIGN(MockDriveFs);
};
......
......@@ -20,9 +20,12 @@
#include "base/task/post_task.h"
#include "base/threading/thread_restrictions.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/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 {
......@@ -70,15 +73,16 @@ base::FilePath MaybeMountDriveFs(
} // namespace
FakeDriveFsBootstrapListener::FakeDriveFsBootstrapListener(
drivefs::mojom::DriveFsBootstrapPtrInfo bootstrap)
mojo::PendingRemote<drivefs::mojom::DriveFsBootstrap> bootstrap)
: bootstrap_(std::move(bootstrap)) {}
FakeDriveFsBootstrapListener::~FakeDriveFsBootstrapListener() = default;
void FakeDriveFsBootstrapListener::SendInvitationOverPipe(base::ScopedFD) {}
mojom::DriveFsBootstrapPtr FakeDriveFsBootstrapListener::bootstrap() {
return mojo::MakeProxy(std::move(bootstrap_));
mojo::PendingRemote<mojom::DriveFsBootstrap>
FakeDriveFsBootstrapListener::bootstrap() {
return std::move(bootstrap_);
}
struct FakeDriveFs::FileMetadata {
......@@ -227,7 +231,7 @@ class FakeDriveFs::SearchQuery : public mojom::SearchQuery {
};
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.ReferencesParent());
}
......@@ -248,13 +252,13 @@ void FakeDriveFs::RegisterMountingForAccountId(
std::unique_ptr<drivefs::DriveFsBootstrapListener>
FakeDriveFs::CreateMojoListener() {
drivefs::mojom::DriveFsBootstrapPtrInfo bootstrap;
if (bootstrap_binding_.is_bound())
bootstrap_binding_.Unbind();
bootstrap_binding_.Bind(mojo::MakeRequest(&bootstrap));
pending_delegate_request_ = mojo::MakeRequest(&delegate_);
delegate_.reset();
pending_delegate_receiver_ = delegate_.BindNewPipeAndPassReceiver();
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,
......@@ -278,18 +282,17 @@ void FakeDriveFs::SetMetadata(const base::FilePath& path,
}
}
void FakeDriveFs::Init(drivefs::mojom::DriveFsConfigurationPtr config,
drivefs::mojom::DriveFsRequest drive_fs_request,
drivefs::mojom::DriveFsDelegatePtr delegate) {
void FakeDriveFs::Init(
drivefs::mojom::DriveFsConfigurationPtr config,
mojo::PendingReceiver<drivefs::mojom::DriveFs> receiver,
mojo::PendingRemote<drivefs::mojom::DriveFsDelegate> delegate) {
{
base::ScopedAllowBlockingForTesting allow_io;
CHECK(base::CreateDirectory(mount_path_.Append(".Trash")));
}
mojo::FuseInterface(std::move(pending_delegate_request_),
delegate.PassInterface());
if (binding_.is_bound())
binding_.Unbind();
binding_.Bind(std::move(drive_fs_request));
mojo::FusePipes(std::move(pending_delegate_receiver_), std::move(delegate));
receiver_.reset();
receiver_.Bind(std::move(receiver));
}
void FakeDriveFs::GetMetadata(const base::FilePath& path,
......@@ -401,11 +404,11 @@ void FakeDriveFs::CopyFile(const base::FilePath& source,
}
void FakeDriveFs::StartSearchQuery(
drivefs::mojom::SearchQueryRequest query,
mojo::PendingReceiver<drivefs::mojom::SearchQuery> receiver,
drivefs::mojom::QueryParametersPtr query_params) {
auto search_query = std::make_unique<SearchQuery>(weak_factory_.GetWeakPtr(),
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() {}
......
......@@ -16,21 +16,24 @@
#include "chromeos/components/drivefs/drivefs_bootstrap.h"
#include "chromeos/components/drivefs/drivefs_host.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 {
class FakeDriveFsBootstrapListener : public DriveFsBootstrapListener {
public:
explicit FakeDriveFsBootstrapListener(
drivefs::mojom::DriveFsBootstrapPtrInfo bootstrap);
mojo::PendingRemote<drivefs::mojom::DriveFsBootstrap> bootstrap);
~FakeDriveFsBootstrapListener() override;
private:
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);
};
......@@ -61,9 +64,10 @@ class FakeDriveFs : public drivefs::mojom::DriveFs,
class SearchQuery;
// drivefs::mojom::DriveFsBootstrap:
void Init(drivefs::mojom::DriveFsConfigurationPtr config,
drivefs::mojom::DriveFsRequest drive_fs_request,
drivefs::mojom::DriveFsDelegatePtr delegate) override;
void Init(
drivefs::mojom::DriveFsConfigurationPtr config,
mojo::PendingReceiver<drivefs::mojom::DriveFs> receiver,
mojo::PendingRemote<drivefs::mojom::DriveFsDelegate> delegate) override;
// drivefs::mojom::DriveFs:
void GetMetadata(const base::FilePath& path,
......@@ -86,7 +90,7 @@ class FakeDriveFs : public drivefs::mojom::DriveFs,
CopyFileCallback callback) override;
void StartSearchQuery(
drivefs::mojom::SearchQueryRequest query,
mojo::PendingReceiver<drivefs::mojom::SearchQuery> receiver,
drivefs::mojom::QueryParametersPtr query_params) override;
void FetchAllChangeLogs() override;
......@@ -98,10 +102,11 @@ class FakeDriveFs : public drivefs::mojom::DriveFs,
std::map<base::FilePath, FileMetadata> metadata_;
mojo::Binding<drivefs::mojom::DriveFs> binding_;
drivefs::mojom::DriveFsDelegatePtr delegate_;
mojo::Binding<drivefs::mojom::DriveFsBootstrap> bootstrap_binding_;
drivefs::mojom::DriveFsDelegateRequest pending_delegate_request_;
mojo::Receiver<drivefs::mojom::DriveFs> receiver_{this};
mojo::Remote<drivefs::mojom::DriveFsDelegate> delegate_;
mojo::Receiver<drivefs::mojom::DriveFsBootstrap> bootstrap_receiver_{this};
mojo::PendingReceiver<drivefs::mojom::DriveFsDelegate>
pending_delegate_receiver_;
base::WeakPtrFactory<FakeDriveFs> weak_factory_{this};
......
......@@ -14,8 +14,8 @@ import "mojo/public/mojom/base/time.mojom";
interface DriveFsBootstrap {
// Initialize a DriveFS instance with its configuration and mojo connections
// to the browser.
Init(DriveFsConfiguration config, DriveFs& drive_fs,
DriveFsDelegate delegate);
Init(DriveFsConfiguration config, pending_receiver<DriveFs> drive_fs,
pending_remote<DriveFsDelegate> delegate);
};
// Implemented by DriveFS, used from Chrome.
......@@ -49,7 +49,8 @@ interface DriveFs {
(FileError error);
// 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.
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