Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: chromeos/disks/disk_mount_manager.cc

Issue 2230713003: Store correct read-only flag of mounted disks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to head. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/disks/disk_mount_manager.h ('k') | chromeos/disks/disk_mount_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 AccessModeMap::iterator it = access_modes_.find(disk->device_path());
satorux1 2016/08/23 05:40:49 source_path passed to Mount() and disk->device_pat
yamaguchi 2016/08/23 08:08:52 Added comments to the 2 places looking up the map.
370 if (it != access_modes_.end()) {
371 disk->set_read_only(it->second ==
372 chromeos::MOUNT_ACCESS_MODE_READ_ONLY);
373 }
360 disk->set_mount_path(mount_info.mount_path); 374 disk->set_mount_path(mount_info.mount_path);
361 } 375 }
362 } 376 }
363 377
364 // Callback for UnmountPath. 378 // Callback for UnmountPath.
365 void OnUnmountPath(const UnmountPathCallback& callback, 379 void OnUnmountPath(const UnmountPathCallback& callback,
366 bool success, 380 bool success,
367 const std::string& mount_path) { 381 const std::string& mount_path) {
368 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); 382 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path);
369 if (mount_points_it == mount_points_.end()) { 383 if (mount_points_it == mount_points_.end()) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 disk_info.uuid(), 480 disk_info.uuid(),
467 FindSystemPathPrefix(disk_info.system_path()), 481 FindSystemPathPrefix(disk_info.system_path()),
468 disk_info.device_type(), 482 disk_info.device_type(),
469 disk_info.total_size_in_bytes(), 483 disk_info.total_size_in_bytes(),
470 disk_info.is_drive(), 484 disk_info.is_drive(),
471 disk_info.is_read_only(), 485 disk_info.is_read_only(),
472 disk_info.has_media(), 486 disk_info.has_media(),
473 disk_info.on_boot_device(), 487 disk_info.on_boot_device(),
474 disk_info.on_removable_device(), 488 disk_info.on_removable_device(),
475 disk_info.is_hidden()); 489 disk_info.is_hidden());
490 // If the device was mounted by the instance, apply recorded parameter.
491 AccessModeMap::iterator access_mode =
satorux1 2016/08/23 05:40:49 maybe just call it |iter|?
yamaguchi 2016/08/23 08:08:52 No, because it collides with the one for DiskMap::
492 access_modes_.find(disk->device_path());
493 if (access_mode != access_modes_.end()) {
494 disk->set_read_only(access_mode->second ==
495 chromeos::MOUNT_ACCESS_MODE_READ_ONLY);
496 }
476 disks_.insert(std::make_pair(disk_info.device_path(), disk)); 497 disks_.insert(std::make_pair(disk_info.device_path(), disk));
477 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk); 498 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk);
478 } 499 }
479 500
480 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are 501 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are
481 // enumerated. 502 // enumerated.
482 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) { 503 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) {
483 std::set<std::string> current_device_set(devices.begin(), devices.end()); 504 std::set<std::string> current_device_set(devices.begin(), devices.end());
484 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { 505 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) {
485 if (current_device_set.find(iter->first) == current_device_set.end()) { 506 if (current_device_set.find(iter->first) == current_device_set.end()) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 DiskMountManager::MountPointMap mount_points_; 654 DiskMountManager::MountPointMap mount_points_;
634 655
635 typedef std::set<std::string> SystemPathPrefixSet; 656 typedef std::set<std::string> SystemPathPrefixSet;
636 SystemPathPrefixSet system_path_prefixes_; 657 SystemPathPrefixSet system_path_prefixes_;
637 658
638 bool already_refreshed_; 659 bool already_refreshed_;
639 std::vector<EnsureMountInfoRefreshedCallback> refresh_callbacks_; 660 std::vector<EnsureMountInfoRefreshedCallback> refresh_callbacks_;
640 661
641 std::unique_ptr<SuspendUnmountManager> suspend_unmount_manager_; 662 std::unique_ptr<SuspendUnmountManager> suspend_unmount_manager_;
642 663
664 // Whether the instance attempted to mount a device in read-only mode for
665 // each source path.
666 typedef std::map<std::string, chromeos::MountAccessMode> AccessModeMap;
667 AccessModeMap access_modes_;
668
643 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_; 669 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_;
644 670
645 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl); 671 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl);
646 }; 672 };
647 673
648 } // namespace 674 } // namespace
649 675
650 DiskMountManager::Disk::Disk(const std::string& device_path, 676 DiskMountManager::Disk::Disk(const std::string& device_path,
651 const std::string& mount_path, 677 const std::string& mount_path,
652 const std::string& system_path, 678 const std::string& system_path,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 VLOG(1) << "DiskMountManager Shutdown completed"; 789 VLOG(1) << "DiskMountManager Shutdown completed";
764 } 790 }
765 791
766 // static 792 // static
767 DiskMountManager* DiskMountManager::GetInstance() { 793 DiskMountManager* DiskMountManager::GetInstance() {
768 return g_disk_mount_manager; 794 return g_disk_mount_manager;
769 } 795 }
770 796
771 } // namespace disks 797 } // namespace disks
772 } // namespace chromeos 798 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/disks/disk_mount_manager.h ('k') | chromeos/disks/disk_mount_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698