Commit e22c74b5 authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Plumb device label through events in volume manager

Bug: 988586
Change-Id: I122c3a16cdd21d594a8fc7f4205cc8d6655aeed9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1966799Reviewed-by: default avatarAnand Mistry <amistry@chromium.org>
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726243}
parent 8bb79e58
......@@ -49,8 +49,8 @@ void DeviceEventRouter::OnDeviceAdded(const std::string& device_path) {
SetDeviceState(device_path, DEVICE_STATE_USUAL);
if (IsExternalStorageDisabled()) {
OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_DISABLED,
device_path);
OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_DISABLED, device_path,
"");
return;
}
}
......@@ -58,7 +58,8 @@ void DeviceEventRouter::OnDeviceAdded(const std::string& device_path) {
void DeviceEventRouter::OnDeviceRemoved(const std::string& device_path) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
SetDeviceState(device_path, DEVICE_STATE_USUAL);
OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_REMOVED, device_path);
OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_REMOVED, device_path,
"");
}
void DeviceEventRouter::OnDiskAdded(const chromeos::disks::Disk& disk,
......@@ -76,7 +77,7 @@ void DeviceEventRouter::OnDiskRemoved(const chromeos::disks::Disk& disk) {
if (!disk.is_read_only() && disk.is_mounted() &&
GetDeviceState(device_path) != DEVICE_HARD_UNPLUGGED_AND_REPORTED) {
OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED,
device_path);
device_path, disk.device_label());
SetDeviceState(device_path, DEVICE_HARD_UNPLUGGED_AND_REPORTED);
}
}
......@@ -95,43 +96,47 @@ void DeviceEventRouter::OnVolumeUnmounted(chromeos::MountError error_code,
}
void DeviceEventRouter::OnFormatStarted(const std::string& device_path,
const std::string& device_label,
bool success) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (success) {
OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_FORMAT_START,
device_path);
device_path, device_label);
} else {
OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_FORMAT_FAIL,
device_path);
device_path, device_label);
}
}
void DeviceEventRouter::OnFormatCompleted(const std::string& device_path,
const std::string& device_label,
bool success) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
OnDeviceEvent(success ? file_manager_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS
: file_manager_private::DEVICE_EVENT_TYPE_FORMAT_FAIL,
device_path);
device_path, device_label);
}
void DeviceEventRouter::OnRenameStarted(const std::string& device_path,
const std::string& device_label,
bool success) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
OnDeviceEvent(success ? file_manager_private::DEVICE_EVENT_TYPE_RENAME_START
: file_manager_private::DEVICE_EVENT_TYPE_RENAME_FAIL,
device_path);
device_path, device_label);
}
void DeviceEventRouter::OnRenameCompleted(const std::string& device_path,
const std::string& device_label,
bool success) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
OnDeviceEvent(success ? file_manager_private::DEVICE_EVENT_TYPE_RENAME_SUCCESS
: file_manager_private::DEVICE_EVENT_TYPE_RENAME_FAIL,
device_path);
device_path, device_label);
}
void DeviceEventRouter::SuspendImminent(
......
......@@ -50,10 +50,18 @@ class DeviceEventRouter : public VolumeManagerObserver,
const Volume& volume) override;
void OnVolumeUnmounted(chromeos::MountError error_code,
const Volume& volume) override;
void OnFormatStarted(const std::string& device_path, bool success) override;
void OnFormatCompleted(const std::string& device_path, bool success) override;
void OnRenameStarted(const std::string& device_path, bool success) override;
void OnRenameCompleted(const std::string& device_path, bool success) override;
void OnFormatStarted(const std::string& device_path,
const std::string& device_label,
bool success) override;
void OnFormatCompleted(const std::string& device_path,
const std::string& device_label,
bool success) override;
void OnRenameStarted(const std::string& device_path,
const std::string& device_label,
bool success) override;
void OnRenameCompleted(const std::string& device_path,
const std::string& device_label,
bool success) override;
// PowerManagerClient::Observer overrides.
void SuspendImminent(power_manager::SuspendImminent::Reason reason) override;
......@@ -66,7 +74,8 @@ class DeviceEventRouter : public VolumeManagerObserver,
// Handles a device event containing |type| and |device_path|.
virtual void OnDeviceEvent(
extensions::api::file_manager_private::DeviceEventType type,
const std::string& device_path) = 0;
const std::string& device_path,
const std::string& device_label) = 0;
// Returns external storage is disabled or not.
virtual bool IsExternalStorageDisabled() = 0;
......
......@@ -26,6 +26,7 @@ const char kTestDevicePath[] = "/device/test";
struct DeviceEvent {
extensions::api::file_manager_private::DeviceEventType type;
std::string device_path;
std::string device_label;
};
// DeviceEventRouter implementation for testing.
......@@ -38,10 +39,12 @@ class DeviceEventRouterImpl : public DeviceEventRouter {
// DeviceEventRouter overrides.
void OnDeviceEvent(file_manager_private::DeviceEventType type,
const std::string& device_path) override {
const std::string& device_path,
const std::string& device_label) override {
DeviceEvent event;
event.type = type;
event.device_path = device_path;
event.device_label = device_label;
events.push_back(event);
}
......
......@@ -314,12 +314,14 @@ class DeviceEventRouterImpl : public DeviceEventRouter {
// DeviceEventRouter overrides.
void OnDeviceEvent(file_manager_private::DeviceEventType type,
const std::string& device_path) override {
const std::string& device_path,
const std::string& device_label) override {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
file_manager_private::DeviceEvent event;
event.type = type;
event.device_path = device_path;
event.device_label = device_label;
BroadcastEvent(profile_,
extensions::events::FILE_MANAGER_PRIVATE_ON_DEVICE_CHANGED,
......@@ -815,24 +817,28 @@ void EventRouter::DispatchMountCompletedEvent(
}
void EventRouter::OnFormatStarted(const std::string& device_path,
const std::string& device_label,
bool success) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Do nothing.
}
void EventRouter::OnFormatCompleted(const std::string& device_path,
const std::string& device_label,
bool success) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Do nothing.
}
void EventRouter::OnRenameStarted(const std::string& device_path,
const std::string& device_label,
bool success) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Do nothing.
}
void EventRouter::OnRenameCompleted(const std::string& device_path,
const std::string& device_label,
bool success) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Do nothing.
......
......@@ -121,10 +121,18 @@ class EventRouter
const Volume& volume) override;
void OnVolumeUnmounted(chromeos::MountError error_code,
const Volume& volume) override;
void OnFormatStarted(const std::string& device_path, bool success) override;
void OnFormatCompleted(const std::string& device_path, bool success) override;
void OnRenameStarted(const std::string& device_path, bool success) override;
void OnRenameCompleted(const std::string& device_path, bool success) override;
void OnFormatStarted(const std::string& device_path,
const std::string& device_label,
bool success) override;
void OnFormatCompleted(const std::string& device_path,
const std::string& device_label,
bool success) override;
void OnRenameStarted(const std::string& device_path,
const std::string& device_label,
bool success) override;
void OnRenameCompleted(const std::string& device_path,
const std::string& device_label,
bool success) override;
// Set custom dispatch directory change event implementation for testing.
void SetDispatchDirectoryChangeEventImplForTesting(
const DispatchDirectoryChangeEventImplCallback& callback);
......
......@@ -934,7 +934,7 @@ void VolumeManager::OnFormatEvent(
switch (event) {
case chromeos::disks::DiskMountManager::FORMAT_STARTED:
for (auto& observer : observers_) {
observer.OnFormatStarted(device_path,
observer.OnFormatStarted(device_path, device_label,
error_code == chromeos::FORMAT_ERROR_NONE);
}
return;
......@@ -949,7 +949,7 @@ void VolumeManager::OnFormatEvent(
GetExternalStorageAccessMode(profile_));
for (auto& observer : observers_) {
observer.OnFormatCompleted(device_path,
observer.OnFormatCompleted(device_path, device_label,
error_code == chromeos::FORMAT_ERROR_NONE);
}
......@@ -970,7 +970,7 @@ void VolumeManager::OnRenameEvent(
switch (event) {
case chromeos::disks::DiskMountManager::RENAME_STARTED:
for (auto& observer : observers_) {
observer.OnRenameStarted(device_path,
observer.OnRenameStarted(device_path, device_label,
error_code == chromeos::RENAME_ERROR_NONE);
}
return;
......@@ -995,7 +995,8 @@ void VolumeManager::OnRenameEvent(
bool successfully_renamed = error_code == chromeos::RENAME_ERROR_NONE;
for (auto& observer : observers_)
observer.OnRenameCompleted(device_path, successfully_renamed);
observer.OnRenameCompleted(device_path, device_label,
successfully_renamed);
return;
}
......
......@@ -45,18 +45,24 @@ class VolumeManagerObserver {
const Volume& volume) {}
// Fired when formatting a device is started (or failed to start).
virtual void OnFormatStarted(const std::string& device_path, bool success) {}
virtual void OnFormatStarted(const std::string& device_path,
const std::string& device_label,
bool success) {}
// Fired when formatting a device is completed (or terminated on error).
virtual void OnFormatCompleted(const std::string& device_path, bool success) {
}
virtual void OnFormatCompleted(const std::string& device_path,
const std::string& device_label,
bool success) {}
// Fired when renaming a device is started (or failed to start).
virtual void OnRenameStarted(const std::string& device_path, bool success) {}
virtual void OnRenameStarted(const std::string& device_path,
const std::string& device_label,
bool success) {}
// Fired when renaming a device is completed (or terminated on error).
virtual void OnRenameCompleted(const std::string& device_path, bool success) {
}
virtual void OnRenameCompleted(const std::string& device_path,
const std::string& device_label,
bool success) {}
};
} // namespace file_manager
......
......@@ -69,6 +69,10 @@ class LoggingObserver : public VolumeManagerObserver {
// VOLUME_UNMOUNTED, FORMAT_STARTED and FORMAT_COMPLETED.
std::string device_path;
// Available on FORMAT_STARTED, FORMAT_COMPLETED, RENAME_STARTED and
// RENAME_COMPLETED.
std::string device_label;
// Available on DISK_ADDED.
bool mounting;
......@@ -132,36 +136,46 @@ class LoggingObserver : public VolumeManagerObserver {
events_.push_back(event);
}
void OnFormatStarted(const std::string& device_path, bool success) override {
void OnFormatStarted(const std::string& device_path,
const std::string& device_label,
bool success) override {
Event event;
event.type = Event::FORMAT_STARTED;
event.device_path = device_path;
event.device_label = device_label;
event.success = success;
events_.push_back(event);
}
void OnFormatCompleted(const std::string& device_path,
const std::string& device_label,
bool success) override {
Event event;
event.type = Event::FORMAT_COMPLETED;
event.device_path = device_path;
event.device_label = device_label;
event.success = success;
events_.push_back(event);
}
void OnRenameStarted(const std::string& device_path, bool success) override {
void OnRenameStarted(const std::string& device_path,
const std::string& device_label,
bool success) override {
Event event;
event.type = Event::RENAME_STARTED;
event.device_path = device_path;
event.device_label = device_label;
event.success = success;
events_.push_back(event);
}
void OnRenameCompleted(const std::string& device_path,
const std::string& device_label,
bool success) override {
Event event;
event.type = Event::RENAME_COMPLETED;
event.device_path = device_path;
event.device_label = device_label;
event.success = success;
events_.push_back(event);
}
......@@ -681,6 +695,7 @@ TEST_F(VolumeManagerTest, OnFormatEvent_Started) {
const LoggingObserver::Event& event = observer.events()[0];
EXPECT_EQ(LoggingObserver::Event::FORMAT_STARTED, event.type);
EXPECT_EQ("device1", event.device_path);
EXPECT_EQ("label1", event.device_label);
EXPECT_TRUE(event.success);
volume_manager()->RemoveObserver(&observer);
......@@ -698,6 +713,7 @@ TEST_F(VolumeManagerTest, OnFormatEvent_StartFailed) {
const LoggingObserver::Event& event = observer.events()[0];
EXPECT_EQ(LoggingObserver::Event::FORMAT_STARTED, event.type);
EXPECT_EQ("device1", event.device_path);
EXPECT_EQ("label1", event.device_label);
EXPECT_FALSE(event.success);
volume_manager()->RemoveObserver(&observer);
......@@ -715,6 +731,7 @@ TEST_F(VolumeManagerTest, OnFormatEvent_Completed) {
const LoggingObserver::Event& event = observer.events()[0];
EXPECT_EQ(LoggingObserver::Event::FORMAT_COMPLETED, event.type);
EXPECT_EQ("device1", event.device_path);
EXPECT_EQ("label1", event.device_label);
EXPECT_TRUE(event.success);
// When "format" is done, VolumeManager requests to mount it.
......@@ -741,6 +758,7 @@ TEST_F(VolumeManagerTest, OnFormatEvent_CompletedFailed) {
const LoggingObserver::Event& event = observer.events()[0];
EXPECT_EQ(LoggingObserver::Event::FORMAT_COMPLETED, event.type);
EXPECT_EQ("device1", event.device_path);
EXPECT_EQ("label1", event.device_label);
EXPECT_FALSE(event.success);
// When "format" is done, VolumeManager requests to mount it.
......@@ -1005,6 +1023,7 @@ TEST_F(VolumeManagerTest, OnRenameEvent_Started) {
const LoggingObserver::Event& event = observer.events()[0];
EXPECT_EQ(LoggingObserver::Event::RENAME_STARTED, event.type);
EXPECT_EQ("device1", event.device_path);
EXPECT_EQ("label1", event.device_label);
EXPECT_TRUE(event.success);
volume_manager()->RemoveObserver(&observer);
......@@ -1022,6 +1041,7 @@ TEST_F(VolumeManagerTest, OnRenameEvent_StartFailed) {
const LoggingObserver::Event& event = observer.events()[0];
EXPECT_EQ(LoggingObserver::Event::RENAME_STARTED, event.type);
EXPECT_EQ("device1", event.device_path);
EXPECT_EQ("label1", event.device_label);
EXPECT_FALSE(event.success);
volume_manager()->RemoveObserver(&observer);
......@@ -1039,6 +1059,7 @@ TEST_F(VolumeManagerTest, OnRenameEvent_Completed) {
const LoggingObserver::Event& event = observer.events()[0];
EXPECT_EQ(LoggingObserver::Event::RENAME_COMPLETED, event.type);
EXPECT_EQ("device1", event.device_path);
EXPECT_EQ("label1", event.device_label);
EXPECT_TRUE(event.success);
// When "rename" is successfully done, VolumeManager requests to mount it.
......@@ -1064,6 +1085,7 @@ TEST_F(VolumeManagerTest, OnRenameEvent_CompletedFailed) {
const LoggingObserver::Event& event = observer.events()[0];
EXPECT_EQ(LoggingObserver::Event::RENAME_COMPLETED, event.type);
EXPECT_EQ("device1", event.device_path);
EXPECT_EQ("label1", event.device_label);
EXPECT_FALSE(event.success);
EXPECT_EQ(1U, disk_mount_manager_->mount_requests().size());
......
......@@ -633,6 +633,8 @@ dictionary DeviceEvent {
DeviceEventType type;
// Device path to identify the device.
DOMString devicePath;
// Human readable label for the device.
DOMString deviceLabel;
};
// Describes an installed provider.
......
......@@ -474,7 +474,8 @@ chrome.fileManagerPrivate.DriveConnectionState;
/**
* @typedef {{
* type: !chrome.fileManagerPrivate.DeviceEventType,
* devicePath: string
* devicePath: string,
* deviceLabel: string
* }}
*/
chrome.fileManagerPrivate.DeviceEvent;
......
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