Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1811)

Unified Diff: chrome/browser/chromeos/base/file_flusher.h

Issue 1815853002: cros: Flush profile files at critical moments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nits and create test files to fix trybots Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/base/file_flusher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/base/file_flusher.h
diff --git a/chrome/browser/chromeos/base/file_flusher.h b/chrome/browser/chromeos/base/file_flusher.h
new file mode 100644
index 0000000000000000000000000000000000000000..d33f9836b543f0352c3f2df9eef0a8437ba0a718
--- /dev/null
+++ b/chrome/browser/chromeos/base/file_flusher.h
@@ -0,0 +1,64 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_
+#define CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_
+
+#include <vector>
+
+#include "base/callback.h"
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+
+namespace chromeos {
+
+// Flushes files under the requested directories in the blocking pool. If the
+// same directory is requested more than once, the last request cancels all
+// previous ones and start a new flushing process.
+class FileFlusher {
+ public:
+ FileFlusher();
+ ~FileFlusher();
+
+ // Flush everything under |path| except the directories/files in |excludes|.
+ // |excluedes| can hold both absolute or relative paths, where absolute paths
+ // are used as-is and relative paths are appended to |path| to make it
+ // absolute. |callback| is invoked when the request is finished or canceled.
+ void RequestFlush(const base::FilePath& path,
+ const std::vector<base::FilePath>& excludes,
+ const base::Closure& callback);
+
+ // Set a callback for every file flush for test. Note the callback is
+ // called on a blocking pool thread.
+ using OnFlushCallback = base::Callback<void(const base::FilePath&)>;
+ void set_on_flush_callback_for_test(
+ const OnFlushCallback& on_flush_callback) {
+ on_flush_callback_for_test_ = on_flush_callback;
+ }
+
+ private:
+ // Job for the flushing requests.
+ class Job;
+
+ // Starts the first job in |jobs_|.
+ void ScheduleJob();
+
+ // Invoked by a Job when it finishes.
+ void OnJobDone(Job* job);
+
+ // Not owned. Job manages its own life time.
+ std::vector<Job*> jobs_;
+
+ // A callback for testing to be invoked when a file is flushed.
+ OnFlushCallback on_flush_callback_for_test_;
+
+ base::WeakPtrFactory<FileFlusher> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileFlusher);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_
« no previous file with comments | « no previous file | chrome/browser/chromeos/base/file_flusher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698