suspend_unmount_manager.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2015 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_SUSPEND_UNMOUNT_MANAGER_H_
  5. #define ASH_COMPONENTS_DISKS_SUSPEND_UNMOUNT_MANAGER_H_
  6. #include <set>
  7. #include <string>
  8. #include "base/component_export.h"
  9. #include "base/time/time.h"
  10. #include "base/unguessable_token.h"
  11. #include "chromeos/ash/components/dbus/cros_disks/cros_disks_client.h"
  12. #include "chromeos/dbus/power/power_manager_client.h"
  13. namespace ash {
  14. namespace disks {
  15. class DiskMountManager;
  16. // Class to unmount disks at suspend.
  17. class COMPONENT_EXPORT(ASH_DISKS) SuspendUnmountManager
  18. : public PowerManagerClient::Observer {
  19. public:
  20. // The ownership of these raw pointers still remains with the caller.
  21. explicit SuspendUnmountManager(DiskMountManager* disk_mount_manager);
  22. SuspendUnmountManager(const SuspendUnmountManager&) = delete;
  23. SuspendUnmountManager& operator=(const SuspendUnmountManager&) = delete;
  24. ~SuspendUnmountManager() override;
  25. private:
  26. void OnUnmountComplete(const std::string& mount_path, MountError error_code);
  27. // PowerManagerClient::Observer
  28. void SuspendImminent(power_manager::SuspendImminent::Reason reason) override;
  29. void SuspendDone(base::TimeDelta sleep_duration) override;
  30. // Callback passed to DiskMountManager holds weak pointers of this.
  31. DiskMountManager* const disk_mount_manager_;
  32. // The paths that the manager currently tries to unmount for suspend.
  33. std::set<std::string> unmounting_paths_;
  34. base::UnguessableToken block_suspend_token_;
  35. base::TimeTicks block_suspend_time_;
  36. base::WeakPtrFactory<SuspendUnmountManager> weak_ptr_factory_{this};
  37. };
  38. } // namespace disks
  39. } // namespace ash
  40. #endif // ASH_COMPONENTS_DISKS_SUSPEND_UNMOUNT_MANAGER_H_