| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chromeos/disks/disk_mount_manager.h" | 5 #include "chromeos/disks/disk_mount_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 cros_disks_client_->SetFormatCompletedHandler( | 42 cros_disks_client_->SetFormatCompletedHandler( |
| 43 base::Bind(&DiskMountManagerImpl::OnFormatCompleted, | 43 base::Bind(&DiskMountManagerImpl::OnFormatCompleted, |
| 44 weak_ptr_factory_.GetWeakPtr())); | 44 weak_ptr_factory_.GetWeakPtr())); |
| 45 } | 45 } |
| 46 | 46 |
| 47 virtual ~DiskMountManagerImpl() { | 47 virtual ~DiskMountManagerImpl() { |
| 48 STLDeleteContainerPairSecondPointers(disks_.begin(), disks_.end()); | 48 STLDeleteContainerPairSecondPointers(disks_.begin(), disks_.end()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // DiskMountManager override. | 51 // DiskMountManager override. |
| 52 virtual void AddObserver(Observer* observer) OVERRIDE { | 52 virtual void AddObserver(Observer* observer) override { |
| 53 observers_.AddObserver(observer); | 53 observers_.AddObserver(observer); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // DiskMountManager override. | 56 // DiskMountManager override. |
| 57 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 57 virtual void RemoveObserver(Observer* observer) override { |
| 58 observers_.RemoveObserver(observer); | 58 observers_.RemoveObserver(observer); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // DiskMountManager override. | 61 // DiskMountManager override. |
| 62 virtual void MountPath(const std::string& source_path, | 62 virtual void MountPath(const std::string& source_path, |
| 63 const std::string& source_format, | 63 const std::string& source_format, |
| 64 const std::string& mount_label, | 64 const std::string& mount_label, |
| 65 MountType type) OVERRIDE { | 65 MountType type) override { |
| 66 // Hidden and non-existent devices should not be mounted. | 66 // Hidden and non-existent devices should not be mounted. |
| 67 if (type == MOUNT_TYPE_DEVICE) { | 67 if (type == MOUNT_TYPE_DEVICE) { |
| 68 DiskMap::const_iterator it = disks_.find(source_path); | 68 DiskMap::const_iterator it = disks_.find(source_path); |
| 69 if (it == disks_.end() || it->second->is_hidden()) { | 69 if (it == disks_.end() || it->second->is_hidden()) { |
| 70 OnMountCompleted(MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, | 70 OnMountCompleted(MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, |
| 71 "")); | 71 "")); |
| 72 return; | 72 return; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 cros_disks_client_->Mount( | 75 cros_disks_client_->Mount( |
| 76 source_path, | 76 source_path, |
| 77 source_format, | 77 source_format, |
| 78 mount_label, | 78 mount_label, |
| 79 // When succeeds, OnMountCompleted will be called by | 79 // When succeeds, OnMountCompleted will be called by |
| 80 // "MountCompleted" signal instead. | 80 // "MountCompleted" signal instead. |
| 81 base::Bind(&base::DoNothing), | 81 base::Bind(&base::DoNothing), |
| 82 base::Bind(&DiskMountManagerImpl::OnMountCompleted, | 82 base::Bind(&DiskMountManagerImpl::OnMountCompleted, |
| 83 weak_ptr_factory_.GetWeakPtr(), | 83 weak_ptr_factory_.GetWeakPtr(), |
| 84 MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, ""))); | 84 MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, ""))); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // DiskMountManager override. | 87 // DiskMountManager override. |
| 88 virtual void UnmountPath(const std::string& mount_path, | 88 virtual void UnmountPath(const std::string& mount_path, |
| 89 UnmountOptions options, | 89 UnmountOptions options, |
| 90 const UnmountPathCallback& callback) OVERRIDE { | 90 const UnmountPathCallback& callback) override { |
| 91 UnmountChildMounts(mount_path); | 91 UnmountChildMounts(mount_path); |
| 92 cros_disks_client_->Unmount(mount_path, options, | 92 cros_disks_client_->Unmount(mount_path, options, |
| 93 base::Bind(&DiskMountManagerImpl::OnUnmountPath, | 93 base::Bind(&DiskMountManagerImpl::OnUnmountPath, |
| 94 weak_ptr_factory_.GetWeakPtr(), | 94 weak_ptr_factory_.GetWeakPtr(), |
| 95 callback, | 95 callback, |
| 96 true, | 96 true, |
| 97 mount_path), | 97 mount_path), |
| 98 base::Bind(&DiskMountManagerImpl::OnUnmountPath, | 98 base::Bind(&DiskMountManagerImpl::OnUnmountPath, |
| 99 weak_ptr_factory_.GetWeakPtr(), | 99 weak_ptr_factory_.GetWeakPtr(), |
| 100 callback, | 100 callback, |
| 101 false, | 101 false, |
| 102 mount_path)); | 102 mount_path)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // DiskMountManager override. | 105 // DiskMountManager override. |
| 106 virtual void FormatMountedDevice(const std::string& mount_path) OVERRIDE { | 106 virtual void FormatMountedDevice(const std::string& mount_path) override { |
| 107 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path); | 107 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path); |
| 108 if (mount_point == mount_points_.end()) { | 108 if (mount_point == mount_points_.end()) { |
| 109 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found."; | 109 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found."; |
| 110 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, mount_path); | 110 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, mount_path); |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 | 113 |
| 114 std::string device_path = mount_point->second.source_path; | 114 std::string device_path = mount_point->second.source_path; |
| 115 DiskMap::const_iterator disk = disks_.find(device_path); | 115 DiskMap::const_iterator disk = disks_.find(device_path); |
| 116 if (disk == disks_.end()) { | 116 if (disk == disks_.end()) { |
| 117 LOG(ERROR) << "Device with path \"" << device_path << "\" not found."; | 117 LOG(ERROR) << "Device with path \"" << device_path << "\" not found."; |
| 118 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, device_path); | 118 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, device_path); |
| 119 return; | 119 return; |
| 120 } | 120 } |
| 121 | 121 |
| 122 UnmountPath(disk->second->mount_path(), | 122 UnmountPath(disk->second->mount_path(), |
| 123 UNMOUNT_OPTIONS_NONE, | 123 UNMOUNT_OPTIONS_NONE, |
| 124 base::Bind(&DiskMountManagerImpl::OnUnmountPathForFormat, | 124 base::Bind(&DiskMountManagerImpl::OnUnmountPathForFormat, |
| 125 weak_ptr_factory_.GetWeakPtr(), | 125 weak_ptr_factory_.GetWeakPtr(), |
| 126 device_path)); | 126 device_path)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // DiskMountManager override. | 129 // DiskMountManager override. |
| 130 virtual void UnmountDeviceRecursively( | 130 virtual void UnmountDeviceRecursively( |
| 131 const std::string& device_path, | 131 const std::string& device_path, |
| 132 const UnmountDeviceRecursivelyCallbackType& callback) OVERRIDE { | 132 const UnmountDeviceRecursivelyCallbackType& callback) override { |
| 133 std::vector<std::string> devices_to_unmount; | 133 std::vector<std::string> devices_to_unmount; |
| 134 | 134 |
| 135 // Get list of all devices to unmount. | 135 // Get list of all devices to unmount. |
| 136 int device_path_len = device_path.length(); | 136 int device_path_len = device_path.length(); |
| 137 for (DiskMap::iterator it = disks_.begin(); it != disks_.end(); ++it) { | 137 for (DiskMap::iterator it = disks_.begin(); it != disks_.end(); ++it) { |
| 138 if (!it->second->mount_path().empty() && | 138 if (!it->second->mount_path().empty() && |
| 139 strncmp(device_path.c_str(), it->second->device_path().c_str(), | 139 strncmp(device_path.c_str(), it->second->device_path().c_str(), |
| 140 device_path_len) == 0) { | 140 device_path_len) == 0) { |
| 141 devices_to_unmount.push_back(it->second->mount_path()); | 141 devices_to_unmount.push_back(it->second->mount_path()); |
| 142 } | 142 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 base::Bind(&DiskMountManagerImpl::OnUnmountDeviceRecursively, | 185 base::Bind(&DiskMountManagerImpl::OnUnmountDeviceRecursively, |
| 186 weak_ptr_factory_.GetWeakPtr(), | 186 weak_ptr_factory_.GetWeakPtr(), |
| 187 cb_data, | 187 cb_data, |
| 188 false, | 188 false, |
| 189 devices_to_unmount[i])); | 189 devices_to_unmount[i])); |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 | 192 |
| 193 // DiskMountManager override. | 193 // DiskMountManager override. |
| 194 virtual void EnsureMountInfoRefreshed( | 194 virtual void EnsureMountInfoRefreshed( |
| 195 const EnsureMountInfoRefreshedCallback& callback) OVERRIDE { | 195 const EnsureMountInfoRefreshedCallback& callback) override { |
| 196 if (already_refreshed_) { | 196 if (already_refreshed_) { |
| 197 callback.Run(true); | 197 callback.Run(true); |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 | 200 |
| 201 refresh_callbacks_.push_back(callback); | 201 refresh_callbacks_.push_back(callback); |
| 202 if (refresh_callbacks_.size() == 1) { | 202 if (refresh_callbacks_.size() == 1) { |
| 203 // If there's no in-flight refreshing task, start it. | 203 // If there's no in-flight refreshing task, start it. |
| 204 cros_disks_client_->EnumerateAutoMountableDevices( | 204 cros_disks_client_->EnumerateAutoMountableDevices( |
| 205 base::Bind(&DiskMountManagerImpl::RefreshAfterEnumerateDevices, | 205 base::Bind(&DiskMountManagerImpl::RefreshAfterEnumerateDevices, |
| 206 weak_ptr_factory_.GetWeakPtr()), | 206 weak_ptr_factory_.GetWeakPtr()), |
| 207 base::Bind(&DiskMountManagerImpl::RefreshCompleted, | 207 base::Bind(&DiskMountManagerImpl::RefreshCompleted, |
| 208 weak_ptr_factory_.GetWeakPtr(), false)); | 208 weak_ptr_factory_.GetWeakPtr(), false)); |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 // DiskMountManager override. | 212 // DiskMountManager override. |
| 213 virtual const DiskMap& disks() const OVERRIDE { return disks_; } | 213 virtual const DiskMap& disks() const override { return disks_; } |
| 214 | 214 |
| 215 // DiskMountManager override. | 215 // DiskMountManager override. |
| 216 virtual const Disk* FindDiskBySourcePath(const std::string& source_path) | 216 virtual const Disk* FindDiskBySourcePath(const std::string& source_path) |
| 217 const OVERRIDE { | 217 const override { |
| 218 DiskMap::const_iterator disk_it = disks_.find(source_path); | 218 DiskMap::const_iterator disk_it = disks_.find(source_path); |
| 219 return disk_it == disks_.end() ? NULL : disk_it->second; | 219 return disk_it == disks_.end() ? NULL : disk_it->second; |
| 220 } | 220 } |
| 221 | 221 |
| 222 // DiskMountManager override. | 222 // DiskMountManager override. |
| 223 virtual const MountPointMap& mount_points() const OVERRIDE { | 223 virtual const MountPointMap& mount_points() const override { |
| 224 return mount_points_; | 224 return mount_points_; |
| 225 } | 225 } |
| 226 | 226 |
| 227 // DiskMountManager override. | 227 // DiskMountManager override. |
| 228 virtual bool AddDiskForTest(Disk* disk) OVERRIDE { | 228 virtual bool AddDiskForTest(Disk* disk) override { |
| 229 if (disks_.find(disk->device_path()) != disks_.end()) { | 229 if (disks_.find(disk->device_path()) != disks_.end()) { |
| 230 LOG(ERROR) << "Attempt to add a duplicate disk"; | 230 LOG(ERROR) << "Attempt to add a duplicate disk"; |
| 231 return false; | 231 return false; |
| 232 } | 232 } |
| 233 | 233 |
| 234 disks_.insert(std::make_pair(disk->device_path(), disk)); | 234 disks_.insert(std::make_pair(disk->device_path(), disk)); |
| 235 return true; | 235 return true; |
| 236 } | 236 } |
| 237 | 237 |
| 238 // DiskMountManager override. | 238 // DiskMountManager override. |
| 239 // Corresponding disk should be added to the manager before this is called. | 239 // Corresponding disk should be added to the manager before this is called. |
| 240 virtual bool AddMountPointForTest( | 240 virtual bool AddMountPointForTest( |
| 241 const MountPointInfo& mount_point) OVERRIDE { | 241 const MountPointInfo& mount_point) override { |
| 242 if (mount_points_.find(mount_point.mount_path) != mount_points_.end()) { | 242 if (mount_points_.find(mount_point.mount_path) != mount_points_.end()) { |
| 243 LOG(ERROR) << "Attempt to add a duplicate mount point"; | 243 LOG(ERROR) << "Attempt to add a duplicate mount point"; |
| 244 return false; | 244 return false; |
| 245 } | 245 } |
| 246 if (mount_point.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 246 if (mount_point.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
| 247 disks_.find(mount_point.source_path) == disks_.end()) { | 247 disks_.find(mount_point.source_path) == disks_.end()) { |
| 248 LOG(ERROR) << "Device mount points must have a disk entry."; | 248 LOG(ERROR) << "Device mount points must have a disk entry."; |
| 249 return false; | 249 return false; |
| 250 } | 250 } |
| 251 | 251 |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 VLOG(1) << "DiskMountManager Shutdown completed"; | 751 VLOG(1) << "DiskMountManager Shutdown completed"; |
| 752 } | 752 } |
| 753 | 753 |
| 754 // static | 754 // static |
| 755 DiskMountManager* DiskMountManager::GetInstance() { | 755 DiskMountManager* DiskMountManager::GetInstance() { |
| 756 return g_disk_mount_manager; | 756 return g_disk_mount_manager; |
| 757 } | 757 } |
| 758 | 758 |
| 759 } // namespace disks | 759 } // namespace disks |
| 760 } // namespace chromeos | 760 } // namespace chromeos |
| OLD | NEW |