[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / storage_monitor / storage_monitor_mac.h
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.
4
5 #ifndef COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_
6 #define COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_
7
8 #include <DiskArbitration/DiskArbitration.h>
9
10 #include <map>
11 #include <memory>
12
13 #include "base/apple/scoped_cftyperef.h"
14 #include "base/memory/weak_ptr.h"
15 #include "components/storage_monitor/storage_monitor.h"
16
17 namespace storage_monitor {
18
19 class ImageCaptureDeviceManager;
20
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> {
25  public:
26   enum UpdateType {
27     UPDATE_DEVICE_ADDED,
28     UPDATE_DEVICE_CHANGED,
29     UPDATE_DEVICE_REMOVED,
30   };
31
32   // Should only be called by browser start up code.  Use GetInstance() instead.
33   StorageMonitorMac();
34
35   StorageMonitorMac(const StorageMonitorMac&) = delete;
36   StorageMonitorMac& operator=(const StorageMonitorMac&) = delete;
37
38   ~StorageMonitorMac() override;
39
40   void Init() override;
41
42   void UpdateDisk(UpdateType update_type,
43                   std::string* bsd_name,
44                   const StorageInfo& info);
45
46   bool GetStorageInfoForPath(const base::FilePath& path,
47                              StorageInfo* device_info) const override;
48
49   void EjectDevice(const std::string& device_id,
50                    base::OnceCallback<void(EjectStatus)> callback) override;
51
52  private:
53   static void DiskAppearedCallback(DADiskRef disk, void* context);
54   static void DiskDisappearedCallback(DADiskRef disk, void* context);
55   static void DiskDescriptionChangedCallback(DADiskRef disk,
56                                              CFArrayRef keys,
57                                              void* context);
58   void GetDiskInfoAndUpdate(DADiskRef disk, UpdateType update_type);
59
60   bool ShouldPostNotificationForDisk(const StorageInfo& info) const;
61   bool FindDiskWithMountPoint(const base::FilePath& mount_point,
62                               StorageInfo* info) const;
63
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
67   // posted.
68   std::map<std::string, StorageInfo> disk_info_map_;
69
70   int pending_disk_updates_ = 0;
71
72   std::unique_ptr<ImageCaptureDeviceManager> image_capture_device_manager_;
73 };
74
75 }  // namespace storage_monitor
76
77 #endif  // COMPONENTS_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_