| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h" | 5 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | |
| 8 | |
| 9 namespace file_manager { | 7 namespace file_manager { |
| 10 | 8 |
| 11 FakeDiskMountManager::MountRequest::MountRequest( | 9 FakeDiskMountManager::MountRequest::MountRequest( |
| 12 const std::string& source_path, | 10 const std::string& source_path, |
| 13 const std::string& source_format, | 11 const std::string& source_format, |
| 14 const std::string& mount_label, | 12 const std::string& mount_label, |
| 15 chromeos::MountType type, | 13 chromeos::MountType type, |
| 16 chromeos::MountAccessMode access_mode) | 14 chromeos::MountAccessMode access_mode) |
| 17 : source_path(source_path), | 15 : source_path(source_path), |
| 18 source_format(source_format), | 16 source_format(source_format), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 48 | 46 |
| 49 const chromeos::disks::DiskMountManager::DiskMap& | 47 const chromeos::disks::DiskMountManager::DiskMap& |
| 50 FakeDiskMountManager::disks() const { | 48 FakeDiskMountManager::disks() const { |
| 51 return disks_; | 49 return disks_; |
| 52 } | 50 } |
| 53 | 51 |
| 54 const chromeos::disks::DiskMountManager::Disk* | 52 const chromeos::disks::DiskMountManager::Disk* |
| 55 FakeDiskMountManager::FindDiskBySourcePath( | 53 FakeDiskMountManager::FindDiskBySourcePath( |
| 56 const std::string& source_path) const { | 54 const std::string& source_path) const { |
| 57 DiskMap::const_iterator iter = disks_.find(source_path); | 55 DiskMap::const_iterator iter = disks_.find(source_path); |
| 58 if (iter == disks_.end()) | 56 return iter != disks_.end() ? iter->second.get() : nullptr; |
| 59 return nullptr; | |
| 60 return iter->second.get(); | |
| 61 } | 57 } |
| 62 | 58 |
| 63 const chromeos::disks::DiskMountManager::MountPointMap& | 59 const chromeos::disks::DiskMountManager::MountPointMap& |
| 64 FakeDiskMountManager::mount_points() const { | 60 FakeDiskMountManager::mount_points() const { |
| 65 return mount_points_; | 61 return mount_points_; |
| 66 } | 62 } |
| 67 | 63 |
| 68 void FakeDiskMountManager::EnsureMountInfoRefreshed( | 64 void FakeDiskMountManager::EnsureMountInfoRefreshed( |
| 69 const EnsureMountInfoRefreshedCallback& callback, | 65 const EnsureMountInfoRefreshedCallback& callback, |
| 70 bool force) { | 66 bool force) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 } | 88 } |
| 93 | 89 |
| 94 void FakeDiskMountManager::UnmountPath(const std::string& mount_path, | 90 void FakeDiskMountManager::UnmountPath(const std::string& mount_path, |
| 95 chromeos::UnmountOptions options, | 91 chromeos::UnmountOptions options, |
| 96 const UnmountPathCallback& callback) { | 92 const UnmountPathCallback& callback) { |
| 97 unmount_requests_.push_back(UnmountRequest(mount_path, options)); | 93 unmount_requests_.push_back(UnmountRequest(mount_path, options)); |
| 98 | 94 |
| 99 MountPointMap::iterator iter = mount_points_.find(mount_path); | 95 MountPointMap::iterator iter = mount_points_.find(mount_path); |
| 100 if (iter == mount_points_.end()) | 96 if (iter == mount_points_.end()) |
| 101 return; | 97 return; |
| 98 |
| 102 const MountPointInfo mount_point = iter->second; | 99 const MountPointInfo mount_point = iter->second; |
| 103 mount_points_.erase(iter); | 100 mount_points_.erase(iter); |
| 104 FOR_EACH_OBSERVER(DiskMountManager::Observer, observers_, | 101 FOR_EACH_OBSERVER(DiskMountManager::Observer, observers_, |
| 105 OnMountEvent(DiskMountManager::UNMOUNTING, | 102 OnMountEvent(DiskMountManager::UNMOUNTING, |
| 106 chromeos::MOUNT_ERROR_NONE, | 103 chromeos::MOUNT_ERROR_NONE, |
| 107 mount_point)); | 104 mount_point)); |
| 105 |
| 108 // Enqueue callback so that |FakeDiskMountManager::FinishAllUnmountRequest()| | 106 // Enqueue callback so that |FakeDiskMountManager::FinishAllUnmountRequest()| |
| 109 // can call them. | 107 // can call them. |
| 110 pending_unmount_callbacks_.push(callback); | 108 pending_unmount_callbacks_.push(callback); |
| 111 } | 109 } |
| 112 | 110 |
| 113 bool FakeDiskMountManager::FinishAllUnmountPathRequests() { | 111 bool FakeDiskMountManager::FinishAllUnmountPathRequests() { |
| 114 if (pending_unmount_callbacks_.empty()) | 112 if (pending_unmount_callbacks_.empty()) |
| 115 return false; | 113 return false; |
| 114 |
| 116 while (!pending_unmount_callbacks_.empty()) { | 115 while (!pending_unmount_callbacks_.empty()) { |
| 117 pending_unmount_callbacks_.front().Run(chromeos::MOUNT_ERROR_NONE); | 116 pending_unmount_callbacks_.front().Run(chromeos::MOUNT_ERROR_NONE); |
| 118 pending_unmount_callbacks_.pop(); | 117 pending_unmount_callbacks_.pop(); |
| 119 } | 118 } |
| 120 return true; | 119 return true; |
| 121 } | 120 } |
| 122 | 121 |
| 123 void FakeDiskMountManager::FormatMountedDevice(const std::string& mount_path) { | 122 void FakeDiskMountManager::FormatMountedDevice(const std::string& mount_path) { |
| 124 } | 123 } |
| 125 | 124 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 140 | 139 |
| 141 void FakeDiskMountManager::InvokeDiskEventForTest( | 140 void FakeDiskMountManager::InvokeDiskEventForTest( |
| 142 chromeos::disks::DiskMountManager::DiskEvent event, | 141 chromeos::disks::DiskMountManager::DiskEvent event, |
| 143 const chromeos::disks::DiskMountManager::Disk* disk) { | 142 const chromeos::disks::DiskMountManager::Disk* disk) { |
| 144 FOR_EACH_OBSERVER(chromeos::disks::DiskMountManager::Observer, | 143 FOR_EACH_OBSERVER(chromeos::disks::DiskMountManager::Observer, |
| 145 observers_, | 144 observers_, |
| 146 OnDiskEvent(event, disk)); | 145 OnDiskEvent(event, disk)); |
| 147 } | 146 } |
| 148 | 147 |
| 149 } // namespace file_manager | 148 } // namespace file_manager |
| OLD | NEW |