blob: 21b1dacd5ffa1757c0ae935d228e48969e7c7545 [file] [log] [blame]
[email protected]b4037d132009-11-11 01:10:451// 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]268b02f2010-02-04 21:07:155#ifndef CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_
6#define CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]b4037d132009-11-11 01:10:458
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]583dca282010-12-17 01:12:0515#include "third_party/cros/chromeos_mount.h"
[email protected]b4037d132009-11-11 01:10:4516
17namespace 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]819a43862010-08-12 10:09:2121// library class like this: chromeos::CrosLibrary::Get()->GetMountLibrary()
[email protected]b4037d132009-11-11 01:10:4522class MountLibrary {
23 public:
24 // Used to house an instance of each found mount device.
25 struct Disk {
26 Disk() {}
[email protected]75a3230a2010-01-11 23:16:5827 Disk(const std::string& devicepath,
28 const std::string& mountpath,
[email protected]b52e52a2010-04-02 22:47:4529 const std::string& systempath,
30 bool isparent,
31 bool hasmedia)
[email protected]b4037d132009-11-11 01:10:4532 : device_path(devicepath),
[email protected]75a3230a2010-01-11 23:16:5833 mount_path(mountpath),
[email protected]b52e52a2010-04-02 22:47:4534 system_path(systempath),
35 is_parent(isparent),
36 has_media(hasmedia) {}
[email protected]75a3230a2010-01-11 23:16:5837 // The path of the device, used by devicekit-disks.
[email protected]b4037d132009-11-11 01:10:4538 std::string device_path;
[email protected]75a3230a2010-01-11 23:16:5839 // The path to the mount point of this device. Will be empty if not mounted.
[email protected]b4037d132009-11-11 01:10:4540 std::string mount_path;
[email protected]75a3230a2010-01-11 23:16:5841 // The path of the device according to the udev system.
42 std::string system_path;
[email protected]b52e52a2010-04-02 22:47:4543 // 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]b4037d132009-11-11 01:10:4547 };
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]62c7ef32010-03-23 23:44:2457 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]b52e52a2010-04-02 22:47:4561 virtual bool MountPath(const char* device_path) = 0;
[email protected]b4037d132009-11-11 01:10:4562
[email protected]819a43862010-08-12 10:09:2163 // Factory function, creates a new instance and returns ownership.
64 // For normal usage, access the singleton via CrosLibrary::Get().
[email protected]617fd0d2010-08-04 20:05:1765 static MountLibrary* GetImpl(bool stub);
[email protected]b4037d132009-11-11 01:10:4566};
67
68} // namespace chromeos
69
[email protected]268b02f2010-02-04 21:07:1570#endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_