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 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" | 5 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "chromeos/dbus/power_manager_client.h" | 10 #include "chromeos/dbus/power_manager_client.h" |
11 | 11 |
12 using chromeos::disks::DiskMountManager; | 12 using chromeos::disks::DiskMountManager; |
13 | 13 |
14 namespace file_manager { | 14 namespace file_manager { |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Time span of the resuming process. All unmount events sent during this | 17 // Time span of the resuming process. All unmount events sent during this |
18 // time are considered as being part of remounting process, since remounting | 18 // time are considered as being part of remounting process, since remounting |
19 // is done just after resuming. | 19 // is done just after resuming. |
20 const base::TimeDelta kResumingTimeSpan = base::TimeDelta::FromSeconds(5); | 20 const base::TimeDelta kResumingTimeSpan = base::TimeDelta::FromSeconds(5); |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 MountedDiskMonitor::MountedDiskMonitor( | 24 MountedDiskMonitor::MountedDiskMonitor( |
25 chromeos::PowerManagerClient* power_manager_client, | 25 chromeos::PowerManagerClient* power_manager_client) |
26 chromeos::disks::DiskMountManager* disk_mount_manager) | |
27 : power_manager_client_(power_manager_client), | 26 : power_manager_client_(power_manager_client), |
28 disk_mount_manager_(disk_mount_manager), | |
29 is_resuming_(false), | 27 is_resuming_(false), |
30 resuming_time_span_(kResumingTimeSpan), | 28 resuming_time_span_(kResumingTimeSpan), |
31 weak_factory_(this) { | 29 weak_factory_(this) { |
32 DCHECK(power_manager_client_); | 30 DCHECK(power_manager_client_); |
33 DCHECK(disk_mount_manager_); | |
34 power_manager_client_->AddObserver(this); | 31 power_manager_client_->AddObserver(this); |
35 disk_mount_manager_->AddObserver(this); | |
36 disk_mount_manager_->RequestMountInfoRefresh(); | |
37 } | 32 } |
38 | 33 |
39 MountedDiskMonitor::~MountedDiskMonitor() { | 34 MountedDiskMonitor::~MountedDiskMonitor() { |
40 disk_mount_manager_->RemoveObserver(this); | |
41 power_manager_client_->RemoveObserver(this); | 35 power_manager_client_->RemoveObserver(this); |
42 } | 36 } |
43 | 37 |
44 void MountedDiskMonitor::SuspendImminent() { | 38 void MountedDiskMonitor::SuspendImminent() { |
45 // Flip the resuming flag while suspending, so it is possible to detect | 39 // Flip the resuming flag while suspending, so it is possible to detect |
46 // resuming as soon as possible after the lid is open. Note, that mount | 40 // resuming as soon as possible after the lid is open. Note, that mount |
47 // events may occur before the SuspendDone method is called. | 41 // events may occur before the SuspendDone method is called. |
48 is_resuming_ = true; | 42 is_resuming_ = true; |
49 weak_factory_.InvalidateWeakPtrs(); | 43 weak_factory_.InvalidateWeakPtrs(); |
50 } | 44 } |
(...skipping 22 matching lines...) Expand all Loading... |
73 } | 67 } |
74 | 68 |
75 void MountedDiskMonitor::MarkAsHardUnpluggedReported( | 69 void MountedDiskMonitor::MarkAsHardUnpluggedReported( |
76 const std::string& device_path) { | 70 const std::string& device_path) { |
77 hard_unplugged_[device_path] = HARD_UNPLUGGED_AND_REPORTED; | 71 hard_unplugged_[device_path] = HARD_UNPLUGGED_AND_REPORTED; |
78 } | 72 } |
79 | 73 |
80 void MountedDiskMonitor::OnMountEvent( | 74 void MountedDiskMonitor::OnMountEvent( |
81 chromeos::disks::DiskMountManager::MountEvent event, | 75 chromeos::disks::DiskMountManager::MountEvent event, |
82 chromeos::MountError error_code, | 76 chromeos::MountError error_code, |
83 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { | 77 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info, |
| 78 const DiskMountManager::Disk* disk) { |
84 if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) | 79 if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) |
85 return; | 80 return; |
86 | 81 |
87 switch (event) { | 82 switch (event) { |
88 case DiskMountManager::MOUNTING: { | 83 case DiskMountManager::MOUNTING: { |
89 const DiskMountManager::Disk* disk = | |
90 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); | |
91 if (!disk || error_code != chromeos::MOUNT_ERROR_NONE) | 84 if (!disk || error_code != chromeos::MOUNT_ERROR_NONE) |
92 return; | 85 return; |
93 mounted_disks_[mount_info.source_path] = disk->fs_uuid(); | 86 mounted_disks_[mount_info.source_path] = disk->fs_uuid(); |
94 break; | 87 break; |
95 } | 88 } |
96 | 89 |
97 case DiskMountManager::UNMOUNTING: { | 90 case DiskMountManager::UNMOUNTING: { |
98 DiskMap::iterator it = mounted_disks_.find(mount_info.source_path); | 91 DiskMap::iterator it = mounted_disks_.find(mount_info.source_path); |
99 if (it == mounted_disks_.end()) | 92 if (it == mounted_disks_.end()) |
100 return; | 93 return; |
(...skipping 25 matching lines...) Expand all Loading... |
126 chromeos::disks::DiskMountManager::DeviceEvent event, | 119 chromeos::disks::DiskMountManager::DeviceEvent event, |
127 const std::string& device_path) { | 120 const std::string& device_path) { |
128 if (event == chromeos::disks::DiskMountManager::DEVICE_REMOVED) { | 121 if (event == chromeos::disks::DiskMountManager::DEVICE_REMOVED) { |
129 const std::map<std::string, HardUnpluggedState>::iterator it | 122 const std::map<std::string, HardUnpluggedState>::iterator it |
130 = hard_unplugged_.find(device_path); | 123 = hard_unplugged_.find(device_path); |
131 if (it != hard_unplugged_.end()) | 124 if (it != hard_unplugged_.end()) |
132 hard_unplugged_.erase(it); | 125 hard_unplugged_.erase(it); |
133 } | 126 } |
134 } | 127 } |
135 | 128 |
136 void MountedDiskMonitor::OnFormatEvent( | |
137 chromeos::disks::DiskMountManager::FormatEvent event, | |
138 chromeos::FormatError error_code, | |
139 const std::string& device_path) { | |
140 } | |
141 | |
142 void MountedDiskMonitor::Reset() { | 129 void MountedDiskMonitor::Reset() { |
143 unmounted_while_resuming_.clear(); | 130 unmounted_while_resuming_.clear(); |
144 is_resuming_ = false; | 131 is_resuming_ = false; |
145 } | 132 } |
146 | 133 |
147 } // namespace file_manager | 134 } // namespace file_manager |
OLD | NEW |