Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / components / storage_monitor / storage_monitor_mac.h
blob9379f5e734abc1f6d9650a5f5eb150022f8c0306
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.
5 #ifndef COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_
6 #define COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_
8 #include <DiskArbitration/DiskArbitration.h>
9 #include <map>
11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/memory/weak_ptr.h"
13 #include "components/storage_monitor/storage_monitor.h"
15 namespace storage_monitor {
17 class ImageCaptureDeviceManager;
19 // This class posts notifications to listeners when a new disk
20 // is attached, removed, or changed.
21 class StorageMonitorMac : public StorageMonitor,
22 public base::SupportsWeakPtr<StorageMonitorMac> {
23 public:
24 enum UpdateType {
25 UPDATE_DEVICE_ADDED,
26 UPDATE_DEVICE_CHANGED,
27 UPDATE_DEVICE_REMOVED,
30 // Should only be called by browser start up code. Use GetInstance() instead.
31 StorageMonitorMac();
33 ~StorageMonitorMac() override;
35 void Init() override;
37 void UpdateDisk(const std::string& bsd_name,
38 const StorageInfo& info,
39 UpdateType update_type);
41 bool GetStorageInfoForPath(const base::FilePath& path,
42 StorageInfo* device_info) const override;
44 void EjectDevice(const std::string& device_id,
45 base::Callback<void(EjectStatus)> callback) override;
47 private:
48 static void DiskAppearedCallback(DADiskRef disk, void* context);
49 static void DiskDisappearedCallback(DADiskRef disk, void* context);
50 static void DiskDescriptionChangedCallback(DADiskRef disk,
51 CFArrayRef keys,
52 void *context);
53 void GetDiskInfoAndUpdate(DADiskRef disk, UpdateType update_type);
55 bool ShouldPostNotificationForDisk(const StorageInfo& info) const;
56 bool FindDiskWithMountPoint(const base::FilePath& mount_point,
57 StorageInfo* info) const;
59 base::ScopedCFTypeRef<DASessionRef> session_;
60 // Maps disk bsd names to disk info objects. This map tracks all mountable
61 // devices on the system, though only notifications for removable devices are
62 // posted.
63 std::map<std::string, StorageInfo> disk_info_map_;
65 int pending_disk_updates_;
67 scoped_ptr<ImageCaptureDeviceManager> image_capture_device_manager_;
69 DISALLOW_COPY_AND_ASSIGN(StorageMonitorMac);
72 } // namespace storage_monitor
74 #endif // COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_