1 // Copyright (c) 2013 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 CHROME_BROWSER_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
10 #define CHROME_BROWSER_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
12 #if defined(OS_CHROMEOS)
13 #error "ChromeOS does not use MtabWatcherLinux."
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"
25 class MtabWatcherLinux
{
27 // (mount point, mount device)
28 // A mapping from mount point to mount device, as extracted from the mtab
30 typedef std::map
<base::FilePath
, base::FilePath
> MountPointDeviceMap
;
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
);
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
);
66 #endif // CHROME_BROWSER_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_