blob: 2b332b9127650938b7953d5bce771aacad122ca0 [file] [log] [blame]
Klemen Kozjekb0658852017-08-15 13:03:48 +09001// Copyright 2017 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_RENAME_MANAGER_H_
6#define CROS_DISKS_RENAME_MANAGER_H_
7
8#include <map>
9#include <string>
10
Ben Chan445852f2017-10-02 23:00:16 -070011#include <base/memory/weak_ptr.h>
Simon Glass2b1da092020-05-21 12:24:16 -060012#include <brillo/process/process_reaper.h>
Klemen Kozjekb0658852017-08-15 13:03:48 +090013#include <chromeos/dbus/service_constants.h>
14#include <gtest/gtest_prod.h>
15
16#include "cros-disks/sandboxed_process.h"
17
Klemen Kozjekb0658852017-08-15 13:03:48 +090018namespace cros_disks {
19
20class Platform;
21class RenameManagerObserverInterface;
22
23class RenameManager {
24 public:
Ben Chan445852f2017-10-02 23:00:16 -070025 RenameManager(Platform* platform, brillo::ProcessReaper* process_reaper);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090026 RenameManager(const RenameManager&) = delete;
27 RenameManager& operator=(const RenameManager&) = delete;
28
Klemen Kozjekb0658852017-08-15 13:03:48 +090029 ~RenameManager();
30
31 // Starts a renaming process of a given device.
32 RenameErrorType StartRenaming(const std::string& device_path,
33 const std::string& device_file,
34 const std::string& volume_name,
35 const std::string& filesystem_type);
36
Klemen Kozjekb0658852017-08-15 13:03:48 +090037 void set_observer(RenameManagerObserverInterface* observer) {
38 observer_ = observer;
39 }
40
41 private:
42 FRIEND_TEST(RenameManagerTest, CanRename);
Klemen Kozjekb0658852017-08-15 13:03:48 +090043
Ben Chan445852f2017-10-02 23:00:16 -070044 void OnRenameProcessTerminated(const std::string& device_path,
45 const siginfo_t& info);
Klemen Kozjekb0658852017-08-15 13:03:48 +090046
Klemen Kozjekb0658852017-08-15 13:03:48 +090047 // Returns true if renaming |source_path| is supported.
48 bool CanRename(const std::string& source_path) const;
49
Ben Chan445852f2017-10-02 23:00:16 -070050 // Platform service
51 Platform* platform_;
52
53 brillo::ProcessReaper* process_reaper_;
54
Klemen Kozjekb0658852017-08-15 13:03:48 +090055 // A list of outstanding renaming processes indexed by device path.
56 std::map<std::string, SandboxedProcess> rename_process_;
57
Klemen Kozjekb0658852017-08-15 13:03:48 +090058 RenameManagerObserverInterface* observer_;
59
Ben Chan445852f2017-10-02 23:00:16 -070060 base::WeakPtrFactory<RenameManager> weak_ptr_factory_;
Klemen Kozjekb0658852017-08-15 13:03:48 +090061};
62
63} // namespace cros_disks
64
65#endif // CROS_DISKS_RENAME_MANAGER_H_