blob: 8c3bc936d43445b47b556f1b58201ece05bd1f9e [file] [log] [blame]
Ben Chan1e5a0cb2012-03-22 00:41:52 -07001// Copyright (c) 2012 The Chromium OS 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 CROS_DISKS_DEVICE_EJECTOR_H_
6#define CROS_DISKS_DEVICE_EJECTOR_H_
7
Ben Chan445852f2017-10-02 23:00:16 -07008#include <map>
Ben Chanbba00ef2017-01-05 13:26:04 -08009#include <memory>
Ben Chan1e5a0cb2012-03-22 00:41:52 -070010#include <string>
11
Simon Glass2b1da092020-05-21 12:24:16 -060012#include <brillo/process/process_reaper.h>
Ben Chan445852f2017-10-02 23:00:16 -070013
14#include "cros-disks/sandboxed_process.h"
Ben Chan1e5a0cb2012-03-22 00:41:52 -070015
16namespace cros_disks {
17
Ben Chan1e5a0cb2012-03-22 00:41:52 -070018// A class for ejecting any removable media on a device.
19class DeviceEjector {
20 public:
Ben Chan445852f2017-10-02 23:00:16 -070021 explicit DeviceEjector(brillo::ProcessReaper* process_reaper);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090022 DeviceEjector(const DeviceEjector&) = delete;
23 DeviceEjector& operator=(const DeviceEjector&) = delete;
24
Ben Chan1e5a0cb2012-03-22 00:41:52 -070025 virtual ~DeviceEjector();
26
27 // Ejects any removable media on a device at |device_path| using the
28 // 'eject' program. Returns true if the eject process has launched
29 // successfully (but may not complete until OnEjectProcessTerminated
30 // is called).
31 virtual bool Eject(const std::string& device_path);
32
33 private:
34 // Invoked when an eject process has terminated.
Ben Chan445852f2017-10-02 23:00:16 -070035 void OnEjectProcessTerminated(const std::string& device_path,
36 const siginfo_t& info);
Ben Chan1e5a0cb2012-03-22 00:41:52 -070037
Ben Chan445852f2017-10-02 23:00:16 -070038 brillo::ProcessReaper* process_reaper_;
39
40 // A list of outstanding eject processes indexed by device path.
41 std::map<std::string, SandboxedProcess> eject_process_;
42
43 base::WeakPtrFactory<DeviceEjector> weak_ptr_factory_;
Ben Chan1e5a0cb2012-03-22 00:41:52 -070044};
45
46} // namespace cros_disks
47
48#endif // CROS_DISKS_DEVICE_EJECTOR_H_