When unmounting, unmount all mounts thaty are mounted from unmounting disk.

TEST=manual (mount a zip from a usb device, unmount the usb device..
             the zip should also be unmounted)
BUG=126972


Review URL: https://chromiumcodereview.appspot.com/10919234

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157017 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chromeos/disks/disk_mount_manager.cc b/chromeos/disks/disk_mount_manager.cc
index 9850fb3..65bcda5 100644
--- a/chromeos/disks/disk_mount_manager.cc
+++ b/chromeos/disks/disk_mount_manager.cc
@@ -82,6 +82,7 @@
 
   // DiskMountManager override.
   virtual void UnmountPath(const std::string& mount_path) OVERRIDE {
+    UnmountChildMounts(mount_path);
     cros_disks_client_->Unmount(mount_path,
                                 base::Bind(&DiskMountManagerImpl::OnUnmountPath,
                                            weak_ptr_factory_.GetWeakPtr()),
@@ -228,6 +229,24 @@
     }
   };
 
+  // Unmounts all mount points whose source path is transitively parented by
+  // |mount_path|.
+  void UnmountChildMounts(const std::string& mount_path_in) {
+    std::string mount_path = mount_path_in;
+    // Let's make sure mount path has trailing slash.
+    if (mount_path[mount_path.length() - 1] != '/')
+      mount_path += '/';
+
+    for (MountPointMap::iterator it = mount_points_.begin();
+         it != mount_points_.end();
+         ++it) {
+      if (StartsWithASCII(it->second.source_path, mount_path,
+                          true /*case sensitive*/)) {
+        UnmountPath(it->second.mount_path);
+      }
+    }
+  }
+
   // Callback for UnmountDeviceRecursive.
   void OnUnmountDeviceRecursive(UnmountDeviceRecursiveCallbackData* cb_data,
                                 bool success,