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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/base/file_flusher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_
6 #define CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_
7
8 #include <vector>
9
10 #include "base/callback.h"
11 #include "base/files/file_path.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14
15 namespace chromeos {
16
17 // Flushes files under the requested directories in the blocking pool. If the
18 // same directory is requested more than once, the last request cancels all
19 // previous ones and start a new flushing process.
20 class FileFlusher {
21 public:
22 FileFlusher();
23 ~FileFlusher();
24
25 // Flush everything under |path| except the directories/files in |excludes|.
26 // |excluedes| can hold both absolute or relative paths, where absolute paths
27 // are used as-is and relative paths are appended to |path| to make it
28 // absolute. |callback| is invoked when the request is finished or canceled.
29 void RequestFlush(const base::FilePath& path,
30 const std::vector<base::FilePath>& excludes,
31 const base::Closure& callback);
32
33 // Set a callback for every file flush for test. Note the callback is
34 // called on a blocking pool thread.
35 using OnFlushCallback = base::Callback<void(const base::FilePath&)>;
36 void set_on_flush_callback_for_test(
37 const OnFlushCallback& on_flush_callback) {
38 on_flush_callback_for_test_ = on_flush_callback;
39 }
40
41 private:
42 // Job for the flushing requests.
43 class Job;
44
45 // Starts the first job in |jobs_|.
46 void ScheduleJob();
47
48 // Invoked by a Job when it finishes.
49 void OnJobDone(Job* job);
50
51 // Not owned. Job manages its own life time.
52 std::vector<Job*> jobs_;
53
54 // A callback for testing to be invoked when a file is flushed.
55 OnFlushCallback on_flush_callback_for_test_;
56
57 base::WeakPtrFactory<FileFlusher> weak_factory_;
58
59 DISALLOW_COPY_AND_ASSIGN(FileFlusher);
60 };
61
62 } // namespace chromeos
63
64 #endif // CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_
OLDNEW
« 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