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"
23 class MtabWatcherLinux
{
25 // (mount point, mount device)
26 // A mapping from mount point to mount device, as extracted from the mtab
28 typedef std::map
<base::FilePath
, base::FilePath
> MountPointDeviceMap
;
32 virtual ~Delegate() {}
34 // Parses |new_mtab| and find all changes. Called on the UI thread.
35 virtual void UpdateMtab(const MountPointDeviceMap
& new_mtab
) = 0;
38 MtabWatcherLinux(const base::FilePath
& mtab_path
,
39 base::WeakPtr
<Delegate
> delegate
);
43 // Reads mtab file entries into |mtab|.
44 void ReadMtab() const;
46 // Called when |mtab_path_| changes.
47 void OnFilePathChanged(const base::FilePath
& path
, bool error
);
49 // Mtab file that lists the mount points.
50 const base::FilePath mtab_path_
;
52 // Watcher for |mtab_path_|.
53 base::FilePathWatcher file_watcher_
;
55 base::WeakPtr
<Delegate
> delegate_
;
57 base::WeakPtrFactory
<MtabWatcherLinux
> weak_ptr_factory_
;
59 DISALLOW_COPY_AND_ASSIGN(MtabWatcherLinux
);
62 #endif // CHROME_BROWSER_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_