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