| 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // from CrosDisksClientImpl::OnMountCompleted. | 362 // from CrosDisksClientImpl::OnMountCompleted. |
| 363 // The disk should be treated as read-only when: | 363 // The disk should be treated as read-only when: |
| 364 // - the read-only option was passed when issuing mount command | 364 // - the read-only option was passed when issuing mount command |
| 365 // - or the device hardware is read-only. | 365 // - or the device hardware is read-only. |
| 366 // |source_path| should be same as |disk->device_path| because | 366 // |source_path| should be same as |disk->device_path| because |
| 367 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a | 367 // |VolumeManager::OnDiskEvent()| passes the latter to cros-disks as a |
| 368 // source path when mounting a device. | 368 // source path when mounting a device. |
| 369 AccessModeMap::iterator it = access_modes_.find(entry.source_path()); | 369 AccessModeMap::iterator it = access_modes_.find(entry.source_path()); |
| 370 if (it != access_modes_.end() && | 370 if (it != access_modes_.end() && |
| 371 it->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY) { | 371 it->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY) { |
| 372 disk->set_read_only(true); | 372 disk->set_write_disabled_by_policy(true); |
| 373 } | 373 } |
| 374 disk->set_mount_path(mount_info.mount_path); | 374 disk->set_mount_path(mount_info.mount_path); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 // Observers may read the values of disks_. So notify them after tweaking | 377 // Observers may read the values of disks_. So notify them after tweaking |
| 378 // values of disks_. | 378 // values of disks_. |
| 379 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info); | 379 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info); |
| 380 } | 380 } |
| 381 | 381 |
| 382 // Callback for UnmountPath. | 382 // Callback for UnmountPath. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 return; | 463 return; |
| 464 | 464 |
| 465 LOG(WARNING) << "Found disk " << disk_info.device_path(); | 465 LOG(WARNING) << "Found disk " << disk_info.device_path(); |
| 466 // Delete previous disk info for this path: | 466 // Delete previous disk info for this path: |
| 467 bool is_new = true; | 467 bool is_new = true; |
| 468 DiskMap::iterator iter = disks_.find(disk_info.device_path()); | 468 DiskMap::iterator iter = disks_.find(disk_info.device_path()); |
| 469 if (iter != disks_.end()) { | 469 if (iter != disks_.end()) { |
| 470 disks_.erase(iter); | 470 disks_.erase(iter); |
| 471 is_new = false; | 471 is_new = false; |
| 472 } | 472 } |
| 473 |
| 474 // If the device was mounted by the instance, apply recorded parameter. |
| 475 // Otherwise, default to false. |
| 476 // Lookup by |device_path| which we pass to cros-disks when mounting a |
| 477 // device in |VolumeManager::OnDiskEvent()|. |
| 478 auto access_mode = access_modes_.find(disk_info.device_path()); |
| 479 bool write_disabled_by_policy = access_mode != access_modes_.end() |
| 480 && access_mode->second == chromeos::MOUNT_ACCESS_MODE_READ_ONLY; |
| 473 Disk* disk = new Disk(disk_info.device_path(), | 481 Disk* disk = new Disk(disk_info.device_path(), |
| 474 disk_info.mount_path(), | 482 disk_info.mount_path(), |
| 483 write_disabled_by_policy, |
| 475 disk_info.system_path(), | 484 disk_info.system_path(), |
| 476 disk_info.file_path(), | 485 disk_info.file_path(), |
| 477 disk_info.label(), | 486 disk_info.label(), |
| 478 disk_info.drive_label(), | 487 disk_info.drive_label(), |
| 479 disk_info.vendor_id(), | 488 disk_info.vendor_id(), |
| 480 disk_info.vendor_name(), | 489 disk_info.vendor_name(), |
| 481 disk_info.product_id(), | 490 disk_info.product_id(), |
| 482 disk_info.product_name(), | 491 disk_info.product_name(), |
| 483 disk_info.uuid(), | 492 disk_info.uuid(), |
| 484 FindSystemPathPrefix(disk_info.system_path()), | 493 FindSystemPathPrefix(disk_info.system_path()), |
| 485 disk_info.device_type(), | 494 disk_info.device_type(), |
| 486 disk_info.total_size_in_bytes(), | 495 disk_info.total_size_in_bytes(), |
| 487 disk_info.is_drive(), | 496 disk_info.is_drive(), |
| 488 disk_info.is_read_only(), | 497 disk_info.is_read_only(), |
| 489 disk_info.has_media(), | 498 disk_info.has_media(), |
| 490 disk_info.on_boot_device(), | 499 disk_info.on_boot_device(), |
| 491 disk_info.on_removable_device(), | 500 disk_info.on_removable_device(), |
| 492 disk_info.is_hidden()); | 501 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 } | |
| 502 disks_.insert( | 502 disks_.insert( |
| 503 std::make_pair(disk_info.device_path(), base::WrapUnique(disk))); | 503 std::make_pair(disk_info.device_path(), base::WrapUnique(disk))); |
| 504 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk); | 504 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk); |
| 505 } | 505 } |
| 506 | 506 |
| 507 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are | 507 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are |
| 508 // enumerated. | 508 // enumerated. |
| 509 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) { | 509 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) { |
| 510 std::set<std::string> current_device_set(devices.begin(), devices.end()); | 510 std::set<std::string> current_device_set(devices.begin(), devices.end()); |
| 511 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { | 511 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 674 |
| 675 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_; | 675 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_; |
| 676 | 676 |
| 677 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl); | 677 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl); |
| 678 }; | 678 }; |
| 679 | 679 |
| 680 } // namespace | 680 } // namespace |
| 681 | 681 |
| 682 DiskMountManager::Disk::Disk(const std::string& device_path, | 682 DiskMountManager::Disk::Disk(const std::string& device_path, |
| 683 const std::string& mount_path, | 683 const std::string& mount_path, |
| 684 bool write_disabled_by_policy, |
| 684 const std::string& system_path, | 685 const std::string& system_path, |
| 685 const std::string& file_path, | 686 const std::string& file_path, |
| 686 const std::string& device_label, | 687 const std::string& device_label, |
| 687 const std::string& drive_label, | 688 const std::string& drive_label, |
| 688 const std::string& vendor_id, | 689 const std::string& vendor_id, |
| 689 const std::string& vendor_name, | 690 const std::string& vendor_name, |
| 690 const std::string& product_id, | 691 const std::string& product_id, |
| 691 const std::string& product_name, | 692 const std::string& product_name, |
| 692 const std::string& fs_uuid, | 693 const std::string& fs_uuid, |
| 693 const std::string& system_path_prefix, | 694 const std::string& system_path_prefix, |
| 694 DeviceType device_type, | 695 DeviceType device_type, |
| 695 uint64_t total_size_in_bytes, | 696 uint64_t total_size_in_bytes, |
| 696 bool is_parent, | 697 bool is_parent, |
| 697 bool is_read_only, | 698 bool is_read_only_hardware, |
| 698 bool has_media, | 699 bool has_media, |
| 699 bool on_boot_device, | 700 bool on_boot_device, |
| 700 bool on_removable_device, | 701 bool on_removable_device, |
| 701 bool is_hidden) | 702 bool is_hidden) |
| 702 : device_path_(device_path), | 703 : device_path_(device_path), |
| 703 mount_path_(mount_path), | 704 mount_path_(mount_path), |
| 705 write_disabled_by_policy_(write_disabled_by_policy), |
| 704 system_path_(system_path), | 706 system_path_(system_path), |
| 705 file_path_(file_path), | 707 file_path_(file_path), |
| 706 device_label_(device_label), | 708 device_label_(device_label), |
| 707 drive_label_(drive_label), | 709 drive_label_(drive_label), |
| 708 vendor_id_(vendor_id), | 710 vendor_id_(vendor_id), |
| 709 vendor_name_(vendor_name), | 711 vendor_name_(vendor_name), |
| 710 product_id_(product_id), | 712 product_id_(product_id), |
| 711 product_name_(product_name), | 713 product_name_(product_name), |
| 712 fs_uuid_(fs_uuid), | 714 fs_uuid_(fs_uuid), |
| 713 system_path_prefix_(system_path_prefix), | 715 system_path_prefix_(system_path_prefix), |
| 714 device_type_(device_type), | 716 device_type_(device_type), |
| 715 total_size_in_bytes_(total_size_in_bytes), | 717 total_size_in_bytes_(total_size_in_bytes), |
| 716 is_parent_(is_parent), | 718 is_parent_(is_parent), |
| 717 is_read_only_(is_read_only), | 719 is_read_only_hardware_(is_read_only_hardware), |
| 718 has_media_(has_media), | 720 has_media_(has_media), |
| 719 on_boot_device_(on_boot_device), | 721 on_boot_device_(on_boot_device), |
| 720 on_removable_device_(on_removable_device), | 722 on_removable_device_(on_removable_device), |
| 721 is_hidden_(is_hidden) {} | 723 is_hidden_(is_hidden) {} |
| 722 | 724 |
| 723 DiskMountManager::Disk::Disk(const Disk& other) = default; | 725 DiskMountManager::Disk::Disk(const Disk& other) = default; |
| 724 | 726 |
| 725 DiskMountManager::Disk::~Disk() {} | 727 DiskMountManager::Disk::~Disk() {} |
| 726 | 728 |
| 727 bool DiskMountManager::AddDiskForTest(std::unique_ptr<Disk> disk) { | 729 bool DiskMountManager::AddDiskForTest(std::unique_ptr<Disk> disk) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 VLOG(1) << "DiskMountManager Shutdown completed"; | 797 VLOG(1) << "DiskMountManager Shutdown completed"; |
| 796 } | 798 } |
| 797 | 799 |
| 798 // static | 800 // static |
| 799 DiskMountManager* DiskMountManager::GetInstance() { | 801 DiskMountManager* DiskMountManager::GetInstance() { |
| 800 return g_disk_mount_manager; | 802 return g_disk_mount_manager; |
| 801 } | 803 } |
| 802 | 804 |
| 803 } // namespace disks | 805 } // namespace disks |
| 804 } // namespace chromeos | 806 } // namespace chromeos |
| OLD | NEW |