Storage Monitor: Migrate to using TaskScheduler
Removes content::BrowserThread::FILE usage in favor of TaskScheduler
interfaces.
Bug: 689520
Change-Id: Icd77c188320f57e4b8a1810c55bb6172d3093ae1
Reviewed-on: https://chromium-review.googlesource.com/567418
Reviewed-by: Lei Zhang <[email protected]>
Commit-Queue: Tommy Li <[email protected]>
Cr-Commit-Position: refs/heads/master@{#487141}
diff --git a/components/storage_monitor/mtab_watcher_linux.h b/components/storage_monitor/mtab_watcher_linux.h
index 0a39fe3..8e77921 100644
--- a/components/storage_monitor/mtab_watcher_linux.h
+++ b/components/storage_monitor/mtab_watcher_linux.h
@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// MtabWatcherLinux listens for mount point changes from a mtab file and
-// notifies a StorageMonitorLinux about them.
-// MtabWatcherLinux lives on the FILE thread.
-
#ifndef COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
#define COMPONENTS_STORAGE_MONITOR_MTAB_WATCHER_LINUX_H_
@@ -19,27 +15,28 @@
#include "base/files/file_path_watcher.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "base/sequence_checker.h"
#include "build/build_config.h"
namespace storage_monitor {
+// MtabWatcherLinux listens for mount point changes from a mtab file and
+// notifies a StorageMonitorLinux about them. This class should be created and
+// destroyed on a single sequence suitable for file IO.
class MtabWatcherLinux {
public:
// (mount point, mount device)
// A mapping from mount point to mount device, as extracted from the mtab
// file.
- typedef std::map<base::FilePath, base::FilePath> MountPointDeviceMap;
+ using MountPointDeviceMap = std::map<base::FilePath, base::FilePath>;
- class Delegate {
- public:
- virtual ~Delegate() {}
+ using UpdateMtabCallback =
+ base::Callback<void(const MountPointDeviceMap& new_mtab)>;
- // Parses |new_mtab| and find all changes. Called on the UI thread.
- virtual void UpdateMtab(const MountPointDeviceMap& new_mtab) = 0;
- };
-
+ // |callback| is called on the same sequence as the rest of the class.
+ // Caller is responsible for bouncing to the correct sequence.
MtabWatcherLinux(const base::FilePath& mtab_path,
- base::WeakPtr<Delegate> delegate);
+ const UpdateMtabCallback& callback);
~MtabWatcherLinux();
private:
@@ -55,7 +52,9 @@
// Watcher for |mtab_path_|.
base::FilePathWatcher file_watcher_;
- base::WeakPtr<Delegate> delegate_;
+ UpdateMtabCallback callback_;
+
+ SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<MtabWatcherLinux> weak_ptr_factory_;