file_manager: Move FindPreferredIcon() to drive_app_registry.h
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_manager / mounted_disk_monitor.h
blobd4c0730f2f8957f6411f2f0a4027ccfb58155334
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_
8 #include <map>
9 #include <set>
10 #include <string>
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 {
27 public:
28 MountedDiskMonitor();
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)
46 OVERRIDE;
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;
56 private:
57 // Maps source paths with corresponding uuids.
58 typedef std::map<std::string, std::string> DiskMap;
60 // Set of uuids.
61 typedef std::set<std::string> DiskSet;
63 void Reset();
65 bool is_resuming_;
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_