| 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 <vector> |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 virtual void MountChanged(MountLibrary* obj, | 52 virtual void MountChanged(MountLibrary* obj, |
| 53 MountEventType evt, | 53 MountEventType evt, |
| 54 const std::string& path) = 0; | 54 const std::string& path) = 0; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 virtual ~MountLibrary() {} | 57 virtual ~MountLibrary() {} |
| 58 virtual void AddObserver(Observer* observer) = 0; | 58 virtual void AddObserver(Observer* observer) = 0; |
| 59 virtual void RemoveObserver(Observer* observer) = 0; | 59 virtual void RemoveObserver(Observer* observer) = 0; |
| 60 virtual const DiskVector& disks() const = 0; | 60 virtual const DiskVector& disks() const = 0; |
| 61 virtual bool MountPath(const char* device_path) = 0; | 61 virtual bool MountPath(const char* device_path) = 0; |
| 62 }; | |
| 63 | 62 |
| 64 // This class handles the interaction with the ChromeOS mount library APIs. | 63 // Get library implementation. |
| 65 // Classes can add themselves as observers. Users can get an instance of this | 64 static MountLibrary* GetImpl(bool stub); |
| 66 // library class like this: MountLibrary::Get(). | |
| 67 class MountLibraryImpl : public MountLibrary { | |
| 68 public: | |
| 69 MountLibraryImpl(); | |
| 70 virtual ~MountLibraryImpl(); | |
| 71 | |
| 72 // MountLibrary overrides. | |
| 73 virtual void AddObserver(Observer* observer); | |
| 74 virtual void RemoveObserver(Observer* observer); | |
| 75 virtual const DiskVector& disks() const { return disks_; } | |
| 76 virtual bool MountPath(const char* device_path); | |
| 77 private: | |
| 78 void ParseDisks(const MountStatus& status); | |
| 79 | |
| 80 // This method is called when there's a change in mount status. | |
| 81 // This method is called the UI Thread. | |
| 82 static void MountStatusChangedHandler(void* object, | |
| 83 const MountStatus& status, | |
| 84 MountEventType evt, | |
| 85 const char* path); | |
| 86 | |
| 87 // This methods starts the monitoring of mount changes. | |
| 88 // It should be called on the UI Thread. | |
| 89 void Init(); | |
| 90 | |
| 91 // Called by the handler to update the mount status. | |
| 92 // This will notify all the Observers. | |
| 93 void UpdateMountStatus(const MountStatus& status, | |
| 94 MountEventType evt, | |
| 95 const std::string& path); | |
| 96 | |
| 97 ObserverList<Observer> observers_; | |
| 98 | |
| 99 // A reference to the mount api, to allow callbacks when the mount | |
| 100 // status changes. | |
| 101 MountStatusConnection mount_status_connection_; | |
| 102 | |
| 103 // The list of disks found. | |
| 104 DiskVector disks_; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl); | |
| 107 }; | 65 }; |
| 108 | 66 |
| 109 } // namespace chromeos | 67 } // namespace chromeos |
| 110 | 68 |
| 111 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ | 69 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ |
| OLD | NEW |