Commit b8ede7da authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Dispatch out-of-quota errors from DriveFS to DriveFsHostObservers.

Bug: 844298
Change-Id: I318dbeab7f0badd6d2cf06d22ddf197d590662af
Reviewed-on: https://chromium-review.googlesource.com/1196286Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587861}
parent 9369e026
......@@ -221,6 +221,12 @@ class DriveFsHost::MountState : public mojom::DriveFsDelegate,
}
}
void OnError(mojom::DriveErrorPtr error) override {
for (auto& observer : host_->observers_) {
observer.OnError(*error);
}
}
void OnConnectionError() {
DCHECK_CALLED_ON_VALID_SEQUENCE(host_->sequence_checker_);
if (!drivefs_has_terminated_) {
......
......@@ -9,6 +9,7 @@
namespace drivefs {
namespace mojom {
class DriveError;
class FileChange;
class SyncingStatus;
} // namespace mojom
......@@ -18,6 +19,7 @@ class DriveFsHostObserver {
virtual void OnUnmounted() {}
virtual void OnSyncingStatusUpdate(const mojom::SyncingStatus& status) {}
virtual void OnFilesChanged(const std::vector<mojom::FileChange>& changes) {}
virtual void OnError(const mojom::DriveError& error) {}
protected:
~DriveFsHostObserver() = default;
......
......@@ -233,6 +233,9 @@ class MockDriveFsHostObserver : public DriveFsHostObserver {
public:
MOCK_METHOD0(OnUnmounted, void());
MOCK_METHOD1(OnSyncingStatusUpdate, void(const mojom::SyncingStatus& status));
MOCK_METHOD1(OnFilesChanged,
void(const std::vector<mojom::FileChange>& changes));
MOCK_METHOD1(OnError, void(const mojom::DriveError& error));
};
ACTION_P(RunQuitClosure, quit) {
......@@ -775,8 +778,7 @@ ACTION_P(CloneStruct, output) {
*output = arg0.Clone();
}
TEST_F(DriveFsHostTest,
GetAccessToken_OnSyncingStatusUpdate_ForwardToObservers) {
TEST_F(DriveFsHostTest, OnSyncingStatusUpdate_ForwardToObservers) {
ASSERT_NO_FATAL_FAILURE(DoMount());
MockDriveFsHostObserver observer;
ScopedObserver<DriveFsHost, DriveFsHostObserver> observer_scoper(&observer);
......@@ -795,5 +797,49 @@ TEST_F(DriveFsHostTest,
EXPECT_EQ(status, observed_status);
}
ACTION_P(CloneVectorOfStructs, output) {
for (auto& s : arg0) {
output->emplace_back(s.Clone());
}
}
TEST_F(DriveFsHostTest, OnFilesChanged_ForwardToObservers) {
ASSERT_NO_FATAL_FAILURE(DoMount());
MockDriveFsHostObserver observer;
ScopedObserver<DriveFsHost, DriveFsHostObserver> observer_scoper(&observer);
observer_scoper.Add(host_.get());
std::vector<mojom::FileChangePtr> changes;
changes.emplace_back(base::in_place, base::FilePath("/create"),
mojom::FileChange::Type::kCreate);
changes.emplace_back(base::in_place, base::FilePath("/delete"),
mojom::FileChange::Type::kDelete);
changes.emplace_back(base::in_place, base::FilePath("/modify"),
mojom::FileChange::Type::kModify);
std::vector<mojom::FileChangePtr> observed_changes;
EXPECT_CALL(observer, OnFilesChanged(_))
.WillOnce(CloneVectorOfStructs(&observed_changes));
delegate_ptr_->OnFilesChanged(mojo::Clone(changes));
delegate_ptr_.FlushForTesting();
testing::Mock::VerifyAndClear(&observer);
EXPECT_EQ(changes, observed_changes);
}
TEST_F(DriveFsHostTest, OnError_ForwardToObservers) {
ASSERT_NO_FATAL_FAILURE(DoMount());
MockDriveFsHostObserver observer;
ScopedObserver<DriveFsHost, DriveFsHostObserver> observer_scoper(&observer);
observer_scoper.Add(host_.get());
auto error = mojom::DriveError::New(
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();
testing::Mock::VerifyAndClear(&observer);
EXPECT_EQ(error, observed_error);
}
} // namespace
} // namespace drivefs
......@@ -61,6 +61,9 @@ interface DriveFsDelegate {
// Invoked when server-side file changes are received.
OnFilesChanged(array<FileChange> changes);
// Invoked when a supported error occurs.
OnError(DriveError error);
};
struct DriveFsConfiguration {
......@@ -103,6 +106,18 @@ enum FileError {
kServiceUnavailable = -18,
};
// Errors received from DriveFS to be forwarded to the file manager UI.
struct DriveError {
[Extensible] enum Type {
kCantUploadStorageFull,
};
Type type;
// The path to the file where an error was encountered, if there was one.
mojo_base.mojom.FilePath path;
};
struct FileMetadata {
enum Type {
// A regular file.
......
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