[email protected] | e4c5f97b | 2014-02-17 18:57:17 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | e4c5f97b | 2014-02-17 18:57:17 | [diff] [blame] | 5 | #ifndef COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_ |
6 | #define COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_ | ||||
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 7 | |
8 | #if defined(OS_CHROMEOS) | ||||
9 | #error "ChromeOS does not use MtabWatcherLinux." | ||||
10 | #endif | ||||
11 | |||||
12 | #include <map> | ||||
13 | |||||
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
15 | #include "base/files/file_path_watcher.h" | ||||
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 17 | #include "base/memory/weak_ptr.h" |
Tommy C. Li | 5731fee | 2017-07-17 17:37:49 | [diff] [blame^] | 18 | #include "base/sequence_checker.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 19 | #include "build/build_config.h" |
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 20 | |
[email protected] | 7bfe9460 | 2014-02-25 10:22:39 | [diff] [blame] | 21 | namespace storage_monitor { |
22 | |||||
Tommy C. Li | 5731fee | 2017-07-17 17:37:49 | [diff] [blame^] | 23 | // 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] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 26 | class 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. Li | 5731fee | 2017-07-17 17:37:49 | [diff] [blame^] | 31 | using MountPointDeviceMap = std::map<base::FilePath, base::FilePath>; |
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 32 | |
Tommy C. Li | 5731fee | 2017-07-17 17:37:49 | [diff] [blame^] | 33 | using UpdateMtabCallback = |
34 | base::Callback<void(const MountPointDeviceMap& new_mtab)>; | ||||
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 35 | |
Tommy C. Li | 5731fee | 2017-07-17 17:37:49 | [diff] [blame^] | 36 | // |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] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 38 | MtabWatcherLinux(const base::FilePath& mtab_path, |
Tommy C. Li | 5731fee | 2017-07-17 17:37:49 | [diff] [blame^] | 39 | const UpdateMtabCallback& callback); |
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 40 | ~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. Li | 5731fee | 2017-07-17 17:37:49 | [diff] [blame^] | 55 | UpdateMtabCallback callback_; |
56 | |||||
57 | SEQUENCE_CHECKER(sequence_checker_); | ||||
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 58 | |
59 | base::WeakPtrFactory<MtabWatcherLinux> weak_ptr_factory_; | ||||
60 | |||||
61 | DISALLOW_COPY_AND_ASSIGN(MtabWatcherLinux); | ||||
62 | }; | ||||
63 | |||||
[email protected] | 7bfe9460 | 2014-02-25 10:22:39 | [diff] [blame] | 64 | } // namespace storage_monitor |
65 | |||||
[email protected] | e4c5f97b | 2014-02-17 18:57:17 | [diff] [blame] | 66 | #endif // COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_ |