Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / file_manager / fake_disk_mount_manager.cc
blob585fbdf62c5e9374c3587e2d48001e408978a3fb
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),
20 type(type) {
23 FakeDiskMountManager::UnmountRequest::UnmountRequest(
24 const std::string& mount_path,
25 chromeos::UnmountOptions options)
26 : mount_path(mount_path),
27 options(options) {
30 FakeDiskMountManager::FakeDiskMountManager() {
33 FakeDiskMountManager::~FakeDiskMountManager() {
34 STLDeleteValues(&disks_);
37 void FakeDiskMountManager::AddObserver(Observer* observer) {
38 DCHECK(observer);
39 observers_.AddObserver(observer);
42 void FakeDiskMountManager::RemoveObserver(Observer* observer) {
43 DCHECK(observer);
44 observers_.RemoveObserver(observer);
47 const chromeos::disks::DiskMountManager::DiskMap&
48 FakeDiskMountManager::disks() const {
49 return disks_;
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())
57 return NULL;
58 return iter->second;
61 const chromeos::disks::DiskMountManager::MountPointMap&
62 FakeDiskMountManager::mount_points() const {
63 return mount_points_;
66 void FakeDiskMountManager::EnsureMountInfoRefreshed(
67 const EnsureMountInfoRefreshedCallback& callback) {
68 callback.Run(true);
71 void FakeDiskMountManager::MountPath(const std::string& source_path,
72 const std::string& source_format,
73 const std::string& mount_label,
74 chromeos::MountType type) {
75 mount_requests_.push_back(
76 MountRequest(source_path, source_format, mount_label, type));
78 const MountPointInfo mount_point(
79 source_path,
80 source_path,
81 type,
82 chromeos::disks::MOUNT_CONDITION_NONE);
83 mount_points_.insert(make_pair(source_path, mount_point));
84 FOR_EACH_OBSERVER(DiskMountManager::Observer, observers_,
85 OnMountEvent(DiskMountManager::MOUNTING,
86 chromeos::MOUNT_ERROR_NONE,
87 mount_point));
90 void FakeDiskMountManager::UnmountPath(const std::string& mount_path,
91 chromeos::UnmountOptions options,
92 const UnmountPathCallback& callback) {
93 unmount_requests_.push_back(UnmountRequest(mount_path, options));
95 MountPointMap::iterator iter = mount_points_.find(mount_path);
96 if (iter == mount_points_.end())
97 return;
98 const MountPointInfo mount_point = iter->second;
99 mount_points_.erase(iter);
100 FOR_EACH_OBSERVER(DiskMountManager::Observer, observers_,
101 OnMountEvent(DiskMountManager::UNMOUNTING,
102 chromeos::MOUNT_ERROR_NONE,
103 mount_point));
104 // Currently |callback| is just ignored.
107 void FakeDiskMountManager::FormatMountedDevice(const std::string& mount_path) {
110 void FakeDiskMountManager::UnmountDeviceRecursively(
111 const std::string& device_path,
112 const UnmountDeviceRecursivelyCallbackType& callback) {
115 bool FakeDiskMountManager::AddDiskForTest(Disk* disk) {
116 DCHECK(disk);
117 return disks_.insert(make_pair(disk->device_path(), disk)).second;
120 bool FakeDiskMountManager::AddMountPointForTest(
121 const MountPointInfo& mount_point) {
122 return false;
125 void FakeDiskMountManager::InvokeDiskEventForTest(
126 chromeos::disks::DiskMountManager::DiskEvent event,
127 const chromeos::disks::DiskMountManager::Disk* disk) {
128 FOR_EACH_OBSERVER(chromeos::disks::DiskMountManager::Observer,
129 observers_,
130 OnDiskEvent(event, disk));
133 } // namespace file_manager