| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chromeos/dbus/power_manager_client.h" | 14 #include "chromeos/dbus/power_manager_client.h" |
| 15 #include "chromeos/disks/disk_mount_manager.h" | 15 #include "chromeos/disks/disk_mount_manager.h" |
| 16 | 16 |
| 17 namespace file_manager { | 17 namespace file_manager { |
| 18 | 18 |
| 19 // Observes PowerManager and updates its state when the system suspends and | 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 | 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 | 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 | 22 // removed/added events (events for the devices that were present before suspend |
| 23 // should not trigger any new notifications or file manager windows). | 23 // should not trigger any new notifications or file manager windows). |
| 24 class MountedDiskMonitor | 24 class MountedDiskMonitor : public chromeos::PowerManagerClient::Observer { |
| 25 : public chromeos::PowerManagerClient::Observer, | |
| 26 public chromeos::disks::DiskMountManager::Observer { | |
| 27 public: | 25 public: |
| 28 MountedDiskMonitor( | 26 explicit MountedDiskMonitor( |
| 29 chromeos::PowerManagerClient* power_manager_client, | 27 chromeos::PowerManagerClient* power_manager_client); |
| 30 chromeos::disks::DiskMountManager* disk_mount_manager); | |
| 31 virtual ~MountedDiskMonitor(); | 28 virtual ~MountedDiskMonitor(); |
| 32 | 29 |
| 33 // PowerManagerClient::Observer overrides: | 30 // PowerManagerClient::Observer overrides: |
| 34 virtual void SuspendImminent() OVERRIDE; | 31 virtual void SuspendImminent() OVERRIDE; |
| 35 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; | 32 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; |
| 36 | 33 |
| 37 // DiskMountManager::Observer overrides. | 34 // Receives forwarded notifications originates from DiskMountManager. |
| 38 virtual void OnDiskEvent( | 35 void OnDiskEvent( |
| 39 chromeos::disks::DiskMountManager::DiskEvent event, | 36 chromeos::disks::DiskMountManager::DiskEvent event, |
| 40 const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE; | 37 const chromeos::disks::DiskMountManager::Disk* disk); |
| 41 virtual void OnDeviceEvent( | 38 void OnDeviceEvent( |
| 42 chromeos::disks::DiskMountManager::DeviceEvent event, | 39 chromeos::disks::DiskMountManager::DeviceEvent event, |
| 43 const std::string& device_path) OVERRIDE; | 40 const std::string& device_path); |
| 44 virtual void OnMountEvent( | 41 void OnMountEvent( |
| 45 chromeos::disks::DiskMountManager::MountEvent event, | 42 chromeos::disks::DiskMountManager::MountEvent event, |
| 46 chromeos::MountError error_code, | 43 chromeos::MountError error_code, |
| 47 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) | 44 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info, |
| 48 OVERRIDE; | 45 const chromeos::disks::DiskMountManager::Disk* disk); |
| 49 virtual void OnFormatEvent( | |
| 50 chromeos::disks::DiskMountManager::FormatEvent event, | |
| 51 chromeos::FormatError error_code, | |
| 52 const std::string& device_path) OVERRIDE; | |
| 53 | 46 |
| 54 // Checks if the disk is being remounted. The disk is remounting if it has | 47 // Checks if the disk is being remounted. The disk is remounting if it has |
| 55 // been unmounted during the resuming time span. | 48 // been unmounted during the resuming time span. |
| 56 bool DiskIsRemounting( | 49 bool DiskIsRemounting( |
| 57 const chromeos::disks::DiskMountManager::Disk& disk) const; | 50 const chromeos::disks::DiskMountManager::Disk& disk) const; |
| 58 bool DeviceIsHardUnpluggedButNotReported( | 51 bool DeviceIsHardUnpluggedButNotReported( |
| 59 const std::string& device_path) const; | 52 const std::string& device_path) const; |
| 60 void MarkAsHardUnpluggedReported(const std::string& device_path); | 53 void MarkAsHardUnpluggedReported(const std::string& device_path); |
| 61 | 54 |
| 62 // In order to avoid consuming time a lot for testing, this allows to set the | 55 // In order to avoid consuming time a lot for testing, this allows to set the |
| 63 // resuming time span. | 56 // resuming time span. |
| 64 void set_resuming_time_span_for_testing( | 57 void set_resuming_time_span_for_testing( |
| 65 const base::TimeDelta& resuming_time_span) { | 58 const base::TimeDelta& resuming_time_span) { |
| 66 resuming_time_span_ = resuming_time_span; | 59 resuming_time_span_ = resuming_time_span; |
| 67 } | 60 } |
| 68 | 61 |
| 69 private: | 62 private: |
| 70 enum HardUnpluggedState { HARD_UNPLUGGED, HARD_UNPLUGGED_AND_REPORTED }; | 63 enum HardUnpluggedState { HARD_UNPLUGGED, HARD_UNPLUGGED_AND_REPORTED }; |
| 71 // Maps source paths with corresponding uuids. | 64 // Maps source paths with corresponding uuids. |
| 72 typedef std::map<std::string, std::string> DiskMap; | 65 typedef std::map<std::string, std::string> DiskMap; |
| 73 | 66 |
| 74 // Set of uuids. | 67 // Set of uuids. |
| 75 typedef std::set<std::string> DiskSet; | 68 typedef std::set<std::string> DiskSet; |
| 76 | 69 |
| 77 void Reset(); | 70 void Reset(); |
| 78 | 71 |
| 79 chromeos::PowerManagerClient* power_manager_client_; | 72 chromeos::PowerManagerClient* power_manager_client_; |
| 80 chromeos::disks::DiskMountManager* disk_mount_manager_; | |
| 81 | 73 |
| 82 bool is_resuming_; | 74 bool is_resuming_; |
| 83 DiskMap mounted_disks_; | 75 DiskMap mounted_disks_; |
| 84 DiskSet unmounted_while_resuming_; | 76 DiskSet unmounted_while_resuming_; |
| 85 // Set of device path that is hard unplugged. | 77 // Set of device path that is hard unplugged. |
| 86 std::map<std::string, HardUnpluggedState> hard_unplugged_; | 78 std::map<std::string, HardUnpluggedState> hard_unplugged_; |
| 87 base::TimeDelta resuming_time_span_; | 79 base::TimeDelta resuming_time_span_; |
| 88 base::WeakPtrFactory<MountedDiskMonitor> weak_factory_; | 80 base::WeakPtrFactory<MountedDiskMonitor> weak_factory_; |
| 89 | 81 |
| 90 DISALLOW_COPY_AND_ASSIGN(MountedDiskMonitor); | 82 DISALLOW_COPY_AND_ASSIGN(MountedDiskMonitor); |
| 91 }; | 83 }; |
| 92 | 84 |
| 93 } // namespace file_manager | 85 } // namespace file_manager |
| 94 | 86 |
| 95 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ | 87 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ |
| OLD | NEW |