Chromium Code Reviews| 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(mount_label, access_mode)); | |
|
satorux1
2016/08/12 02:47:51
At this point, mount isn't complete yet. How about
yamaguchi
2016/08/15 15:32:48
OnMountCompleted is invoked by the signal from DBu
| |
| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 mount_info.mount_type == MOUNT_TYPE_DEVICE && | 349 mount_info.mount_type == MOUNT_TYPE_DEVICE && |
| 345 !mount_info.source_path.empty() && | 350 !mount_info.source_path.empty() && |
| 346 !mount_info.mount_path.empty()) { | 351 !mount_info.mount_path.empty()) { |
| 347 DiskMap::iterator iter = disks_.find(mount_info.source_path); | 352 DiskMap::iterator iter = disks_.find(mount_info.source_path); |
| 348 if (iter == disks_.end()) { | 353 if (iter == disks_.end()) { |
| 349 // disk might have been removed by now? | 354 // disk might have been removed by now? |
| 350 return; | 355 return; |
| 351 } | 356 } |
| 352 Disk* disk = iter->second; | 357 Disk* disk = iter->second; |
| 353 DCHECK(disk); | 358 DCHECK(disk); |
| 359 // The is_read_only field in *disk may be incorrect when this is called | |
| 360 // from CrosDisksClientImpl::OnMountCompleted. | |
| 361 // Overwrite based on the access mode option that was passed when issuing | |
| 362 // mount command to the same mount path last time. | |
| 363 AccessModeMap::iterator it = access_modes_.find(disk->mount_path()); | |
|
satorux1
2016/08/12 02:47:51
access_modes_'s keys are mount labels, but here, i
yamaguchi
2016/08/15 15:32:48
Good catch. We need to use device path instead of
| |
| 364 if (it != access_modes_.end()) { | |
| 365 disk->set_read_only(it->second == | |
| 366 chromeos::MOUNT_ACCESS_MODE_READ_ONLY); | |
| 367 } | |
|
satorux1
2016/08/12 02:47:52
If 'access_mode' is passed to OnMountCompleted(),
| |
| 354 disk->set_mount_path(mount_info.mount_path); | 368 disk->set_mount_path(mount_info.mount_path); |
| 355 } | 369 } |
| 356 } | 370 } |
| 357 | 371 |
| 358 // Callback for UnmountPath. | 372 // Callback for UnmountPath. |
| 359 void OnUnmountPath(const UnmountPathCallback& callback, | 373 void OnUnmountPath(const UnmountPathCallback& callback, |
| 360 bool success, | 374 bool success, |
| 361 const std::string& mount_path) { | 375 const std::string& mount_path) { |
| 362 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); | 376 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); |
| 363 if (mount_points_it == mount_points_.end()) { | 377 if (mount_points_it == mount_points_.end()) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 disk_info.uuid(), | 474 disk_info.uuid(), |
| 461 FindSystemPathPrefix(disk_info.system_path()), | 475 FindSystemPathPrefix(disk_info.system_path()), |
| 462 disk_info.device_type(), | 476 disk_info.device_type(), |
| 463 disk_info.total_size_in_bytes(), | 477 disk_info.total_size_in_bytes(), |
| 464 disk_info.is_drive(), | 478 disk_info.is_drive(), |
| 465 disk_info.is_read_only(), | 479 disk_info.is_read_only(), |
| 466 disk_info.has_media(), | 480 disk_info.has_media(), |
| 467 disk_info.on_boot_device(), | 481 disk_info.on_boot_device(), |
| 468 disk_info.on_removable_device(), | 482 disk_info.on_removable_device(), |
| 469 disk_info.is_hidden()); | 483 disk_info.is_hidden()); |
| 484 // If the device was mounted by the instance, apply recorded parameter. | |
| 485 AccessModeMap::iterator mount_option = | |
|
satorux1
2016/08/12 02:47:52
mount_option -> access_mode?
yamaguchi
2016/08/15 15:32:48
Done.
| |
| 486 access_modes_.find(disk->mount_path()); | |
| 487 if (mount_option != access_modes_.end()) { | |
| 488 disk->set_read_only(mount_option->second == | |
| 489 chromeos::MOUNT_ACCESS_MODE_READ_ONLY); | |
| 490 } | |
|
satorux1
2016/08/12 02:47:52
another approach: instead of introducing access_mo
yamaguchi
2016/08/15 15:32:48
The previous disk will be available only when this
| |
| 470 disks_.insert(std::make_pair(disk_info.device_path(), disk)); | 491 disks_.insert(std::make_pair(disk_info.device_path(), disk)); |
| 471 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk); | 492 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk); |
| 472 } | 493 } |
| 473 | 494 |
| 474 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are | 495 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are |
| 475 // enumerated. | 496 // enumerated. |
| 476 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) { | 497 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) { |
| 477 std::set<std::string> current_device_set(devices.begin(), devices.end()); | 498 std::set<std::string> current_device_set(devices.begin(), devices.end()); |
| 478 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { | 499 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { |
| 479 if (current_device_set.find(iter->first) == current_device_set.end()) { | 500 if (current_device_set.find(iter->first) == current_device_set.end()) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 DiskMountManager::MountPointMap mount_points_; | 648 DiskMountManager::MountPointMap mount_points_; |
| 628 | 649 |
| 629 typedef std::set<std::string> SystemPathPrefixSet; | 650 typedef std::set<std::string> SystemPathPrefixSet; |
| 630 SystemPathPrefixSet system_path_prefixes_; | 651 SystemPathPrefixSet system_path_prefixes_; |
| 631 | 652 |
| 632 bool already_refreshed_; | 653 bool already_refreshed_; |
| 633 std::vector<EnsureMountInfoRefreshedCallback> refresh_callbacks_; | 654 std::vector<EnsureMountInfoRefreshedCallback> refresh_callbacks_; |
| 634 | 655 |
| 635 std::unique_ptr<SuspendUnmountManager> suspend_unmount_manager_; | 656 std::unique_ptr<SuspendUnmountManager> suspend_unmount_manager_; |
| 636 | 657 |
| 658 // Whether the instance attempted to mount a device in read-only mode for | |
| 659 // each mount label (not mount source). | |
| 660 typedef std::map<std::string, chromeos::MountAccessMode> AccessModeMap; | |
| 661 AccessModeMap access_modes_; | |
| 662 | |
| 637 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_; | 663 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_; |
| 638 | 664 |
| 639 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl); | 665 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl); |
| 640 }; | 666 }; |
| 641 | 667 |
| 642 } // namespace | 668 } // namespace |
| 643 | 669 |
| 644 DiskMountManager::Disk::Disk(const std::string& device_path, | 670 DiskMountManager::Disk::Disk(const std::string& device_path, |
| 645 const std::string& mount_path, | 671 const std::string& mount_path, |
| 646 const std::string& system_path, | 672 const std::string& system_path, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 VLOG(1) << "DiskMountManager Shutdown completed"; | 783 VLOG(1) << "DiskMountManager Shutdown completed"; |
| 758 } | 784 } |
| 759 | 785 |
| 760 // static | 786 // static |
| 761 DiskMountManager* DiskMountManager::GetInstance() { | 787 DiskMountManager* DiskMountManager::GetInstance() { |
| 762 return g_disk_mount_manager; | 788 return g_disk_mount_manager; |
| 763 } | 789 } |
| 764 | 790 |
| 765 } // namespace disks | 791 } // namespace disks |
| 766 } // namespace chromeos | 792 } // namespace chromeos |
| OLD | NEW |