mount_point.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2019 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. #ifndef ASH_COMPONENTS_DISKS_MOUNT_POINT_H_
  5. #define ASH_COMPONENTS_DISKS_MOUNT_POINT_H_
  6. #include <memory>
  7. #include "ash/components/disks/disk_mount_manager.h"
  8. #include "base/callback.h"
  9. #include "base/component_export.h"
  10. #include "base/files/file_path.h"
  11. #include "base/memory/weak_ptr.h"
  12. namespace ash {
  13. namespace disks {
  14. class DiskMountManager;
  15. // MountPoint is a thin wrapper around a mount point that was mounted with
  16. // DiskMountManager. MountPoint 'owns' the mount point and unmounts it on
  17. // destruction.
  18. class COMPONENT_EXPORT(ASH_DISKS) MountPoint {
  19. public:
  20. using DoneCallback =
  21. base::OnceCallback<void(MountError, std::unique_ptr<MountPoint>)>;
  22. using UnmountCallback = DiskMountManager::UnmountPathCallback;
  23. // Mounts a device, archive, or network filesystem, and runs |callback| when
  24. // done. |callback| will never be called inline. |callback| should be bound
  25. // with a WeakPtr<> since Mount() can take an indefinite amount of time.
  26. // See DiskMountManager::MountPath() for other argument details.
  27. static void Mount(DiskMountManager* disk_mount_manager,
  28. const std::string& source_path,
  29. const std::string& source_format,
  30. const std::string& mount_label,
  31. const std::vector<std::string>& mount_options,
  32. MountType mount_type,
  33. MountAccessMode access_mode,
  34. DoneCallback callback);
  35. MountPoint() = delete;
  36. MountPoint(const MountPoint&) = delete;
  37. MountPoint& operator=(const MountPoint&) = delete;
  38. MountPoint(const base::FilePath& mount_path,
  39. DiskMountManager* disk_mount_manager);
  40. ~MountPoint();
  41. // Unmounts the mount point, and runs |callback| when done. |callback| must be
  42. // non-null, and will not be run if |this| is destroyed before the unmount has
  43. // completed.
  44. void Unmount(UnmountCallback callback);
  45. const base::FilePath& mount_path() const { return mount_path_; }
  46. private:
  47. // Callback for DiskMountManager::UnmountPath().
  48. void OnUmountDone(UnmountCallback callback, MountError unmount_error);
  49. base::FilePath mount_path_;
  50. DiskMountManager* const disk_mount_manager_;
  51. base::WeakPtrFactory<MountPoint> weak_factory_{this};
  52. };
  53. } // namespace disks
  54. } // namespace ash
  55. #endif // ASH_COMPONENTS_DISKS_MOUNT_POINT_H_