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.
5 #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h"
7 #include "base/callback.h"
8 #include "base/stl_util.h"
10 namespace file_manager
{
12 FakeDiskMountManager::MountRequest::MountRequest(
13 const std::string
& source_path
,
14 const std::string
& source_format
,
15 const std::string
& mount_label
,
16 chromeos::MountType type
)
17 : source_path(source_path
),
18 source_format(source_format
),
19 mount_label(mount_label
),
23 FakeDiskMountManager::UnmountRequest::UnmountRequest(
24 const std::string
& mount_path
,
25 chromeos::UnmountOptions options
)
26 : mount_path(mount_path
),
30 FakeDiskMountManager::FakeDiskMountManager() {
33 FakeDiskMountManager::~FakeDiskMountManager() {
34 STLDeleteValues(&disks_
);
37 void FakeDiskMountManager::AddObserver(Observer
* observer
) {
39 observers_
.AddObserver(observer
);
42 void FakeDiskMountManager::RemoveObserver(Observer
* observer
) {
44 observers_
.RemoveObserver(observer
);
47 const chromeos::disks::DiskMountManager::DiskMap
&
48 FakeDiskMountManager::disks() const {
52 const chromeos::disks::DiskMountManager::Disk
*
53 FakeDiskMountManager::FindDiskBySourcePath(
54 const std::string
& source_path
) const {
55 DiskMap::const_iterator iter
= disks_
.find(source_path
);
56 if (iter
== disks_
.end())
61 const chromeos::disks::DiskMountManager::MountPointMap
&
62 FakeDiskMountManager::mount_points() const {
66 void FakeDiskMountManager::EnsureMountInfoRefreshed(
67 const EnsureMountInfoRefreshedCallback
& callback
,
72 void FakeDiskMountManager::MountPath(const std::string
& source_path
,
73 const std::string
& source_format
,
74 const std::string
& mount_label
,
75 chromeos::MountType type
) {
76 mount_requests_
.push_back(
77 MountRequest(source_path
, source_format
, mount_label
, type
));
79 const MountPointInfo
mount_point(
83 chromeos::disks::MOUNT_CONDITION_NONE
);
84 mount_points_
.insert(make_pair(source_path
, mount_point
));
85 FOR_EACH_OBSERVER(DiskMountManager::Observer
, observers_
,
86 OnMountEvent(DiskMountManager::MOUNTING
,
87 chromeos::MOUNT_ERROR_NONE
,
91 void FakeDiskMountManager::UnmountPath(const std::string
& mount_path
,
92 chromeos::UnmountOptions options
,
93 const UnmountPathCallback
& callback
) {
94 unmount_requests_
.push_back(UnmountRequest(mount_path
, options
));
96 MountPointMap::iterator iter
= mount_points_
.find(mount_path
);
97 if (iter
== mount_points_
.end())
99 const MountPointInfo mount_point
= iter
->second
;
100 mount_points_
.erase(iter
);
101 FOR_EACH_OBSERVER(DiskMountManager::Observer
, observers_
,
102 OnMountEvent(DiskMountManager::UNMOUNTING
,
103 chromeos::MOUNT_ERROR_NONE
,
105 // Currently |callback| is just ignored.
108 void FakeDiskMountManager::FormatMountedDevice(const std::string
& mount_path
) {
111 void FakeDiskMountManager::UnmountDeviceRecursively(
112 const std::string
& device_path
,
113 const UnmountDeviceRecursivelyCallbackType
& callback
) {
116 bool FakeDiskMountManager::AddDiskForTest(Disk
* disk
) {
118 return disks_
.insert(make_pair(disk
->device_path(), disk
)).second
;
121 bool FakeDiskMountManager::AddMountPointForTest(
122 const MountPointInfo
& mount_point
) {
126 void FakeDiskMountManager::InvokeDiskEventForTest(
127 chromeos::disks::DiskMountManager::DiskEvent event
,
128 const chromeos::disks::DiskMountManager::Disk
* disk
) {
129 FOR_EACH_OBSERVER(chromeos::disks::DiskMountManager::Observer
,
131 OnDiskEvent(event
, disk
));
134 } // namespace file_manager