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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 // DiskMountManager override. | 59 // DiskMountManager override. |
60 virtual void MountPath(const std::string& source_path, | 60 virtual void MountPath(const std::string& source_path, |
61 const std::string& source_format, | 61 const std::string& source_format, |
62 const std::string& mount_label, | 62 const std::string& mount_label, |
63 MountType type) OVERRIDE { | 63 MountType type) OVERRIDE { |
64 // Hidden and non-existent devices should not be mounted. | 64 // Hidden and non-existent devices should not be mounted. |
65 if (type == MOUNT_TYPE_DEVICE) { | 65 if (type == MOUNT_TYPE_DEVICE) { |
66 DiskMap::const_iterator it = disks_.find(source_path); | 66 DiskMap::const_iterator it = disks_.find(source_path); |
67 if (it == disks_.end() || it->second->is_hidden()) { | 67 if (it == disks_.end() || it->second->is_hidden()) { |
68 OnMountCompleted(MOUNT_ERROR_INTERNAL, source_path, type, ""); | 68 OnMountCompleted(MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, |
| 69 "")); |
69 return; | 70 return; |
70 } | 71 } |
71 } | 72 } |
72 cros_disks_client_->Mount( | 73 cros_disks_client_->Mount( |
73 source_path, | 74 source_path, |
74 source_format, | 75 source_format, |
75 mount_label, | 76 mount_label, |
76 // When succeeds, OnMountCompleted will be called by | 77 // When succeeds, OnMountCompleted will be called by |
77 // "MountCompleted" signal instead. | 78 // "MountCompleted" signal instead. |
78 base::Bind(&base::DoNothing), | 79 base::Bind(&base::DoNothing), |
79 base::Bind(&DiskMountManagerImpl::OnMountCompleted, | 80 base::Bind(&DiskMountManagerImpl::OnMountCompleted, |
80 weak_ptr_factory_.GetWeakPtr(), | 81 weak_ptr_factory_.GetWeakPtr(), |
81 MOUNT_ERROR_INTERNAL, | 82 MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, ""))); |
82 source_path, | |
83 type, | |
84 "")); | |
85 } | 83 } |
86 | 84 |
87 // DiskMountManager override. | 85 // DiskMountManager override. |
88 virtual void UnmountPath(const std::string& mount_path, | 86 virtual void UnmountPath(const std::string& mount_path, |
89 UnmountOptions options, | 87 UnmountOptions options, |
90 const UnmountPathCallback& callback) OVERRIDE { | 88 const UnmountPathCallback& callback) OVERRIDE { |
91 UnmountChildMounts(mount_path); | 89 UnmountChildMounts(mount_path); |
92 cros_disks_client_->Unmount(mount_path, options, | 90 cros_disks_client_->Unmount(mount_path, options, |
93 base::Bind(&DiskMountManagerImpl::OnUnmountPath, | 91 base::Bind(&DiskMountManagerImpl::OnUnmountPath, |
94 weak_ptr_factory_.GetWeakPtr(), | 92 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 if (cb_data->num_pending_callbacks == 0) { | 291 if (cb_data->num_pending_callbacks == 0) { |
294 // This code has a problem that the |success| status used here is for the | 292 // This code has a problem that the |success| status used here is for the |
295 // last "unmount" callback, but not whether all unmounting is succeeded. | 293 // last "unmount" callback, but not whether all unmounting is succeeded. |
296 // TODO(hidehiko): Fix the issue. | 294 // TODO(hidehiko): Fix the issue. |
297 cb_data->callback.Run(success); | 295 cb_data->callback.Run(success); |
298 delete cb_data; | 296 delete cb_data; |
299 } | 297 } |
300 } | 298 } |
301 | 299 |
302 // Callback to handle MountCompleted signal and Mount method call failure. | 300 // Callback to handle MountCompleted signal and Mount method call failure. |
303 void OnMountCompleted(MountError error_code, | 301 void OnMountCompleted(const MountEntry& entry) { |
304 const std::string& source_path, | |
305 MountType mount_type, | |
306 const std::string& mount_path) { | |
307 MountCondition mount_condition = MOUNT_CONDITION_NONE; | 302 MountCondition mount_condition = MOUNT_CONDITION_NONE; |
308 if (mount_type == MOUNT_TYPE_DEVICE) { | 303 if (entry.mount_type() == MOUNT_TYPE_DEVICE) { |
309 if (error_code == MOUNT_ERROR_UNKNOWN_FILESYSTEM) { | 304 if (entry.error_code() == MOUNT_ERROR_UNKNOWN_FILESYSTEM) { |
310 mount_condition = MOUNT_CONDITION_UNKNOWN_FILESYSTEM; | 305 mount_condition = MOUNT_CONDITION_UNKNOWN_FILESYSTEM; |
311 } | 306 } |
312 if (error_code == MOUNT_ERROR_UNSUPPORTED_FILESYSTEM) { | 307 if (entry.error_code() == MOUNT_ERROR_UNSUPPORTED_FILESYSTEM) { |
313 mount_condition = MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; | 308 mount_condition = MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; |
314 } | 309 } |
315 } | 310 } |
316 const MountPointInfo mount_info(source_path, mount_path, mount_type, | 311 const MountPointInfo mount_info(entry.source_path(), |
| 312 entry.mount_path(), |
| 313 entry.mount_type(), |
317 mount_condition); | 314 mount_condition); |
318 | 315 |
319 NotifyMountStatusUpdate(MOUNTING, error_code, mount_info); | 316 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info); |
320 | 317 |
321 // If the device is corrupted but it's still possible to format it, it will | 318 // If the device is corrupted but it's still possible to format it, it will |
322 // be fake mounted. | 319 // be fake mounted. |
323 if ((error_code == MOUNT_ERROR_NONE || mount_info.mount_condition) && | 320 if ((entry.error_code() == MOUNT_ERROR_NONE || |
| 321 mount_info.mount_condition) && |
324 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { | 322 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { |
325 mount_points_.insert(MountPointMap::value_type(mount_info.mount_path, | 323 mount_points_.insert(MountPointMap::value_type(mount_info.mount_path, |
326 mount_info)); | 324 mount_info)); |
327 } | 325 } |
328 if ((error_code == MOUNT_ERROR_NONE || mount_info.mount_condition) && | 326 if ((entry.error_code() == MOUNT_ERROR_NONE || |
| 327 mount_info.mount_condition) && |
329 mount_info.mount_type == MOUNT_TYPE_DEVICE && | 328 mount_info.mount_type == MOUNT_TYPE_DEVICE && |
330 !mount_info.source_path.empty() && | 329 !mount_info.source_path.empty() && |
331 !mount_info.mount_path.empty()) { | 330 !mount_info.mount_path.empty()) { |
332 DiskMap::iterator iter = disks_.find(mount_info.source_path); | 331 DiskMap::iterator iter = disks_.find(mount_info.source_path); |
333 if (iter == disks_.end()) { | 332 if (iter == disks_.end()) { |
334 // disk might have been removed by now? | 333 // disk might have been removed by now? |
335 return; | 334 return; |
336 } | 335 } |
337 Disk* disk = iter->second; | 336 Disk* disk = iter->second; |
338 DCHECK(disk); | 337 DCHECK(disk); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 VLOG(1) << "DiskMountManager Shutdown completed"; | 700 VLOG(1) << "DiskMountManager Shutdown completed"; |
702 } | 701 } |
703 | 702 |
704 // static | 703 // static |
705 DiskMountManager* DiskMountManager::GetInstance() { | 704 DiskMountManager* DiskMountManager::GetInstance() { |
706 return g_disk_mount_manager; | 705 return g_disk_mount_manager; |
707 } | 706 } |
708 | 707 |
709 } // namespace disks | 708 } // namespace disks |
710 } // namespace chromeos | 709 } // namespace chromeos |
OLD | NEW |