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.
5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_
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"
17 namespace file_manager {
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 : public chromeos::PowerManagerClient::Observer {
26 explicit MountedDiskMonitor(
27 chromeos::PowerManagerClient* power_manager_client);
28 virtual ~MountedDiskMonitor();
30 // PowerManagerClient::Observer overrides:
31 virtual void SuspendImminent() OVERRIDE;
32 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE;
34 // Receives forwarded notifications originates from DiskMountManager.
36 chromeos::disks::DiskMountManager::DiskEvent event,
37 const chromeos::disks::DiskMountManager::Disk* disk);
39 chromeos::disks::DiskMountManager::DeviceEvent event,
40 const std::string& device_path);
42 chromeos::disks::DiskMountManager::MountEvent event,
43 chromeos::MountError error_code,
44 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info,
45 const chromeos::disks::DiskMountManager::Disk* disk);
47 // Checks if the disk is being remounted. The disk is remounting if it has
48 // been unmounted during the resuming time span.
49 bool DiskIsRemounting(
50 const chromeos::disks::DiskMountManager::Disk& disk) const;
51 bool DeviceIsHardUnpluggedButNotReported(
52 const std::string& device_path) const;
53 void MarkAsHardUnpluggedReported(const std::string& device_path);
55 // In order to avoid consuming time a lot for testing, this allows to set the
56 // resuming time span.
57 void set_resuming_time_span_for_testing(
58 const base::TimeDelta& resuming_time_span) {
59 resuming_time_span_ = resuming_time_span;
63 enum HardUnpluggedState { HARD_UNPLUGGED, HARD_UNPLUGGED_AND_REPORTED };
64 // Maps source paths with corresponding uuids.
65 typedef std::map<std::string, std::string> DiskMap;
68 typedef std::set<std::string> DiskSet;
72 chromeos::PowerManagerClient* power_manager_client_;
75 DiskMap mounted_disks_;
76 DiskSet unmounted_while_resuming_;
77 // Set of device path that is hard unplugged.
78 std::map<std::string, HardUnpluggedState> hard_unplugged_;
79 base::TimeDelta resuming_time_span_;
80 base::WeakPtrFactory<MountedDiskMonitor> weak_factory_;
82 DISALLOW_COPY_AND_ASSIGN(MountedDiskMonitor);
85 } // namespace file_manager
87 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_