OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 DeviceType device_type_; | 97 DeviceType device_type_; |
98 uint64 total_size_; | 98 uint64 total_size_; |
99 bool is_parent_; | 99 bool is_parent_; |
100 bool is_read_only_; | 100 bool is_read_only_; |
101 bool has_media_; | 101 bool has_media_; |
102 bool on_boot_device_; | 102 bool on_boot_device_; |
103 }; | 103 }; |
104 typedef std::map<std::string, Disk*> DiskMap; | 104 typedef std::map<std::string, Disk*> DiskMap; |
105 typedef std::map<std::string, std::string> PathMap; | 105 typedef std::map<std::string, std::string> PathMap; |
106 | 106 |
107 // MountPointInfo: {mount_path, mount_type}. | |
108 struct MountPointInfo { | 107 struct MountPointInfo { |
109 std::string source_path; | 108 std::string source_path; |
110 std::string mount_path; | 109 std::string mount_path; |
111 MountType mount_type; | 110 MountType mount_type; |
112 | 111 |
113 MountPointInfo(const char* source, const char* mount, const MountType type) | 112 MountPointInfo(const char* source, const char* mount, const MountType type) |
114 : source_path(source ? source : ""), | 113 : source_path(source ? source : ""), |
115 mount_path(mount ? mount : ""), | 114 mount_path(mount ? mount : ""), |
116 mount_type(type) { | 115 mount_type(type) { |
117 } | 116 } |
118 }; | 117 }; |
119 | 118 |
120 // MountPointMap key is source_path. | 119 // MountPointMap key is mount_path. |
121 typedef std::map<std::string, MountPointInfo> MountPointMap; | 120 typedef std::map<std::string, MountPointInfo> MountPointMap; |
122 | 121 |
123 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool); | 122 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool); |
124 | 123 |
125 class Observer { | 124 class Observer { |
126 public: | 125 public: |
127 virtual ~Observer() {} | 126 virtual ~Observer() {} |
128 // Async API events. | 127 // Async API events. |
129 virtual void DiskChanged(MountLibraryEventType event, | 128 virtual void DiskChanged(MountLibraryEventType event, |
130 const Disk* disk) = 0; | 129 const Disk* disk) = 0; |
131 virtual void DeviceChanged(MountLibraryEventType event, | 130 virtual void DeviceChanged(MountLibraryEventType event, |
132 const std::string& device_path ) = 0; | 131 const std::string& device_path ) = 0; |
133 virtual void MountCompleted(MountEvent event_type, | 132 virtual void MountCompleted(MountEvent event_type, |
134 MountError error_code, | 133 MountError error_code, |
135 const MountPointInfo& mount_info) = 0; | 134 const MountPointInfo& mount_info) = 0; |
136 }; | 135 }; |
137 | 136 |
138 virtual ~MountLibrary() {} | 137 virtual ~MountLibrary() {} |
139 virtual void AddObserver(Observer* observer) = 0; | 138 virtual void AddObserver(Observer* observer) = 0; |
140 virtual void RemoveObserver(Observer* observer) = 0; | 139 virtual void RemoveObserver(Observer* observer) = 0; |
141 virtual const DiskMap& disks() const = 0; | 140 virtual const DiskMap& disks() const = 0; |
142 virtual const MountPointMap& mount_points() const = 0; | 141 virtual const MountPointMap& mount_points() const = 0; |
143 | 142 |
144 virtual void RequestMountInfoRefresh() = 0; | 143 virtual void RequestMountInfoRefresh() = 0; |
145 virtual void MountPath(const char* source_path, | 144 virtual void MountPath(const char* source_path, |
146 MountType type, | 145 MountType type, |
147 const MountPathOptions& options) = 0; | 146 const MountPathOptions& options) = 0; |
148 // |path| may be source od mount path. | 147 // |path| is device's mount path. |
149 virtual void UnmountPath(const char* path) = 0; | 148 virtual void UnmountPath(const char* path) = 0; |
150 | 149 |
151 // Formats device given its file path. | 150 // Formats device given its file path. |
152 // Example: file_path: /dev/sdb1 | 151 // Example: file_path: /dev/sdb1 |
153 virtual void FormatUnmountedDevice(const char* file_path) = 0; | 152 virtual void FormatUnmountedDevice(const char* file_path) = 0; |
154 | 153 |
155 // Formats Device given its mount path. Unmount's the device | 154 // Formats Device given its mount path. Unmount's the device |
156 // Example: mount_path: /media/VOLUME_LABEL | 155 // Example: mount_path: /media/VOLUME_LABEL |
157 virtual void FormatMountedDevice(const char* mount_path) = 0; | 156 virtual void FormatMountedDevice(const char* mount_path) = 0; |
158 | 157 |
159 // Unmounts device_poath and all of its known children. | 158 // Unmounts device_poath and all of its known children. |
160 virtual void UnmountDeviceRecursive(const char* device_path, | 159 virtual void UnmountDeviceRecursive(const char* device_path, |
161 UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0; | 160 UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0; |
162 | 161 |
163 // Helper functions for parameter conversions. | 162 // Helper functions for parameter conversions. |
164 static std::string MountTypeToString(MountType type); | 163 static std::string MountTypeToString(MountType type); |
165 static MountType MountTypeFromString(const std::string& type_str); | 164 static MountType MountTypeFromString(const std::string& type_str); |
166 | 165 |
167 // Factory function, creates a new instance and returns ownership. | 166 // Factory function, creates a new instance and returns ownership. |
168 // For normal usage, access the singleton via CrosLibrary::Get(). | 167 // For normal usage, access the singleton via CrosLibrary::Get(). |
169 static MountLibrary* GetImpl(bool stub); | 168 static MountLibrary* GetImpl(bool stub); |
170 }; | 169 }; |
171 | 170 |
172 } // namespace chromeos | 171 } // namespace chromeos |
173 | 172 |
174 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ | 173 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
OLD | NEW |