blob: 8e7792198707f36b75832cf037bd9d218502b8b5 [file] [log] [blame]
[email protected]e4c5f97b2014-02-17 18:57:171// Copyright 2014 The Chromium Authors. All rights reserved.
[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
8#if defined(OS_CHROMEOS)
9#error "ChromeOS does not use MtabWatcherLinux."
10#endif
11
12#include <map>
13
[email protected]a4fec1a2013-04-03 04:43:3814#include "base/files/file_path.h"
15#include "base/files/file_path_watcher.h"
avi5dd91f82015-12-25 22:30:4616#include "base/macros.h"
[email protected]a4fec1a2013-04-03 04:43:3817#include "base/memory/weak_ptr.h"
Tommy C. Li5731fee2017-07-17 17:37:4918#include "base/sequence_checker.h"
avi5dd91f82015-12-25 22:30:4619#include "build/build_config.h"
[email protected]a4fec1a2013-04-03 04:43:3820
[email protected]7bfe94602014-02-25 10:22:3921namespace storage_monitor {
22
Tommy C. Li5731fee2017-07-17 17:37:4923// MtabWatcherLinux listens for mount point changes from a mtab file and
24// notifies a StorageMonitorLinux about them. This class should be created and
25// destroyed on a single sequence suitable for file IO.
[email protected]a4fec1a2013-04-03 04:43:3826class MtabWatcherLinux {
27 public:
28 // (mount point, mount device)
29 // A mapping from mount point to mount device, as extracted from the mtab
30 // file.
Tommy C. Li5731fee2017-07-17 17:37:4931 using MountPointDeviceMap = std::map<base::FilePath, base::FilePath>;
[email protected]a4fec1a2013-04-03 04:43:3832
Tommy C. Li5731fee2017-07-17 17:37:4933 using UpdateMtabCallback =
34 base::Callback<void(const MountPointDeviceMap& new_mtab)>;
[email protected]a4fec1a2013-04-03 04:43:3835
Tommy C. Li5731fee2017-07-17 17:37:4936 // |callback| is called on the same sequence as the rest of the class.
37 // Caller is responsible for bouncing to the correct sequence.
[email protected]a4fec1a2013-04-03 04:43:3838 MtabWatcherLinux(const base::FilePath& mtab_path,
Tommy C. Li5731fee2017-07-17 17:37:4939 const UpdateMtabCallback& callback);
[email protected]a4fec1a2013-04-03 04:43:3840 ~MtabWatcherLinux();
41
42 private:
43 // Reads mtab file entries into |mtab|.
44 void ReadMtab() const;
45
46 // Called when |mtab_path_| changes.
47 void OnFilePathChanged(const base::FilePath& path, bool error);
48
49 // Mtab file that lists the mount points.
50 const base::FilePath mtab_path_;
51
52 // Watcher for |mtab_path_|.
53 base::FilePathWatcher file_watcher_;
54
Tommy C. Li5731fee2017-07-17 17:37:4955 UpdateMtabCallback callback_;
56
57 SEQUENCE_CHECKER(sequence_checker_);
[email protected]a4fec1a2013-04-03 04:43:3858
59 base::WeakPtrFactory<MtabWatcherLinux> weak_ptr_factory_;
60
61 DISALLOW_COPY_AND_ASSIGN(MtabWatcherLinux);
62};
63
[email protected]7bfe94602014-02-25 10:22:3964} // namespace storage_monitor
65
[email protected]e4c5f97b2014-02-17 18:57:1766#endif // COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_