Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "third_party/cros/chromeos_mount.h" | 15 #include "third_party/cros/chromeos_mount.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 typedef enum MountLibraryEventType { | |
| 20 MOUNT_DISK_ADDED, | |
| 21 MOUNT_DISK_REMOVED, | |
| 22 MOUNT_DISK_CHANGED, | |
| 23 MOUNT_DISK_MOUNTED, | |
| 24 MOUNT_DISK_UNMOUNTED, | |
| 25 MOUNT_DEVICE_ADDED, | |
| 26 MOUNT_DEVICE_REMOVED, | |
| 27 MOUNT_DEVICE_SCANNED | |
| 28 } MountLibraryEventType; | |
| 29 | |
| 19 // This class handles the interaction with the ChromeOS mount library APIs. | 30 // This class handles the interaction with the ChromeOS mount library APIs. |
| 20 // Classes can add themselves as observers. Users can get an instance of this | 31 // Classes can add themselves as observers. Users can get an instance of this |
| 21 // library class like this: chromeos::CrosLibrary::Get()->GetMountLibrary() | 32 // library class like this: chromeos::CrosLibrary::Get()->GetMountLibrary() |
| 22 class MountLibrary { | 33 class MountLibrary { |
| 23 public: | 34 public: |
| 24 // Used to house an instance of each found mount device. | 35 // Used to house an instance of each found mount device. |
| 25 struct Disk { | 36 class Disk { |
| 26 Disk() {} | 37 public: |
| 27 Disk(const std::string& devicepath, | 38 Disk(const std::string& device_path, |
| 28 const std::string& mountpath, | 39 const std::string& mount_path, |
| 29 const std::string& systempath, | 40 const std::string& system_path, |
| 30 bool isparent, | 41 bool is_parent, |
| 31 bool hasmedia) | 42 bool has_media, |
| 32 : device_path(devicepath), | 43 bool on_boot_device) |
| 33 mount_path(mountpath), | 44 : device_path_(device_path), |
| 34 system_path(systempath), | 45 mount_path_(mount_path), |
| 35 is_parent(isparent), | 46 system_path_(system_path), |
| 36 has_media(hasmedia) {} | 47 is_parent_(is_parent), |
| 48 has_media_(has_media), | |
| 49 on_boot_device_(on_boot_device) {} | |
| 37 // The path of the device, used by devicekit-disks. | 50 // The path of the device, used by devicekit-disks. |
| 38 std::string device_path; | 51 const std::string& device_path() const { return device_path_; } |
| 39 // The path to the mount point of this device. Will be empty if not mounted. | 52 // The path to the mount point of this device. Will be empty if not mounted. |
| 40 std::string mount_path; | 53 const std::string& mount_path() const { return mount_path_; } |
| 41 // The path of the device according to the udev system. | 54 // The path of the device according to the udev system. |
| 42 std::string system_path; | 55 const std::string system_path() const { return system_path_; } |
|
xiyuan
2011/03/17 00:23:32
nit: return const std::string& ?
zel
2011/03/17 01:00:30
Done.
| |
| 43 // if the device is a parent device (i.e. sdb rather than sdb1) | 56 // Is the device is a parent device (i.e. sdb rather than sdb1) |
| 44 bool is_parent; | 57 bool is_parent() const { return is_parent_; } |
| 45 // if the device has media currently | 58 // Does the device contains media. |
| 46 bool has_media; | 59 bool has_media() const { return has_media_; } |
| 60 // Is the device ont | |
| 61 bool on_boot_device() const { return on_boot_device_; } | |
| 62 | |
| 63 void set_mount_path(const char* mount_path) { mount_path_ = mount_path; } | |
| 64 void clear_mount_path() { mount_path_.clear(); } | |
| 65 private: | |
| 66 std::string device_path_; | |
| 67 std::string mount_path_; | |
| 68 std::string system_path_; | |
| 69 bool is_parent_; | |
| 70 bool has_media_; | |
| 71 bool on_boot_device_; | |
| 47 }; | 72 }; |
| 48 typedef std::vector<Disk> DiskVector; | 73 typedef std::map<std::string, Disk*> DiskMap; |
| 49 | 74 |
| 50 class Observer { | 75 class Observer { |
| 51 public: | 76 public: |
| 52 virtual ~Observer() {} | 77 virtual ~Observer() {} |
| 53 virtual void MountChanged(MountLibrary* obj, | 78 // Async API events. |
| 54 MountEventType evt, | 79 virtual void DiskChanged(MountLibraryEventType event, |
| 55 const std::string& path) = 0; | 80 const Disk* disk) = 0; |
| 81 virtual void DeviceChanged(MountLibraryEventType event, | |
| 82 const std::string& device_path ) = 0; | |
| 56 }; | 83 }; |
| 57 | 84 |
| 58 virtual ~MountLibrary() {} | 85 virtual ~MountLibrary() {} |
| 59 virtual void AddObserver(Observer* observer) = 0; | 86 virtual void AddObserver(Observer* observer) = 0; |
| 60 virtual void RemoveObserver(Observer* observer) = 0; | 87 virtual void RemoveObserver(Observer* observer) = 0; |
| 61 virtual const DiskVector& disks() const = 0; | 88 virtual const DiskMap& disks() const = 0; |
| 62 virtual bool MountPath(const char* device_path) = 0; | 89 |
| 63 virtual bool IsBootPath(const char* device_path) = 0; | 90 virtual void RequestMountInfoRefresh() = 0; |
| 91 virtual void MountPath(const char* device_path) = 0; | |
| 92 virtual void UnmountPath(const char* device_path) = 0; | |
| 64 | 93 |
| 65 // Factory function, creates a new instance and returns ownership. | 94 // Factory function, creates a new instance and returns ownership. |
| 66 // For normal usage, access the singleton via CrosLibrary::Get(). | 95 // For normal usage, access the singleton via CrosLibrary::Get(). |
| 67 static MountLibrary* GetImpl(bool stub); | 96 static MountLibrary* GetImpl(bool stub); |
| 68 }; | 97 }; |
| 69 | 98 |
| 70 } // namespace chromeos | 99 } // namespace chromeos |
| 71 | 100 |
| 72 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ | 101 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
| OLD | NEW |