File: fake_disk_mount_manager.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (133 lines) | stat: -rw-r--r-- 5,136 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_DISKS_FAKE_DISK_MOUNT_MANAGER_H_
#define CHROMEOS_ASH_COMPONENTS_DISKS_FAKE_DISK_MOUNT_MANAGER_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "base/containers/queue.h"
#include "base/functional/callback.h"
#include "base/observer_list.h"
#include "chromeos/ash/components/dbus/cros_disks/cros_disks_client.h"
#include "chromeos/ash/components/disks/disk_mount_manager.h"

namespace ash::disks {

class FakeDiskMountManager : public DiskMountManager {
 public:
  struct MountRequest {
    MountRequest(const std::string& source_path,
                 const std::string& source_format,
                 const std::string& mount_label,
                 const std::vector<std::string>& mount_options,
                 MountType type,
                 MountAccessMode access_mode);
    MountRequest(const MountRequest& other);
    ~MountRequest();

    std::string source_path;
    std::string source_format;
    std::string mount_label;
    std::vector<std::string> mount_options;
    MountType type;
    MountAccessMode access_mode;
  };

  struct RemountRequest {
    RemountRequest(std::string device_path, MountAccessMode access_mode);
    friend bool operator==(const RemountRequest&,
                           const RemountRequest&) = default;
    std::string device_path;
    MountAccessMode access_mode;
  };

  FakeDiskMountManager();

  FakeDiskMountManager(const FakeDiskMountManager&) = delete;
  FakeDiskMountManager& operator=(const FakeDiskMountManager&) = delete;

  ~FakeDiskMountManager() override;

  const std::vector<MountRequest>& mount_requests() const {
    return mount_requests_;
  }
  const std::vector<std::string>& unmount_requests() const {
    return unmount_requests_;
  }
  const std::vector<RemountRequest>& remount_requests() const {
    return remount_requests_;
  }

  // Emulates that all mount request finished.
  // Return true if there was one or more mount request enqueued, or false
  // otherwise.
  bool FinishAllUnmountPathRequests();

  // Fails a future unmount request for |mount_path| with |error_code|.
  void FailUnmountRequest(const std::string& mount_path, MountError error_code);

  // DiskMountManager overrides.
  void AddObserver(Observer* observer) override;
  void RemoveObserver(Observer* observer) override;
  const Disks& disks() const override;
  const Disk* FindDiskBySourcePath(std::string_view source_path) const override;
  const MountPoints& mount_points() const override;
  void EnsureMountInfoRefreshed(EnsureMountInfoRefreshedCallback callback,
                                bool force) override;
  void MountPath(const std::string& source_path,
                 const std::string& source_format,
                 const std::string& mount_label,
                 const std::vector<std::string>& mount_options,
                 MountType type,
                 MountAccessMode access_mode,
                 MountPathCallback) override;
  // In order to simulate asynchronous invocation of callbacks after unmount
  // is finished, |callback| will be invoked only when
  // |FinishAllUnmountRequest()| is called.
  void UnmountPath(const std::string& mount_path,
                   UnmountPathCallback callback) override;
  void RemountRemovableDrive(const Disk& disk,
                             MountAccessMode access_mode) override;
  void FormatMountedDevice(const std::string& mount_path,
                           FormatFileSystemType filesystem,
                           const std::string& label) override;
  void SinglePartitionFormatDevice(const std::string& device_path,
                                   FormatFileSystemType filesystem,
                                   const std::string& label) override;
  void RenameMountedDevice(const std::string& mount_path,
                           const std::string& volume_name) override;
  void UnmountDeviceRecursively(
      const std::string& device_path,
      UnmountDeviceRecursivelyCallbackType callback) override;

  bool AddDiskForTest(std::unique_ptr<Disk> disk) override;
  bool AddMountPointForTest(const MountPoint& mount_point) override;
  void InvokeDiskEventForTest(DiskEvent event, const Disk* disk);

  void RegisterMountPointForNetworkStorageScheme(const std::string& scheme,
                                                 const std::string& mount_path);

 private:
  base::ObserverList<Observer> observers_;
  base::queue<base::OnceClosure> pending_unmount_callbacks_;

  Disks disks_;
  MountPoints mount_points_;

  std::vector<MountRequest> mount_requests_;
  std::vector<std::string> unmount_requests_;
  std::vector<RemountRequest> remount_requests_;
  std::map<std::string, MountError> unmount_errors_;
  // Maps a network storage URL scheme to a registered mount point path for that
  // scheme.
  std::map<std::string, std::string> network_storage_mount_paths_;
};

}  // namespace ash::disks

#endif  // CHROMEOS_ASH_COMPONENTS_DISKS_FAKE_DISK_MOUNT_MANAGER_H_