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> |
11 | 11 |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.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 { | 19 typedef enum MountLibraryEventType { |
20 MOUNT_DISK_ADDED, | 20 MOUNT_DISK_ADDED, |
21 MOUNT_DISK_REMOVED, | 21 MOUNT_DISK_REMOVED, |
22 MOUNT_DISK_CHANGED, | 22 MOUNT_DISK_CHANGED, |
23 MOUNT_DISK_MOUNTED, | 23 MOUNT_DISK_MOUNTED, |
24 MOUNT_DISK_UNMOUNTED, | 24 MOUNT_DISK_UNMOUNTED, |
25 MOUNT_DEVICE_ADDED, | 25 MOUNT_DEVICE_ADDED, |
26 MOUNT_DEVICE_REMOVED, | 26 MOUNT_DEVICE_REMOVED, |
27 MOUNT_DEVICE_SCANNED, | 27 MOUNT_DEVICE_SCANNED |
28 MOUNT_FORMATTING_STARTED, | |
29 MOUNT_FORMATTING_FINISHED | |
30 } MountLibraryEventType; | 28 } MountLibraryEventType; |
31 | 29 |
32 // This class handles the interaction with the ChromeOS mount library APIs. | 30 // This class handles the interaction with the ChromeOS mount library APIs. |
33 // 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 |
34 // library class like this: chromeos::CrosLibrary::Get()->GetMountLibrary() | 32 // library class like this: chromeos::CrosLibrary::Get()->GetMountLibrary() |
35 class MountLibrary { | 33 class MountLibrary { |
36 public: | 34 public: |
37 enum MountEvent { | 35 enum MountEvent { |
38 MOUNTING, | 36 MOUNTING, |
39 UNMOUNTING | 37 UNMOUNTING |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 std::string drive_label_; | 93 std::string drive_label_; |
96 std::string parent_path_; | 94 std::string parent_path_; |
97 DeviceType device_type_; | 95 DeviceType device_type_; |
98 uint64 total_size_; | 96 uint64 total_size_; |
99 bool is_parent_; | 97 bool is_parent_; |
100 bool is_read_only_; | 98 bool is_read_only_; |
101 bool has_media_; | 99 bool has_media_; |
102 bool on_boot_device_; | 100 bool on_boot_device_; |
103 }; | 101 }; |
104 typedef std::map<std::string, Disk*> DiskMap; | 102 typedef std::map<std::string, Disk*> DiskMap; |
105 typedef std::map<std::string, std::string> PathMap; | |
106 | 103 |
107 // MountPointInfo: {mount_path, mount_type}. | 104 // MountPointInfo: {mount_path, mount_type}. |
108 struct MountPointInfo { | 105 struct MountPointInfo { |
109 std::string source_path; | 106 std::string source_path; |
110 std::string mount_path; | 107 std::string mount_path; |
111 MountType mount_type; | 108 MountType mount_type; |
112 | 109 |
113 MountPointInfo(const char* source, const char* mount, const MountType type) | 110 MountPointInfo(const char* source, const char* mount, const MountType type) |
114 : source_path(source ? source : ""), | 111 : source_path(source ? source : ""), |
115 mount_path(mount ? mount : ""), | 112 mount_path(mount ? mount : ""), |
(...skipping 25 matching lines...) Expand all Loading... |
141 virtual const DiskMap& disks() const = 0; | 138 virtual const DiskMap& disks() const = 0; |
142 virtual const MountPointMap& mount_points() const = 0; | 139 virtual const MountPointMap& mount_points() const = 0; |
143 | 140 |
144 virtual void RequestMountInfoRefresh() = 0; | 141 virtual void RequestMountInfoRefresh() = 0; |
145 virtual void MountPath(const char* source_path, | 142 virtual void MountPath(const char* source_path, |
146 MountType type, | 143 MountType type, |
147 const MountPathOptions& options) = 0; | 144 const MountPathOptions& options) = 0; |
148 // |path| may be source od mount path. | 145 // |path| may be source od mount path. |
149 virtual void UnmountPath(const char* path) = 0; | 146 virtual void UnmountPath(const char* path) = 0; |
150 | 147 |
151 // Formats device given its file path. | |
152 // Example: file_path: /dev/sdb1 | |
153 virtual void FormatUnmountedDevice(const char* file_path) = 0; | |
154 | |
155 // Formats Device given its mount path. Unmount's the device | |
156 // Example: mount_path: /media/VOLUME_LABEL | |
157 virtual void FormatMountedDevice(const char* mount_path) = 0; | |
158 | |
159 // Unmounts device_poath and all of its known children. | 148 // Unmounts device_poath and all of its known children. |
160 virtual void UnmountDeviceRecursive(const char* device_path, | 149 virtual void UnmountDeviceRecursive(const char* device_path, |
161 UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0; | 150 UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0; |
162 | 151 |
163 // Helper functions for parameter conversions. | 152 // Helper functions for parameter conversions. |
164 static std::string MountTypeToString(MountType type); | 153 static std::string MountTypeToString(MountType type); |
165 static MountType MountTypeFromString(const std::string& type_str); | 154 static MountType MountTypeFromString(const std::string& type_str); |
166 | 155 |
167 // Factory function, creates a new instance and returns ownership. | 156 // Factory function, creates a new instance and returns ownership. |
168 // For normal usage, access the singleton via CrosLibrary::Get(). | 157 // For normal usage, access the singleton via CrosLibrary::Get(). |
169 static MountLibrary* GetImpl(bool stub); | 158 static MountLibrary* GetImpl(bool stub); |
170 }; | 159 }; |
171 | 160 |
172 } // namespace chromeos | 161 } // namespace chromeos |
173 | 162 |
174 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ | 163 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
OLD | NEW |