blob: e69dfb0c4f608be12870549c1c1c22c872154b0a [file] [log] [blame]
hirono9f5eae542015-06-22 04:28:411// 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
avi6e1a22d2015-12-21 03:43:2011#include "base/macros.h"
hirono9f5eae542015-06-22 04:28:4112#include "chromeos/chromeos_export.h"
13#include "chromeos/dbus/cros_disks_client.h"
14#include "chromeos/dbus/power_manager_client.h"
15
16namespace chromeos {
17namespace disks {
18
19class DiskMountManager;
20
21// Class to unmount disks at suspend.
22class 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_