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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 } | 80 } |
81 } | 81 } |
82 cros_disks_client_->Mount( | 82 cros_disks_client_->Mount( |
83 source_path, source_format, mount_label, access_mode, | 83 source_path, source_format, mount_label, access_mode, |
84 // When succeeds, OnMountCompleted will be called by | 84 // When succeeds, OnMountCompleted will be called by |
85 // "MountCompleted" signal instead. | 85 // "MountCompleted" signal instead. |
86 base::Bind(&base::DoNothing), | 86 base::Bind(&base::DoNothing), |
87 base::Bind(&DiskMountManagerImpl::OnMountCompleted, | 87 base::Bind(&DiskMountManagerImpl::OnMountCompleted, |
88 weak_ptr_factory_.GetWeakPtr(), | 88 weak_ptr_factory_.GetWeakPtr(), |
89 MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, ""))); | 89 MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, ""))); |
90 | |
91 // Record the access mode option passed to CrosDisks. | |
92 // This is needed because CrosDisks service methods doesn't return the info | |
93 // via DBus. | |
94 access_modes_.insert(std::make_pair(source_path, access_mode)); | |
90 } | 95 } |
91 | 96 |
92 // DiskMountManager override. | 97 // DiskMountManager override. |
93 void UnmountPath(const std::string& mount_path, | 98 void UnmountPath(const std::string& mount_path, |
94 UnmountOptions options, | 99 UnmountOptions options, |
95 const UnmountPathCallback& callback) override { | 100 const UnmountPathCallback& callback) override { |
96 UnmountChildMounts(mount_path); | 101 UnmountChildMounts(mount_path); |
97 cros_disks_client_->Unmount(mount_path, options, | 102 cros_disks_client_->Unmount(mount_path, options, |
98 base::Bind(&DiskMountManagerImpl::OnUnmountPath, | 103 base::Bind(&DiskMountManagerImpl::OnUnmountPath, |
99 weak_ptr_factory_.GetWeakPtr(), | 104 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 } | 333 } |
329 if (entry.error_code() == MOUNT_ERROR_UNSUPPORTED_FILESYSTEM) { | 334 if (entry.error_code() == MOUNT_ERROR_UNSUPPORTED_FILESYSTEM) { |
330 mount_condition = MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; | 335 mount_condition = MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM; |
331 } | 336 } |
332 } | 337 } |
333 const MountPointInfo mount_info(entry.source_path(), | 338 const MountPointInfo mount_info(entry.source_path(), |
334 entry.mount_path(), | 339 entry.mount_path(), |
335 entry.mount_type(), | 340 entry.mount_type(), |
336 mount_condition); | 341 mount_condition); |
337 | 342 |
338 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info); | 343 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info); |
yamaguchi
2016/08/24 06:46:28
This will invoke observer functions. Especially, S
| |
339 | 344 |
340 // If the device is corrupted but it's still possible to format it, it will | 345 // If the device is corrupted but it's still possible to format it, it will |
341 // be fake mounted. | 346 // be fake mounted. |
342 if ((entry.error_code() == MOUNT_ERROR_NONE || | 347 if ((entry.error_code() == MOUNT_ERROR_NONE || |
343 mount_info.mount_condition) && | 348 mount_info.mount_condition) && |
344 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { | 349 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { |
345 mount_points_.insert(MountPointMap::value_type(mount_info.mount_path, | 350 mount_points_.insert(MountPointMap::value_type(mount_info.mount_path, |
346 mount_info)); | 351 mount_info)); |
347 } | 352 } |
348 if ((entry.error_code() == MOUNT_ERROR_NONE || | 353 if ((entry.error_code() == MOUNT_ERROR_NONE || |
349 mount_info.mount_condition) && | 354 mount_info.mount_condition) && |
350 mount_info.mount_type == MOUNT_TYPE_DEVICE && | 355 mount_info.mount_type == MOUNT_TYPE_DEVICE && |
351 !mount_info.source_path.empty() && | 356 !mount_info.source_path.empty() && |
352 !mount_info.mount_path.empty()) { | 357 !mount_info.mount_path.empty()) { |
353 DiskMap::iterator iter = disks_.find(mount_info.source_path); | 358 DiskMap::iterator iter = disks_.find(mount_info.source_path); |
354 if (iter == disks_.end()) { | 359 if (iter == disks_.end()) { |
355 // disk might have been removed by now? | 360 // disk might have been removed by now? |
356 return; | 361 return; |
357 } | 362 } |
358 Disk* disk = iter->second; | 363 Disk* disk = iter->second; |
359 DCHECK(disk); | 364 DCHECK(disk); |
365 // The is_read_only field in *disk may be incorrect when this is called | |
366 // from CrosDisksClientImpl::OnMountCompleted. | |
367 // Overwrite based on the access mode option that was passed when issuing | |
368 // mount command to the same mount path last time. | |
369 // |source_path| should be same as |disk->device_path| because | |
370 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a | |
371 // source path when mounting a device. | |
372 AccessModeMap::iterator it = access_modes_.find(entry.source_path()); | |
373 if (it != access_modes_.end()) { | |
374 disk->set_read_only(it->second == | |
375 chromeos::MOUNT_ACCESS_MODE_READ_ONLY); | |
376 } | |
360 disk->set_mount_path(mount_info.mount_path); | 377 disk->set_mount_path(mount_info.mount_path); |
361 } | 378 } |
362 } | 379 } |
363 | 380 |
364 // Callback for UnmountPath. | 381 // Callback for UnmountPath. |
365 void OnUnmountPath(const UnmountPathCallback& callback, | 382 void OnUnmountPath(const UnmountPathCallback& callback, |
366 bool success, | 383 bool success, |
367 const std::string& mount_path) { | 384 const std::string& mount_path) { |
368 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); | 385 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); |
369 if (mount_points_it == mount_points_.end()) { | 386 if (mount_points_it == mount_points_.end()) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 disk_info.uuid(), | 483 disk_info.uuid(), |
467 FindSystemPathPrefix(disk_info.system_path()), | 484 FindSystemPathPrefix(disk_info.system_path()), |
468 disk_info.device_type(), | 485 disk_info.device_type(), |
469 disk_info.total_size_in_bytes(), | 486 disk_info.total_size_in_bytes(), |
470 disk_info.is_drive(), | 487 disk_info.is_drive(), |
471 disk_info.is_read_only(), | 488 disk_info.is_read_only(), |
472 disk_info.has_media(), | 489 disk_info.has_media(), |
473 disk_info.on_boot_device(), | 490 disk_info.on_boot_device(), |
474 disk_info.on_removable_device(), | 491 disk_info.on_removable_device(), |
475 disk_info.is_hidden()); | 492 disk_info.is_hidden()); |
493 // If the device was mounted by the instance, apply recorded parameter. | |
494 // Lookup by |device_path| which we pass to cros-disks when mounting a | |
495 // device in |VolumeManager::OnDiskEvent()|. | |
496 AccessModeMap::iterator access_mode = | |
497 access_modes_.find(disk->device_path()); | |
498 if (access_mode != access_modes_.end()) { | |
499 disk->set_read_only(access_mode->second == | |
500 chromeos::MOUNT_ACCESS_MODE_READ_ONLY); | |
501 } | |
476 disks_.insert(std::make_pair(disk_info.device_path(), disk)); | 502 disks_.insert(std::make_pair(disk_info.device_path(), disk)); |
477 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk); | 503 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk); |
478 } | 504 } |
479 | 505 |
480 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are | 506 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are |
481 // enumerated. | 507 // enumerated. |
482 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) { | 508 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) { |
483 std::set<std::string> current_device_set(devices.begin(), devices.end()); | 509 std::set<std::string> current_device_set(devices.begin(), devices.end()); |
484 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { | 510 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { |
485 if (current_device_set.find(iter->first) == current_device_set.end()) { | 511 if (current_device_set.find(iter->first) == current_device_set.end()) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 DiskMountManager::MountPointMap mount_points_; | 659 DiskMountManager::MountPointMap mount_points_; |
634 | 660 |
635 typedef std::set<std::string> SystemPathPrefixSet; | 661 typedef std::set<std::string> SystemPathPrefixSet; |
636 SystemPathPrefixSet system_path_prefixes_; | 662 SystemPathPrefixSet system_path_prefixes_; |
637 | 663 |
638 bool already_refreshed_; | 664 bool already_refreshed_; |
639 std::vector<EnsureMountInfoRefreshedCallback> refresh_callbacks_; | 665 std::vector<EnsureMountInfoRefreshedCallback> refresh_callbacks_; |
640 | 666 |
641 std::unique_ptr<SuspendUnmountManager> suspend_unmount_manager_; | 667 std::unique_ptr<SuspendUnmountManager> suspend_unmount_manager_; |
642 | 668 |
669 // Whether the instance attempted to mount a device in read-only mode for | |
670 // each source path. | |
671 typedef std::map<std::string, chromeos::MountAccessMode> AccessModeMap; | |
672 AccessModeMap access_modes_; | |
673 | |
643 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_; | 674 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_; |
644 | 675 |
645 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl); | 676 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl); |
646 }; | 677 }; |
647 | 678 |
648 } // namespace | 679 } // namespace |
649 | 680 |
650 DiskMountManager::Disk::Disk(const std::string& device_path, | 681 DiskMountManager::Disk::Disk(const std::string& device_path, |
651 const std::string& mount_path, | 682 const std::string& mount_path, |
652 const std::string& system_path, | 683 const std::string& system_path, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 VLOG(1) << "DiskMountManager Shutdown completed"; | 794 VLOG(1) << "DiskMountManager Shutdown completed"; |
764 } | 795 } |
765 | 796 |
766 // static | 797 // static |
767 DiskMountManager* DiskMountManager::GetInstance() { | 798 DiskMountManager* DiskMountManager::GetInstance() { |
768 return g_disk_mount_manager; | 799 return g_disk_mount_manager; |
769 } | 800 } |
770 | 801 |
771 } // namespace disks | 802 } // namespace disks |
772 } // namespace chromeos | 803 } // namespace chromeos |
OLD | NEW |