1 // Copyright 2013 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_CHROMEOS_EXTENSIONS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ 7 8 #include <map> 9 #include <set> 10 #include <string> 11 12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/weak_ptr.h" 14 #include "chromeos/dbus/power_manager_client.h" 15 #include "chromeos/disks/disk_mount_manager.h" 16 17 namespace file_manager { 18 19 // Observes PowerManager and updates its state when the system suspends and 20 // resumes. After the system resumes it will stay in "is_resuming" state for 21 // couple of seconds. This is to give DiskManager time to process device 22 // removed/added events (events for the devices that were present before suspend 23 // should not trigger any new notifications or file manager windows). 24 class MountedDiskMonitor 25 : public chromeos::PowerManagerClient::Observer, 26 public chromeos::disks::DiskMountManager::Observer { 27 public: 28 MountedDiskMonitor(); 29 virtual ~MountedDiskMonitor(); 30 31 // PowerManagerClient::Observer overrides: 32 virtual void SuspendImminent() OVERRIDE; 33 virtual void SystemResumed(const base::TimeDelta& sleep_duration) OVERRIDE; 34 35 // DiskMountManager::Observer overrides. 36 virtual void OnDiskEvent( 37 chromeos::disks::DiskMountManager::DiskEvent event, 38 const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE; 39 virtual void OnDeviceEvent( 40 chromeos::disks::DiskMountManager::DeviceEvent event, 41 const std::string& device_path) OVERRIDE; 42 virtual void OnMountEvent( 43 chromeos::disks::DiskMountManager::MountEvent event, 44 chromeos::MountError error_code, 45 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) 46 OVERRIDE; 47 virtual void OnFormatEvent( 48 chromeos::disks::DiskMountManager::FormatEvent event, 49 chromeos::FormatError error_code, 50 const std::string& device_path) OVERRIDE; 51 52 // Checks if the disk is being remounted. The disk is remounting if it has 53 // been unmounted during the resuming time span. 54 bool DiskIsRemounting( 55 const chromeos::disks::DiskMountManager::Disk& disk) const; 56 private: 57 // Maps source paths with corresponding uuids. 58 typedef std::map<std::string, std::string> DiskMap; 59 60 // Set of uuids. 61 typedef std::set<std::string> DiskSet; 62 63 void Reset(); 64 65 bool is_resuming_; 66 DiskMap mounted_disks_; 67 DiskSet unmounted_while_resuming_; 68 base::WeakPtrFactory<MountedDiskMonitor> weak_factory_; 69 70 DISALLOW_COPY_AND_ASSIGN(MountedDiskMonitor); 71 }; 72 73 } // namespace file_manager 74 75 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ 76