1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h" 6 7 #include "base/stl_util.h" 8 9 namespace file_manager { 10 11 FakeDiskMountManager::MountRequest::MountRequest( 12 const std::string& source_path, 13 const std::string& source_format, 14 const std::string& mount_label, 15 chromeos::MountType type) 16 : source_path(source_path), 17 source_format(source_format), 18 mount_label(mount_label), 19 type(type) { 20 } 21 22 FakeDiskMountManager::UnmountRequest::UnmountRequest( 23 const std::string& mount_path, 24 chromeos::UnmountOptions options) 25 : mount_path(mount_path), 26 options(options) { 27 } 28 29 FakeDiskMountManager::FakeDiskMountManager() { 30 } 31 32 FakeDiskMountManager::~FakeDiskMountManager() { 33 STLDeleteValues(&disks_); 34 } 35 36 void FakeDiskMountManager::AddObserver(Observer* observer) { 37 DCHECK(observer); 38 observers_.AddObserver(observer); 39 } 40 41 void FakeDiskMountManager::RemoveObserver(Observer* observer) { 42 DCHECK(observer); 43 observers_.RemoveObserver(observer); 44 } 45 46 const chromeos::disks::DiskMountManager::DiskMap& 47 FakeDiskMountManager::disks() const { 48 return disks_; 49 } 50 51 const chromeos::disks::DiskMountManager::Disk* 52 FakeDiskMountManager::FindDiskBySourcePath( 53 const std::string& source_path) const { 54 DiskMap::const_iterator iter = disks_.find(source_path); 55 if (iter == disks_.end()) 56 return NULL; 57 return iter->second; 58 } 59 60 const chromeos::disks::DiskMountManager::MountPointMap& 61 FakeDiskMountManager::mount_points() const { 62 return mount_points_; 63 } 64 65 void FakeDiskMountManager::RequestMountInfoRefresh() { 66 } 67 68 void FakeDiskMountManager::MountPath(const std::string& source_path, 69 const std::string& source_format, 70 const std::string& mount_label, 71 chromeos::MountType type) { 72 mount_requests_.push_back( 73 MountRequest(source_path, source_format, mount_label, type)); 74 75 const MountPointInfo mount_point( 76 source_path, 77 source_path, 78 type, 79 chromeos::disks::MOUNT_CONDITION_NONE); 80 mount_points_.insert(make_pair(source_path, mount_point)); 81 FOR_EACH_OBSERVER(DiskMountManager::Observer, observers_, 82 OnMountEvent(DiskMountManager::MOUNTING, 83 chromeos::MOUNT_ERROR_NONE, 84 mount_point)); 85 } 86 87 void FakeDiskMountManager::UnmountPath(const std::string& mount_path, 88 chromeos::UnmountOptions options, 89 const UnmountPathCallback& callback) { 90 unmount_requests_.push_back(UnmountRequest(mount_path, options)); 91 92 MountPointMap::iterator iter = mount_points_.find(mount_path); 93 if (iter == mount_points_.end()) 94 return; 95 const MountPointInfo mount_point = iter->second; 96 mount_points_.erase(iter); 97 FOR_EACH_OBSERVER(DiskMountManager::Observer, observers_, 98 OnMountEvent(DiskMountManager::UNMOUNTING, 99 chromeos::MOUNT_ERROR_NONE, 100 mount_point)); 101 // Currently |callback| is just ignored. 102 } 103 104 void FakeDiskMountManager::FormatMountedDevice(const std::string& mount_path) { 105 } 106 107 void FakeDiskMountManager::UnmountDeviceRecursively( 108 const std::string& device_path, 109 const UnmountDeviceRecursivelyCallbackType& callback) { 110 } 111 112 bool FakeDiskMountManager::AddDiskForTest(Disk* disk) { 113 DCHECK(disk); 114 return disks_.insert(make_pair(disk->device_path(), disk)).second; 115 } 116 117 bool FakeDiskMountManager::AddMountPointForTest( 118 const MountPointInfo& mount_point) { 119 return false; 120 } 121 122 } // namespace file_manager 123