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

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: Add test to make sure observers can see updated disks. 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
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
339
340 // If the device is corrupted but it's still possible to format it, it will 343 // If the device is corrupted but it's still possible to format it, it will
341 // be fake mounted. 344 // be fake mounted.
342 if ((entry.error_code() == MOUNT_ERROR_NONE || 345 if ((entry.error_code() == MOUNT_ERROR_NONE ||
343 mount_info.mount_condition) && 346 mount_info.mount_condition) &&
344 mount_points_.find(mount_info.mount_path) == mount_points_.end()) { 347 mount_points_.find(mount_info.mount_path) == mount_points_.end()) {
345 mount_points_.insert(MountPointMap::value_type(mount_info.mount_path, 348 mount_points_.insert(MountPointMap::value_type(mount_info.mount_path,
346 mount_info)); 349 mount_info));
347 } 350 }
351
348 if ((entry.error_code() == MOUNT_ERROR_NONE || 352 if ((entry.error_code() == MOUNT_ERROR_NONE ||
349 mount_info.mount_condition) && 353 mount_info.mount_condition) &&
350 mount_info.mount_type == MOUNT_TYPE_DEVICE && 354 mount_info.mount_type == MOUNT_TYPE_DEVICE &&
351 !mount_info.source_path.empty() && 355 !mount_info.source_path.empty() &&
352 !mount_info.mount_path.empty()) { 356 !mount_info.mount_path.empty()) {
353 DiskMap::iterator iter = disks_.find(mount_info.source_path); 357 DiskMap::iterator iter = disks_.find(mount_info.source_path);
354 if (iter == disks_.end()) { 358 if (iter != disks_.end()) { // disk might have been removed by now?
355 // disk might have been removed by now? 359 Disk* disk = iter->second;
356 return; 360 DCHECK(disk);
361 // The is_read_only field in *disk may be incorrect when this is called
362 // from CrosDisksClientImpl::OnMountCompleted.
363 // Overwrite based on the access mode option that was passed when
364 // issuing
365 // mount command to the same mount path last time.
366 // |source_path| should be same as |disk->device_path| because
367 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a
368 // source path when mounting a device.
369 AccessModeMap::iterator it = access_modes_.find(entry.source_path());
370 if (it != access_modes_.end()) {
371 disk->set_read_only(it->second ==
372 chromeos::MOUNT_ACCESS_MODE_READ_ONLY);
373 }
374 disk->set_mount_path(mount_info.mount_path);
357 } 375 }
358 Disk* disk = iter->second;
359 DCHECK(disk);
360 disk->set_mount_path(mount_info.mount_path);
361 } 376 }
377 // Observers may read the values of disks_. So notify them after tweaking
378 // values of disks_.
379 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info);
362 } 380 }
363 381
364 // Callback for UnmountPath. 382 // Callback for UnmountPath.
365 void OnUnmountPath(const UnmountPathCallback& callback, 383 void OnUnmountPath(const UnmountPathCallback& callback,
366 bool success, 384 bool success,
367 const std::string& mount_path) { 385 const std::string& mount_path) {
368 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path); 386 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path);
369 if (mount_points_it == mount_points_.end()) { 387 if (mount_points_it == mount_points_.end()) {
370 // The path was unmounted, but not as a result of this unmount request, 388 // The path was unmounted, but not as a result of this unmount request,
371 // so return error. 389 // so return error.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 disk_info.uuid(), 484 disk_info.uuid(),
467 FindSystemPathPrefix(disk_info.system_path()), 485 FindSystemPathPrefix(disk_info.system_path()),
468 disk_info.device_type(), 486 disk_info.device_type(),
469 disk_info.total_size_in_bytes(), 487 disk_info.total_size_in_bytes(),
470 disk_info.is_drive(), 488 disk_info.is_drive(),
471 disk_info.is_read_only(), 489 disk_info.is_read_only(),
472 disk_info.has_media(), 490 disk_info.has_media(),
473 disk_info.on_boot_device(), 491 disk_info.on_boot_device(),
474 disk_info.on_removable_device(), 492 disk_info.on_removable_device(),
475 disk_info.is_hidden()); 493 disk_info.is_hidden());
494 // If the device was mounted by the instance, apply recorded parameter.
495 // Lookup by |device_path| which we pass to cros-disks when mounting a
496 // device in |VolumeManager::OnDiskEvent()|.
497 AccessModeMap::iterator access_mode =
498 access_modes_.find(disk->device_path());
499 if (access_mode != access_modes_.end()) {
500 disk->set_read_only(access_mode->second ==
501 chromeos::MOUNT_ACCESS_MODE_READ_ONLY);
502 }
476 disks_.insert(std::make_pair(disk_info.device_path(), disk)); 503 disks_.insert(std::make_pair(disk_info.device_path(), disk));
477 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk); 504 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk);
478 } 505 }
479 506
480 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are 507 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are
481 // enumerated. 508 // enumerated.
482 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) { 509 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) {
483 std::set<std::string> current_device_set(devices.begin(), devices.end()); 510 std::set<std::string> current_device_set(devices.begin(), devices.end());
484 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { 511 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) {
485 if (current_device_set.find(iter->first) == current_device_set.end()) { 512 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_; 660 DiskMountManager::MountPointMap mount_points_;
634 661
635 typedef std::set<std::string> SystemPathPrefixSet; 662 typedef std::set<std::string> SystemPathPrefixSet;
636 SystemPathPrefixSet system_path_prefixes_; 663 SystemPathPrefixSet system_path_prefixes_;
637 664
638 bool already_refreshed_; 665 bool already_refreshed_;
639 std::vector<EnsureMountInfoRefreshedCallback> refresh_callbacks_; 666 std::vector<EnsureMountInfoRefreshedCallback> refresh_callbacks_;
640 667
641 std::unique_ptr<SuspendUnmountManager> suspend_unmount_manager_; 668 std::unique_ptr<SuspendUnmountManager> suspend_unmount_manager_;
642 669
670 // Whether the instance attempted to mount a device in read-only mode for
671 // each source path.
672 typedef std::map<std::string, chromeos::MountAccessMode> AccessModeMap;
673 AccessModeMap access_modes_;
674
643 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_; 675 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_;
644 676
645 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl); 677 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl);
646 }; 678 };
647 679
648 } // namespace 680 } // namespace
649 681
650 DiskMountManager::Disk::Disk(const std::string& device_path, 682 DiskMountManager::Disk::Disk(const std::string& device_path,
651 const std::string& mount_path, 683 const std::string& mount_path,
652 const std::string& system_path, 684 const std::string& system_path,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 VLOG(1) << "DiskMountManager Shutdown completed"; 795 VLOG(1) << "DiskMountManager Shutdown completed";
764 } 796 }
765 797
766 // static 798 // static
767 DiskMountManager* DiskMountManager::GetInstance() { 799 DiskMountManager* DiskMountManager::GetInstance() {
768 return g_disk_mount_manager; 800 return g_disk_mount_manager;
769 } 801 }
770 802
771 } // namespace disks 803 } // namespace disks
772 } // namespace chromeos 804 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698