storage_monitor_mac.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2014 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. #ifndef COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_
  5. #define COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_
  6. #include <DiskArbitration/DiskArbitration.h>
  7. #include <map>
  8. #include <memory>
  9. #include "base/mac/scoped_cftyperef.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "components/storage_monitor/storage_monitor.h"
  12. namespace storage_monitor {
  13. class ImageCaptureDeviceManager;
  14. // This class posts notifications to listeners when a new disk
  15. // is attached, removed, or changed.
  16. class StorageMonitorMac : public StorageMonitor,
  17. public base::SupportsWeakPtr<StorageMonitorMac> {
  18. public:
  19. enum UpdateType {
  20. UPDATE_DEVICE_ADDED,
  21. UPDATE_DEVICE_CHANGED,
  22. UPDATE_DEVICE_REMOVED,
  23. };
  24. // Should only be called by browser start up code. Use GetInstance() instead.
  25. StorageMonitorMac();
  26. StorageMonitorMac(const StorageMonitorMac&) = delete;
  27. StorageMonitorMac& operator=(const StorageMonitorMac&) = delete;
  28. ~StorageMonitorMac() override;
  29. void Init() override;
  30. void UpdateDisk(UpdateType update_type,
  31. std::string* bsd_name,
  32. const StorageInfo& info);
  33. bool GetStorageInfoForPath(const base::FilePath& path,
  34. StorageInfo* device_info) const override;
  35. void EjectDevice(const std::string& device_id,
  36. base::OnceCallback<void(EjectStatus)> callback) override;
  37. private:
  38. static void DiskAppearedCallback(DADiskRef disk, void* context);
  39. static void DiskDisappearedCallback(DADiskRef disk, void* context);
  40. static void DiskDescriptionChangedCallback(DADiskRef disk,
  41. CFArrayRef keys,
  42. void* context);
  43. void GetDiskInfoAndUpdate(DADiskRef disk, UpdateType update_type);
  44. bool ShouldPostNotificationForDisk(const StorageInfo& info) const;
  45. bool FindDiskWithMountPoint(const base::FilePath& mount_point,
  46. StorageInfo* info) const;
  47. base::ScopedCFTypeRef<DASessionRef> session_;
  48. // Maps disk bsd names to disk info objects. This map tracks all mountable
  49. // devices on the system, though only notifications for removable devices are
  50. // posted.
  51. std::map<std::string, StorageInfo> disk_info_map_;
  52. int pending_disk_updates_;
  53. std::unique_ptr<ImageCaptureDeviceManager> image_capture_device_manager_;
  54. };
  55. } // namespace storage_monitor
  56. #endif // COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_