[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 268b02f | 2010-02-04 21:07:15 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
| 6 | #define CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 8 | |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "base/observer_list.h" |
| 13 | #include "base/singleton.h" |
| 14 | #include "base/time.h" |
[email protected] | 583dca28 | 2010-12-17 01:12:05 | [diff] [blame] | 15 | #include "third_party/cros/chromeos_mount.h" |
[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 16 | |
| 17 | namespace chromeos { |
| 18 | |
| 19 | // 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 |
[email protected] | 819a4386 | 2010-08-12 10:09:21 | [diff] [blame] | 21 | // library class like this: chromeos::CrosLibrary::Get()->GetMountLibrary() |
[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 22 | class MountLibrary { |
| 23 | public: |
| 24 | // Used to house an instance of each found mount device. |
| 25 | struct Disk { |
| 26 | Disk() {} |
[email protected] | 75a3230a | 2010-01-11 23:16:58 | [diff] [blame] | 27 | Disk(const std::string& devicepath, |
| 28 | const std::string& mountpath, |
[email protected] | b52e52a | 2010-04-02 22:47:45 | [diff] [blame] | 29 | const std::string& systempath, |
| 30 | bool isparent, |
| 31 | bool hasmedia) |
[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 32 | : device_path(devicepath), |
[email protected] | 75a3230a | 2010-01-11 23:16:58 | [diff] [blame] | 33 | mount_path(mountpath), |
[email protected] | b52e52a | 2010-04-02 22:47:45 | [diff] [blame] | 34 | system_path(systempath), |
| 35 | is_parent(isparent), |
| 36 | has_media(hasmedia) {} |
[email protected] | 75a3230a | 2010-01-11 23:16:58 | [diff] [blame] | 37 | // The path of the device, used by devicekit-disks. |
[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 38 | std::string device_path; |
[email protected] | 75a3230a | 2010-01-11 23:16:58 | [diff] [blame] | 39 | // The path to the mount point of this device. Will be empty if not mounted. |
[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 40 | std::string mount_path; |
[email protected] | 75a3230a | 2010-01-11 23:16:58 | [diff] [blame] | 41 | // The path of the device according to the udev system. |
| 42 | std::string system_path; |
[email protected] | b52e52a | 2010-04-02 22:47:45 | [diff] [blame] | 43 | // if the device is a parent device (i.e. sdb rather than sdb1) |
| 44 | bool is_parent; |
| 45 | // if the device has media currently |
| 46 | bool has_media; |
[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 47 | }; |
| 48 | typedef std::vector<Disk> DiskVector; |
| 49 | |
| 50 | class Observer { |
| 51 | public: |
| 52 | virtual void MountChanged(MountLibrary* obj, |
| 53 | MountEventType evt, |
| 54 | const std::string& path) = 0; |
| 55 | }; |
| 56 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 57 | virtual ~MountLibrary() {} |
| 58 | virtual void AddObserver(Observer* observer) = 0; |
| 59 | virtual void RemoveObserver(Observer* observer) = 0; |
| 60 | virtual const DiskVector& disks() const = 0; |
[email protected] | b52e52a | 2010-04-02 22:47:45 | [diff] [blame] | 61 | virtual bool MountPath(const char* device_path) = 0; |
[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 62 | |
[email protected] | 819a4386 | 2010-08-12 10:09:21 | [diff] [blame] | 63 | // Factory function, creates a new instance and returns ownership. |
| 64 | // For normal usage, access the singleton via CrosLibrary::Get(). |
[email protected] | 617fd0d | 2010-08-04 20:05:17 | [diff] [blame] | 65 | static MountLibrary* GetImpl(bool stub); |
[email protected] | b4037d13 | 2009-11-11 01:10:45 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | } // namespace chromeos |
| 69 | |
[email protected] | 268b02f | 2010-02-04 21:07:15 | [diff] [blame] | 70 | #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |