blob: 0f1fabe014c5f4564af36e373c89d40a6b995a80 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2014 The Chromium Authors
[email protected]a4fec1a2013-04-03 04:43:382// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e4c5f97b2014-02-17 18:57:175#ifndef COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
6#define COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
[email protected]a4fec1a2013-04-03 04:43:387
[email protected]a4fec1a2013-04-03 04:43:388#include <map>
9
[email protected]a4fec1a2013-04-03 04:43:3810#include "base/files/file_path.h"
11#include "base/files/file_path_watcher.h"
12#include "base/memory/weak_ptr.h"
Tommy C. Li5731fee2017-07-17 17:37:4913#include "base/sequence_checker.h"
avi5dd91f82015-12-25 22:30:4614#include "build/build_config.h"
[email protected]a4fec1a2013-04-03 04:43:3815
Maksim Sisov764f01d2024-12-18 08:34:4216#if BUILDFLAG(IS_CHROMEOS)
17#error "ChromeOS does not use MtabWatcherLinux."
18#endif
19
[email protected]7bfe94602014-02-25 10:22:3920namespace storage_monitor {
21
Tommy C. Li5731fee2017-07-17 17:37:4922// MtabWatcherLinux listens for mount point changes from a mtab file and
23// notifies a StorageMonitorLinux about them. This class should be created and
24// destroyed on a single sequence suitable for file IO.
[email protected]a4fec1a2013-04-03 04:43:3825class MtabWatcherLinux {
26 public:
27 // (mount point, mount device)
28 // A mapping from mount point to mount device, as extracted from the mtab
29 // file.
Tommy C. Li5731fee2017-07-17 17:37:4930 using MountPointDeviceMap = std::map<base::FilePath, base::FilePath>;
[email protected]a4fec1a2013-04-03 04:43:3831
Tommy C. Li5731fee2017-07-17 17:37:4932 using UpdateMtabCallback =
Ken Rockot51240d72019-12-18 03:16:1333 base::RepeatingCallback<void(const MountPointDeviceMap& new_mtab)>;
[email protected]a4fec1a2013-04-03 04:43:3834
Tommy C. Li5731fee2017-07-17 17:37:4935 // |callback| is called on the same sequence as the rest of the class.
36 // Caller is responsible for bouncing to the correct sequence.
[email protected]a4fec1a2013-04-03 04:43:3837 MtabWatcherLinux(const base::FilePath& mtab_path,
Tommy C. Li5731fee2017-07-17 17:37:4938 const UpdateMtabCallback& callback);
Peter Boström09c01822021-09-20 22:43:2739
40 MtabWatcherLinux(const MtabWatcherLinux&) = delete;
41 MtabWatcherLinux& operator=(const MtabWatcherLinux&) = delete;
42
[email protected]a4fec1a2013-04-03 04:43:3843 ~MtabWatcherLinux();
44
45 private:
46 // Reads mtab file entries into |mtab|.
47 void ReadMtab() const;
48
49 // Called when |mtab_path_| changes.
50 void OnFilePathChanged(const base::FilePath& path, bool error);
51
52 // Mtab file that lists the mount points.
53 const base::FilePath mtab_path_;
54
55 // Watcher for |mtab_path_|.
56 base::FilePathWatcher file_watcher_;
57
Tommy C. Li5731fee2017-07-17 17:37:4958 UpdateMtabCallback callback_;
59
60 SEQUENCE_CHECKER(sequence_checker_);
[email protected]a4fec1a2013-04-03 04:43:3861
Jeremy Roman5c341f6d2019-07-15 15:56:1062 base::WeakPtrFactory<MtabWatcherLinux> weak_ptr_factory_{this};
[email protected]a4fec1a2013-04-03 04:43:3863};
64
[email protected]7bfe94602014-02-25 10:22:3965} // namespace storage_monitor
66
[email protected]e4c5f97b2014-02-17 18:57:17