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_EXTENSIONS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_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
25 : public chromeos::PowerManagerClient::Observer
,
26 public chromeos::disks::DiskMountManager::Observer
{
29 virtual ~MountedDiskMonitor();
31 // PowerManagerClient::Observer overrides:
32 virtual void SuspendImminent() OVERRIDE
;
33 virtual void SystemResumed(const base::TimeDelta
& sleep_duration
) OVERRIDE
;
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
)
47 virtual void OnFormatEvent(
48 chromeos::disks::DiskMountManager::FormatEvent event
,
49 chromeos::FormatError error_code
,
50 const std::string
& device_path
) OVERRIDE
;
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;
57 // Maps source paths with corresponding uuids.
58 typedef std::map
<std::string
, std::string
> DiskMap
;
61 typedef std::set
<std::string
> DiskSet
;
66 DiskMap mounted_disks_
;
67 DiskSet unmounted_while_resuming_
;
68 base::WeakPtrFactory
<MountedDiskMonitor
> weak_factory_
;
70 DISALLOW_COPY_AND_ASSIGN(MountedDiskMonitor
);
73 } // namespace file_manager
75 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_