Complete SyncMessageFilter initialization after SyncChannel initialization
[chromium-blink-merge.git] / components / storage_monitor / mtab_watcher_linux.h
blob206ed53c131dfae12facf3ac809c403ae50cd82a
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
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.
9 #ifndef COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
10 #define COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
12 #if defined(OS_CHROMEOS)
13 #error "ChromeOS does not use MtabWatcherLinux."
14 #endif
16 #include <map>
18 #include "base/basictypes.h"
19 #include "base/files/file_path.h"
20 #include "base/files/file_path_watcher.h"
21 #include "base/memory/weak_ptr.h"
23 namespace storage_monitor {
25 class MtabWatcherLinux {
26 public:
27 // (mount point, mount device)
28 // A mapping from mount point to mount device, as extracted from the mtab
29 // file.
30 typedef std::map<base::FilePath, base::FilePath> MountPointDeviceMap;
32 class Delegate {
33 public:
34 virtual ~Delegate() {}
36 // Parses |new_mtab| and find all changes. Called on the UI thread.
37 virtual void UpdateMtab(const MountPointDeviceMap& new_mtab) = 0;
40 MtabWatcherLinux(const base::FilePath& mtab_path,
41 base::WeakPtr<Delegate> delegate);
42 ~MtabWatcherLinux();
44 private:
45 // Reads mtab file entries into |mtab|.
46 void ReadMtab() const;
48 // Called when |mtab_path_| changes.
49 void OnFilePathChanged(const base::FilePath& path, bool error);
51 // Mtab file that lists the mount points.
52 const base::FilePath mtab_path_;
54 // Watcher for |mtab_path_|.
55 base::FilePathWatcher file_watcher_;
57 base::WeakPtr<Delegate> delegate_;
59 base::WeakPtrFactory<MtabWatcherLinux> weak_ptr_factory_;
61 DISALLOW_COPY_AND_ASSIGN(MtabWatcherLinux);
64 } // namespace storage_monitor
66 #endif // COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_