[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 | |||||
5 | // MtabWatcherLinux listens for mount point changes from a mtab file and | ||||
6 | // notifies a StorageMonitorLinux about them. | ||||
7 | // MtabWatcherLinux lives on the FILE thread. | ||||
8 | |||||
[email protected] | e4c5f97b | 2014-02-17 18:57:17 | [diff] [blame] | 9 | #ifndef COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_ |
10 | #define COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_ | ||||
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 11 | |
12 | #if defined(OS_CHROMEOS) | ||||
13 | #error "ChromeOS does not use MtabWatcherLinux." | ||||
14 | #endif | ||||
15 | |||||
16 | #include <map> | ||||
17 | |||||
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 18 | #include "base/files/file_path.h" |
19 | #include "base/files/file_path_watcher.h" | ||||
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 20 | #include "base/macros.h" |
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 21 | #include "base/memory/weak_ptr.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 22 | #include "build/build_config.h" |
[email protected] | a4fec1a | 2013-04-03 04:43:38 | [diff] [blame] | 23 | |
[email protected] | 7bfe9460 | 2014-02-25 10:22:39 | [diff] [blame] | 24 | namespace storage_monitor { |
25 | |||||
[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. | ||||
31 | typedef std::map<base::FilePath, base::FilePath> MountPointDeviceMap; | ||||
32 | |||||
33 | class Delegate { | ||||
34 | public: | ||||
35 | virtual ~Delegate() {} | ||||
36 | |||||
37 | // Parses |new_mtab| and find all changes. Called on the UI thread. | ||||
38 | virtual void UpdateMtab(const MountPointDeviceMap& new_mtab) = 0; | ||||
39 | }; | ||||
40 | |||||
41 | MtabWatcherLinux(const base::FilePath& mtab_path, | ||||
42 | base::WeakPtr<Delegate> delegate); | ||||
43 | ~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 | |||||
58 | base::WeakPtr<Delegate> delegate_; | ||||
59 | |||||
60 | base::WeakPtrFactory<MtabWatcherLinux> weak_ptr_factory_; | ||||
61 | |||||
62 | DISALLOW_COPY_AND_ASSIGN(MtabWatcherLinux); | ||||
63 | }; | ||||
64 | |||||
[email protected] | 7bfe9460 | 2014-02-25 10:22:39 | [diff] [blame] | 65 | } // namespace storage_monitor |
66 | |||||
[email protected] | e4c5f97b | 2014-02-17 18:57:17 | [diff] [blame] | 67 | #endif // COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_ |