Commit 0f9907ae authored by Austin Tankiang's avatar Austin Tankiang Committed by Chromium LUCI CQ

Add DriveFsDelegate function DisplayConfirmDialog

This will be plumbed to Files App UI where a dialog can be displayed.

Bug: 1166058
Change-Id: I4f271a0b4eb3002e430f5dbd127ebb8a8e844503
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626813Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843826}
parent 227509c0
......@@ -17,6 +17,7 @@
#include "chromeos/constants/chromeos_features.h"
#include "components/drive/drive_notification_manager.h"
#include "components/drive/drive_notification_observer.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "mojo/public/cpp/platform/platform_channel_endpoint.h"
#include "mojo/public/cpp/system/invitation.h"
#include "services/network/public/cpp/network_connection_tracker.h"
......@@ -163,6 +164,17 @@ class DriveFsHost::MountState : public DriveFsSession,
std::move(params), std::move(port), std::move(host)));
}
void DisplayConfirmDialog(mojom::DialogReasonPtr error,
DisplayConfirmDialogCallback callback) override {
if (!IsKnownEnumValue(error->type) || !host_->dialog_handler_) {
std::move(callback).Run(mojom::DialogResult::kNotDisplayed);
return;
}
host_->dialog_handler_.Run(
*error, mojo::WrapCallbackWithDefaultInvokeIfNotRun(
std::move(callback), mojom::DialogResult::kNotDisplayed));
}
// DriveNotificationObserver overrides:
void OnNotificationReceived(
const std::map<std::string, int64_t>& invalidations) override {
......
......@@ -49,6 +49,9 @@ class DriveFsHostObserver;
class COMPONENT_EXPORT(DRIVEFS) DriveFsHost {
public:
using MountObserver = DriveFsSession::MountObserver;
using DialogHandler = base::RepeatingCallback<void(
const mojom::DialogReason&,
base::OnceCallback<void(mojom::DialogResult)>)>;
class Delegate : public DriveFsAuth::Delegate {
public:
......@@ -105,6 +108,10 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsHost {
mojom::QueryParametersPtr query,
mojom::SearchQuery::GetNextPageCallback callback);
void set_dialog_handler(DialogHandler dialog_handler) {
dialog_handler_ = dialog_handler;
}
private:
class AccountTokenDelegate;
class MountState;
......@@ -129,6 +136,7 @@ class COMPONENT_EXPORT(DRIVEFS) DriveFsHost {
std::unique_ptr<MountState> mount_state_;
base::ObserverList<DriveFsHostObserver>::Unchecked observers_;
DialogHandler dialog_handler_;
DISALLOW_COPY_AND_ASSIGN(DriveFsHost);
};
......
......@@ -560,6 +560,64 @@ TEST_F(DriveFsHostTest, OnError_IgnoreUnknownErrorTypes) {
delegate_.FlushForTesting();
}
TEST_F(DriveFsHostTest, DisplayConfirmDialog_ForwardToHandler) {
ASSERT_NO_FATAL_FAILURE(DoMount());
auto reason = mojom::DialogReason::New(
mojom::DialogReason::Type::kEnableDocsOffline, base::FilePath());
mojom::DialogReasonPtr observed_reason;
host_->set_dialog_handler(base::BindLambdaForTesting(
[&](const mojom::DialogReason& reason,
base::OnceCallback<void(mojom::DialogResult)> callback) {
observed_reason = reason.Clone();
std::move(callback).Run(mojom::DialogResult::kAccept);
}));
bool called = false;
delegate_->DisplayConfirmDialog(
reason.Clone(),
base::BindLambdaForTesting([&](mojom::DialogResult result) {
EXPECT_EQ(mojom::DialogResult::kAccept, result);
called = true;
}));
delegate_.FlushForTesting();
EXPECT_EQ(reason, observed_reason);
EXPECT_TRUE(called);
}
TEST_F(DriveFsHostTest, DisplayConfirmDialogImpl_IgnoreIfNoHandler) {
ASSERT_NO_FATAL_FAILURE(DoMount());
bool called = false;
delegate_->DisplayConfirmDialog(
mojom::DialogReason::New(mojom::DialogReason::Type::kEnableDocsOffline,
base::FilePath()),
base::BindLambdaForTesting([&](mojom::DialogResult result) {
EXPECT_EQ(mojom::DialogResult::kNotDisplayed, result);
called = true;
}));
delegate_.FlushForTesting();
EXPECT_TRUE(called);
}
TEST_F(DriveFsHostTest, DisplayConfirmDialogImpl_IgnoreUnknownReasonTypes) {
ASSERT_NO_FATAL_FAILURE(DoMount());
host_->set_dialog_handler(base::BindRepeating(
[](const mojom::DialogReason&,
base::OnceCallback<void(mojom::DialogResult)>) { NOTREACHED(); }));
bool called = false;
delegate_->DisplayConfirmDialog(
mojom::DialogReason::New(
static_cast<mojom::DialogReason::Type>(
static_cast<std::underlying_type_t<mojom::DialogReason::Type>>(
mojom::DialogReason::Type::kMaxValue) +
1),
base::FilePath()),
base::BindLambdaForTesting([&](mojom::DialogResult result) {
EXPECT_EQ(mojom::DialogResult::kNotDisplayed, result);
called = true;
}));
delegate_.FlushForTesting();
EXPECT_TRUE(called);
}
TEST_F(DriveFsHostTest, TeamDriveTracking) {
ASSERT_NO_FATAL_FAILURE(DoMount());
......
......@@ -268,6 +268,8 @@ class DriveFsSessionForTest : public DriveFsSession {
mojo::PendingReceiver<mojom::NativeMessagingPort> port,
mojo::PendingRemote<mojom::NativeMessagingHost> host,
ConnectToExtensionCallback callback) override {}
void DisplayConfirmDialog(mojom::DialogReasonPtr error,
DisplayConfirmDialogCallback callback) override {}
DISALLOW_COPY_AND_ASSIGN(DriveFsSessionForTest);
};
......
......@@ -158,6 +158,9 @@ interface DriveFsDelegate {
pending_receiver<NativeMessagingPort> port,
pending_remote<NativeMessagingHost> host) => (
ExtensionConnectionStatus error);
// Invoked when Drive wants to display a confirmation dialog.
DisplayConfirmDialog(DialogReason reason) => (DialogResult result);
};
// Next MinVersion: 6
......@@ -194,6 +197,17 @@ enum AccessTokenStatus {
kAuthError,
};
enum DialogResult {
// The dialog was not displayed to the user.
kNotDisplayed,
// The user accepted the action proposed by the dialog.
kAccept,
// The user rejected the action proposed by the dialog.
kReject,
// The user closed the dialog without selecting an option.
kDismiss,
};
enum FileError {
// These match the values of drive::FileError in
// //components/drive/file_errors.h
......@@ -231,6 +245,17 @@ struct DriveError {
mojo_base.mojom.FilePath path;
};
struct DialogReason {
[Extensible] enum Type {
kEnableDocsOffline,
};
Type type;
// The path to the file associated with this dialog, if there was one.
mojo_base.mojom.FilePath path;
};
// Next MinVersion: 3
struct FileMetadata {
[Extensible] enum Type {
......
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