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 |
25 : public chromeos::PowerManagerClient::Observer, | 25 : public chromeos::PowerManagerClient::Observer, |
26 public chromeos::disks::DiskMountManager::Observer { | 26 public chromeos::disks::DiskMountManager::Observer { |
27 public: | 27 public: |
28 MountedDiskMonitor(); | 28 MountedDiskMonitor( |
29 chromeos::PowerManagerClient* power_manager_client, | |
30 chromeos::disks::DiskMountManager* disk_mount_manager); | |
29 virtual ~MountedDiskMonitor(); | 31 virtual ~MountedDiskMonitor(); |
30 | 32 |
31 // PowerManagerClient::Observer overrides: | 33 // PowerManagerClient::Observer overrides: |
32 virtual void SuspendImminent() OVERRIDE; | 34 virtual void SuspendImminent() OVERRIDE; |
33 virtual void SystemResumed(const base::TimeDelta& sleep_duration) OVERRIDE; | 35 virtual void SystemResumed(const base::TimeDelta& sleep_duration) OVERRIDE; |
34 | 36 |
35 // DiskMountManager::Observer overrides. | 37 // DiskMountManager::Observer overrides. |
36 virtual void OnDiskEvent( | 38 virtual void OnDiskEvent( |
37 chromeos::disks::DiskMountManager::DiskEvent event, | 39 chromeos::disks::DiskMountManager::DiskEvent event, |
38 const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE; | 40 const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE; |
39 virtual void OnDeviceEvent( | 41 virtual void OnDeviceEvent( |
40 chromeos::disks::DiskMountManager::DeviceEvent event, | 42 chromeos::disks::DiskMountManager::DeviceEvent event, |
41 const std::string& device_path) OVERRIDE; | 43 const std::string& device_path) OVERRIDE; |
42 virtual void OnMountEvent( | 44 virtual void OnMountEvent( |
43 chromeos::disks::DiskMountManager::MountEvent event, | 45 chromeos::disks::DiskMountManager::MountEvent event, |
44 chromeos::MountError error_code, | 46 chromeos::MountError error_code, |
45 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) | 47 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) |
46 OVERRIDE; | 48 OVERRIDE; |
47 virtual void OnFormatEvent( | 49 virtual void OnFormatEvent( |
48 chromeos::disks::DiskMountManager::FormatEvent event, | 50 chromeos::disks::DiskMountManager::FormatEvent event, |
49 chromeos::FormatError error_code, | 51 chromeos::FormatError error_code, |
50 const std::string& device_path) OVERRIDE; | 52 const std::string& device_path) OVERRIDE; |
51 | 53 |
52 // Checks if the disk is being remounted. The disk is remounting if it has | 54 // Checks if the disk is being remounted. The disk is remounting if it has |
53 // been unmounted during the resuming time span. | 55 // been unmounted during the resuming time span. |
54 bool DiskIsRemounting( | 56 bool DiskIsRemounting( |
55 const chromeos::disks::DiskMountManager::Disk& disk) const; | 57 const chromeos::disks::DiskMountManager::Disk& disk) const; |
58 | |
59 // In order to avoid consuming time a lot for testing, this allows to set the | |
60 // resuming time span. | |
61 void SetResumingTimeSpanForTesting( | |
hashimoto
2013/09/09 12:15:17
nit: set_resuming_time_span_for_testing because th
hidehiko
2013/09/09 12:44:11
Done.
| |
62 const base::TimeDelta& resuming_time_span) { | |
63 resuming_time_span_ = resuming_time_span; | |
64 } | |
65 | |
56 private: | 66 private: |
57 // Maps source paths with corresponding uuids. | 67 // Maps source paths with corresponding uuids. |
58 typedef std::map<std::string, std::string> DiskMap; | 68 typedef std::map<std::string, std::string> DiskMap; |
59 | 69 |
60 // Set of uuids. | 70 // Set of uuids. |
61 typedef std::set<std::string> DiskSet; | 71 typedef std::set<std::string> DiskSet; |
62 | 72 |
63 void Reset(); | 73 void Reset(); |
64 | 74 |
75 chromeos::PowerManagerClient* power_manager_client_; | |
76 chromeos::disks::DiskMountManager* disk_mount_manager_; | |
77 | |
65 bool is_resuming_; | 78 bool is_resuming_; |
66 DiskMap mounted_disks_; | 79 DiskMap mounted_disks_; |
67 DiskSet unmounted_while_resuming_; | 80 DiskSet unmounted_while_resuming_; |
81 base::TimeDelta resuming_time_span_; | |
68 base::WeakPtrFactory<MountedDiskMonitor> weak_factory_; | 82 base::WeakPtrFactory<MountedDiskMonitor> weak_factory_; |
69 | 83 |
70 DISALLOW_COPY_AND_ASSIGN(MountedDiskMonitor); | 84 DISALLOW_COPY_AND_ASSIGN(MountedDiskMonitor); |
71 }; | 85 }; |
72 | 86 |
73 } // namespace file_manager | 87 } // namespace file_manager |
74 | 88 |
75 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ | 89 #endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_MOUNTED_DISK_MONITOR_H_ |
OLD | NEW |