hirono | 9f5eae54 | 2015-06-22 04:28:41 | [diff] [blame] | 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 | |
| 5 | #ifndef CHROMEOS_DISKS_SUSPEND_UNMOUNT_MANAGER_H_ |
| 6 | #define CHROMEOS_DISKS_SUSPEND_UNMOUNT_MANAGER_H_ |
| 7 | |
| 8 | #include <set> |
| 9 | #include <string> |
| 10 | |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 11 | #include "base/macros.h" |
hirono | 9f5eae54 | 2015-06-22 04:28:41 | [diff] [blame] | 12 | #include "chromeos/chromeos_export.h" |
| 13 | #include "chromeos/dbus/cros_disks_client.h" |
| 14 | #include "chromeos/dbus/power_manager_client.h" |
| 15 | |
| 16 | namespace chromeos { |
| 17 | namespace disks { |
| 18 | |
| 19 | class DiskMountManager; |
| 20 | |
| 21 | // Class to unmount disks at suspend. |
| 22 | class CHROMEOS_EXPORT SuspendUnmountManager |
| 23 | : public PowerManagerClient::Observer { |
| 24 | public: |
| 25 | // The ownership of these raw pointers still remains with the caller. |
| 26 | SuspendUnmountManager(DiskMountManager* disk_mount_manager, |
| 27 | PowerManagerClient* power_manager_client); |
| 28 | ~SuspendUnmountManager() override; |
| 29 | |
| 30 | private: |
| 31 | void OnUnmountComplete(const std::string& mount_path, |
| 32 | chromeos::MountError error_code); |
| 33 | |
| 34 | // PowerManagerClient::Observer |
| 35 | void SuspendImminent() override; |
| 36 | void SuspendDone(const base::TimeDelta& sleep_duration) override; |
| 37 | |
| 38 | // Callback passed to DiskMountManager holds weak pointers of this. |
| 39 | DiskMountManager* const disk_mount_manager_; |
| 40 | PowerManagerClient* const power_manager_client_; |
| 41 | |
| 42 | // The paths that the manager currently tries to unmount for suspend. |
| 43 | std::set<std::string> unmounting_paths_; |
| 44 | |
| 45 | base::Closure suspend_readiness_callback_; |
| 46 | |
| 47 | base::WeakPtrFactory<SuspendUnmountManager> weak_ptr_factory_; |
| 48 | |
| 49 | DISALLOW_COPY_AND_ASSIGN(SuspendUnmountManager); |
| 50 | }; |
| 51 | |
| 52 | } // namespace disks |
| 53 | } // namespace chromeos |
| 54 | |
| 55 | #endif // CHROMEOS_DISKS_SUSPEND_UNMOUNT_MANAGER_H_ |