1// Copyright (c) 2012 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 5#ifndef CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_ 6#define CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_ 7 8#include <DiskArbitration/DiskArbitration.h> 9#include <map> 10 11#include "base/mac/scoped_cftyperef.h" 12#include "base/memory/weak_ptr.h" 13#include "chrome/browser/storage_monitor/storage_monitor.h" 14 15class ImageCaptureDeviceManager; 16 17// This class posts notifications to listeners when a new disk 18// is attached, removed, or changed. 19class StorageMonitorMac : public StorageMonitor, 20 public base::SupportsWeakPtr<StorageMonitorMac> { 21 public: 22 enum UpdateType { 23 UPDATE_DEVICE_ADDED, 24 UPDATE_DEVICE_CHANGED, 25 UPDATE_DEVICE_REMOVED, 26 }; 27 28 // Should only be called by browser start up code. Use GetInstance() instead. 29 StorageMonitorMac(); 30 31 virtual ~StorageMonitorMac(); 32 33 virtual void Init() OVERRIDE; 34 35 void UpdateDisk(const std::string& bsd_name, 36 const StorageInfo& info, 37 UpdateType update_type); 38 39 virtual bool GetStorageInfoForPath( 40 const base::FilePath& path, 41 StorageInfo* device_info) const OVERRIDE; 42 43 virtual void EjectDevice( 44 const std::string& device_id, 45 base::Callback<void(EjectStatus)> callback) OVERRIDE; 46 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); 54 55 bool ShouldPostNotificationForDisk(const StorageInfo& info) const; 56 bool FindDiskWithMountPoint(const base::FilePath& mount_point, 57 StorageInfo* info) const; 58 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_; 64 65 int pending_disk_updates_; 66 67 scoped_ptr<ImageCaptureDeviceManager> image_capture_device_manager_; 68 69 DISALLOW_COPY_AND_ASSIGN(StorageMonitorMac); 70}; 71 72#endif // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_MONITOR_MAC_H_ 73