Small refactoring in DiskMountManager (event reporting; format method).

* Rename DiskMountManager::Observer methods to On____Event format.

* Break up DiskMountManagerEventType enum.

* Add separate observer method for formatting events.

* Pass formatting event success using bool instead of adding '!' in front of the
path (but only in events from DiskMountManager; will remove it from
CrosDisksClient events in another patch).

* Add unit tests for formatting handling in DiskMountManager.
(TODO: add more tests)

TBR:[email protected]
(for mechanical changes in chrome/browser/system_monitor)

BUG=157587, 126815
TEST=manual: formatting works (and Formatting pending notification goes away)
     chromeos_unittests::DiskMountManagerTest.*

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167799 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chromeos/disks/disk_mount_manager.h b/chromeos/disks/disk_mount_manager.h
index 0fe1a1a..895c607 100644
--- a/chromeos/disks/disk_mount_manager.h
+++ b/chromeos/disks/disk_mount_manager.h
@@ -13,20 +13,6 @@
 namespace chromeos {
 namespace disks {
 
-// Types of events DiskMountManager sends to its observers.
-enum DiskMountManagerEventType {
-  MOUNT_DISK_ADDED,
-  MOUNT_DISK_REMOVED,
-  MOUNT_DISK_CHANGED,
-  MOUNT_DISK_MOUNTED,
-  MOUNT_DISK_UNMOUNTED,
-  MOUNT_DEVICE_ADDED,
-  MOUNT_DEVICE_REMOVED,
-  MOUNT_DEVICE_SCANNED,
-  MOUNT_FORMATTING_STARTED,
-  MOUNT_FORMATTING_FINISHED,
-};
-
 // Condition of mounted filesystem.
 enum MountCondition {
   MOUNT_CONDITION_NONE,
@@ -38,12 +24,29 @@
 // Other classes can add themselves as observers.
 class CHROMEOS_EXPORT DiskMountManager {
  public:
-  // Event type given to observers' MountCompleted method.
+  // Event types passed to the observers.
+  enum DiskEvent {
+    DISK_ADDED,
+    DISK_REMOVED,
+    DISK_CHANGED,
+  };
+
+  enum DeviceEvent {
+    DEVICE_ADDED,
+    DEVICE_REMOVED,
+    DEVICE_SCANNED,
+  };
+
   enum MountEvent {
     MOUNTING,
     UNMOUNTING,
   };
 
+  enum FormatEvent {
+    FORMAT_STARTED,
+    FORMAT_COMPLETED
+  };
+
   // Used to house an instance of each found mount device.
   class Disk {
    public:
@@ -196,16 +199,19 @@
    public:
     virtual ~Observer() {}
 
-    // A function called when disk mount status is changed.
-    virtual void DiskChanged(DiskMountManagerEventType event,
-                             const Disk* disk) = 0;
-    // A function called when device status is changed.
-    virtual void DeviceChanged(DiskMountManagerEventType event,
+    // Called when disk mount status is changed.
+    virtual void OnDiskEvent(DiskEvent event, const Disk* disk) = 0;
+    // Called when device status is changed.
+    virtual void OnDeviceEvent(DeviceEvent event,
                                const std::string& device_path) = 0;
-    // A function called after mount is completed.
-    virtual void MountCompleted(MountEvent event_type,
-                                MountError error_code,
-                                const MountPointInfo& mount_info) = 0;
+    // Called after a mount point has been mounted or unmounted.
+    virtual void OnMountEvent(MountEvent event,
+                              MountError error_code,
+                              const MountPointInfo& mount_info) = 0;
+    // Called on format process events.
+    virtual void OnFormatEvent(FormatEvent event,
+                               FormatError error_code,
+                               const std::string& device_path) = 0;
   };
 
   virtual ~DiskMountManager() {}
@@ -240,10 +246,6 @@
   virtual void UnmountPath(const std::string& mount_path,
                            UnmountOptions options) = 0;
 
-  // Formats device given its file path.
-  // Example: file_path: /dev/sdb1
-  virtual void FormatUnmountedDevice(const std::string& file_path) = 0;
-
   // Formats Device given its mount path. Unmounts the device.
   // Example: mount_path: /media/VOLUME_LABEL
   virtual void FormatMountedDevice(const std::string& mount_path) = 0;
@@ -254,6 +256,11 @@
       UnmountDeviceRecursiveCallbackType callback,
       void* user_data) = 0;
 
+  // Used in tests to initialize the manager's disk and mount point sets.
+  // Default implementation does noting. It just fails.
+  virtual bool AddDiskForTest(Disk* disk);
+  virtual bool AddMountPointForTest(const MountPointInfo& mount_point);
+
   // Returns corresponding string to |type| like "device" or "file".
   static std::string MountTypeToString(MountType type);