Filters out unwanted disk change events to prevent Chrome from unnecessarily opening the file browser tab.

BUG=chromium-os:15024
TEST=Manually verified that Chrome does not open the file browser tab after auto-update.

Change-Id: I830cb6b716e2a1bd5bff1b7a66b0aea9a5e8b44a
Reviewed-on: http://gerrit.chromium.org/gerrit/1472
Reviewed-by: Ben Chan <benchan@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
diff --git a/cros-disks-server-impl.cc b/cros-disks-server-impl.cc
index 64d4e84..18bfe21 100644
--- a/cros-disks-server-impl.cc
+++ b/cros-disks-server-impl.cc
@@ -104,9 +104,11 @@
       DeviceAdded(device_path);
     } else if (action == "remove") {
       DeviceRemoved(device_path);
-    } else if (action == "change") {
-      DeviceChanged(device_path);
     }
+    // To prevent Chrome from popping up the file browser tab for
+    // change events not related to disk mounting, udev change events
+    // are not retransmitted as DBus signals here, but by FilesystemMount
+    // instead.
   }
 }
 
diff --git a/disk-manager.cc b/disk-manager.cc
index a331284..6aa603b 100644
--- a/disk-manager.cc
+++ b/disk-manager.cc
@@ -112,10 +112,19 @@
   LOG(INFO) << "   Subsystem: " << udev_device_get_subsystem(dev);
   LOG(INFO) << "   Devtype: " << udev_device_get_devtype(dev);
   LOG(INFO) << "   Action: " << udev_device_get_action(dev);
-  *device_path = udev_device_get_syspath(dev);
-  *action = udev_device_get_action(dev);
+
+  bool report_changes = false;
+  // Ignore boot device or virtual device changes, which should not be
+  // sent to the Chrome browser.
+  UdevDevice udev(dev);
+  if (!udev.IsOnBootDevice() && !udev.IsVirtual()) {
+    *device_path = udev_device_get_syspath(dev);
+    *action = udev_device_get_action(dev);
+    report_changes = true;
+  }
+
   udev_device_unref(dev);
-  return true;
+  return report_changes;
 }
 
 bool DiskManager::GetDiskByDevicePath(const std::string& device_path,
diff --git a/udev-device.cc b/udev-device.cc
index 050f7d5..6f15c9f 100644
--- a/udev-device.cc
+++ b/udev-device.cc
@@ -145,6 +145,15 @@
   return false;
 }
 
+bool UdevDevice::IsVirtual() const {
+  const char *sys_path = udev_device_get_syspath(dev_);
+  if (sys_path) {
+    return StartsWithASCII(sys_path, "/sys/devices/virtual/", true);
+  }
+  // To be safe, mark it as virtual device if sys path cannot be determined.
+  return true;
+}
+
 std::vector<std::string> UdevDevice::GetMountPaths() const {
   const char *device_path = udev_device_get_devnode(dev_);
   if (device_path) {
@@ -188,16 +197,14 @@
   disk.set_is_hidden(IsPropertyTrue("UDISKS_PRESENTATION_HIDE"));
   disk.set_is_media_available(IsMediaAvailable());
   disk.set_is_on_boot_device(IsOnBootDevice());
+  disk.set_is_virtual(IsVirtual());
   disk.set_drive_model(GetProperty("ID_MODEL"));
   disk.set_uuid(GetProperty("ID_FS_UUID"));
   disk.set_label(GetProperty("ID_FS_LABEL"));
+
   const char *sys_path = udev_device_get_syspath(dev_);
-  bool is_virtual = true;
-  if (sys_path) {
+  if (sys_path)
     disk.set_native_path(sys_path);
-    is_virtual = StartsWithASCII(sys_path, "/sys/devices/virtual/", true);
-  }
-  disk.set_is_virtual(is_virtual);
 
   const char *dev_file = udev_device_get_devnode(dev_);
   if (dev_file)
diff --git a/udev-device.h b/udev-device.h
index f952f79..1993133 100644
--- a/udev-device.h
+++ b/udev-device.h
@@ -50,6 +50,9 @@
   // Checks if a device is on the boot device.
   bool IsOnBootDevice() const;
 
+  // Checks if a device is a virtual device.
+  bool IsVirtual() const;
+
   // Gets the mount paths for the device.
   std::vector<std::string> GetMountPaths() const;