1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_
6 #define COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_
8 #include <DiskArbitration/DiskArbitration.h>
13 #include "base/apple/scoped_cftyperef.h"
14 #include "base/memory/weak_ptr.h"
15 #include "components/storage_monitor/storage_monitor.h"
17 namespace storage_monitor {
19 class ImageCaptureDeviceManager;
21 // This class posts notifications to listeners when a new disk
22 // is attached, removed, or changed.
23 class StorageMonitorMac : public StorageMonitor,
24 public base::SupportsWeakPtr<StorageMonitorMac> {
28 UPDATE_DEVICE_CHANGED,
29 UPDATE_DEVICE_REMOVED,
32 // Should only be called by browser start up code. Use GetInstance() instead.
35 StorageMonitorMac(const StorageMonitorMac&) = delete;
36 StorageMonitorMac& operator=(const StorageMonitorMac&) = delete;
38 ~StorageMonitorMac() override;
42 void UpdateDisk(UpdateType update_type,
43 std::string* bsd_name,
44 const StorageInfo& info);
46 bool GetStorageInfoForPath(const base::FilePath& path,
47 StorageInfo* device_info) const override;
49 void EjectDevice(const std::string& device_id,
50 base::OnceCallback<void(EjectStatus)> callback) override;
53 static void DiskAppearedCallback(DADiskRef disk, void* context);
54 static void DiskDisappearedCallback(DADiskRef disk, void* context);
55 static void DiskDescriptionChangedCallback(DADiskRef disk,
58 void GetDiskInfoAndUpdate(DADiskRef disk, UpdateType update_type);
60 bool ShouldPostNotificationForDisk(const StorageInfo& info) const;
61 bool FindDiskWithMountPoint(const base::FilePath& mount_point,
62 StorageInfo* info) const;
64 base::apple::ScopedCFTypeRef<DASessionRef> session_;
65 // Maps disk bsd names to disk info objects. This map tracks all mountable
66 // devices on the system, though only notifications for removable devices are
68 std::map<std::string, StorageInfo> disk_info_map_;
70 int pending_disk_updates_ = 0;
72 std::unique_ptr<ImageCaptureDeviceManager> image_capture_device_manager_;
75 } // namespace storage_monitor
77 #endif // COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_