Return fixed storage from StorageMonitor::GetAllAvailableStorages(). (1/2)

Fetch information about all devices from OS in the DiskMountManager.
Ignore virtual block devices.

Split disk changes callback into separate callbacks for auto mountable
and fixed storage disks, so clients that are only interested
in auto mountable devices do not need to do additional filtering.


Bug: 420633
Change-Id: I3380c1a0ff49d7167760633cc3ed30d151170a08
Reviewed-on: https://chromium-review.googlesource.com/756273
Commit-Queue: Aga Wronska <[email protected]>
Reviewed-by: Steven Bennetts <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Reviewed-by: Yusuke Sato <[email protected]>
Reviewed-by: Toni Barzic <[email protected]>
Cr-Commit-Position: refs/heads/master@{#521019}
diff --git a/chromeos/disks/disk_mount_manager.cc b/chromeos/disks/disk_mount_manager.cc
index 5b9853c..0f4856f 100644
--- a/chromeos/disks/disk_mount_manager.cc
+++ b/chromeos/disks/disk_mount_manager.cc
@@ -268,7 +268,7 @@
     refresh_callbacks_.push_back(callback);
     if (refresh_callbacks_.size() == 1) {
       // If there's no in-flight refreshing task, start it.
-      cros_disks_client_->EnumerateAutoMountableDevices(
+      cros_disks_client_->EnumerateDevices(
           base::Bind(&DiskMountManagerImpl::RefreshAfterEnumerateDevices,
                      weak_ptr_factory_.GetWeakPtr()),
           base::Bind(&DiskMountManagerImpl::RefreshCompleted,
@@ -626,10 +626,7 @@
 
   // Callback for GetDeviceProperties.
   void OnGetDeviceProperties(const DiskInfo& disk_info) {
-    // TODO(zelidrag): Find a better way to filter these out before we
-    // fetch the properties:
-    // Ignore disks coming from the device we booted the system from.
-    if (disk_info.on_boot_device())
+    if (disk_info.is_virtual())
       return;
 
     LOG(WARNING) << "Found disk " << disk_info.device_path();
@@ -650,6 +647,8 @@
     auto access_mode = access_modes_.find(disk_info.device_path());
     bool write_disabled_by_policy = access_mode != access_modes_.end()
         && access_mode->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY;
+    // TODO(agawronska): Add constructor for Disk from DiskInfo. Introduce Disk
+    // builder class for tests.
     Disk* disk = new Disk(
         disk_info.device_path(), disk_info.mount_path(),
         write_disabled_by_policy, disk_info.system_path(),
@@ -663,7 +662,7 @@
         disk_info.is_hidden(), disk_info.file_system_type(), base_mount_path);
     disks_.insert(
         std::make_pair(disk_info.device_path(), base::WrapUnique(disk)));
-    NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk);
+    NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, *disk);
   }
 
   // Part of EnsureMountInfoRefreshed(). Called after the list of devices are
@@ -743,7 +742,7 @@
         DiskMountManager::DiskMap::iterator iter = disks_.find(device_path);
         if (iter != disks_.end()) {
           Disk* disk = iter->second.get();
-          NotifyDiskStatusUpdate(DISK_REMOVED, disk);
+          NotifyDiskStatusUpdate(DISK_REMOVED, *disk);
           disks_.erase(iter);
         }
         break;
@@ -769,10 +768,11 @@
   }
 
   // Notifies all observers about disk status update.
-  void NotifyDiskStatusUpdate(DiskEvent event,
-                              const Disk* disk) {
-    for (auto& observer : observers_)
-      observer.OnDiskEvent(event, disk);
+  void NotifyDiskStatusUpdate(DiskEvent event, const Disk& disk) {
+    for (auto& observer : observers_) {
+      disk.IsAutoMountable() ? observer.OnAutoMountableDiskEvent(event, disk)
+                             : observer.OnBootDeviceDiskEvent(event, disk);
+    }
   }
 
   // Notifies all observers about device status update.
@@ -906,6 +906,15 @@
     base_mount_path_ = mount_path;
 }
 
+bool DiskMountManager::Disk::IsAutoMountable() const {
+  // Disks are considered auto-mountable if they are:
+  // 1. Non-virtual
+  // 2. Not on boot device
+  // Only the second condition is checked here, because Disks are created from
+  // non-virtual mount devices only.
+  return !on_boot_device_;
+};
+
 bool DiskMountManager::AddDiskForTest(std::unique_ptr<Disk> disk) {
   return false;
 }