blob: 0a39fe3d7430488dbf25bb1809b3485681041c91 [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
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]e4c5f97b2014-02-17 18:57:179#ifndef COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
10#define COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
[email protected]a4fec1a2013-04-03 04:43:3811
12#if defined(OS_CHROMEOS)
13#error "ChromeOS does not use MtabWatcherLinux."
14#endif
15
16#include <map>
17
[email protected]a4fec1a2013-04-03 04:43:3818#include "base/files/file_path.h"
19#include "base/files/file_path_watcher.h"
avi5dd91f82015-12-25 22:30:4620#include "base/macros.h"
[email protected]a4fec1a2013-04-03 04:43:3821#include "base/memory/weak_ptr.h"
avi5dd91f82015-12-25 22:30:4622#include "build/build_config.h"
[email protected]a4fec1a2013-04-03 04:43:3823
[email protected]7bfe94602014-02-25 10:22:3924namespace storage_monitor {
25
[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.
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]7bfe94602014-02-25 10:22:3965} // namespace storage_monitor
66
[email protected]e4c5f97b2014-02-17 18:57:1767#endif // COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_