OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 const base::Closure& callback); | 31 const base::Closure& callback); |
32 | 32 |
33 // Set a callback for every file flush for test. Note the callback is | 33 // Set a callback for every file flush for test. Note the callback is |
34 // called on a blocking pool thread. | 34 // called on a blocking pool thread. |
35 using OnFlushCallback = base::Callback<void(const base::FilePath&)>; | 35 using OnFlushCallback = base::Callback<void(const base::FilePath&)>; |
36 void set_on_flush_callback_for_test( | 36 void set_on_flush_callback_for_test( |
37 const OnFlushCallback& on_flush_callback) { | 37 const OnFlushCallback& on_flush_callback) { |
38 on_flush_callback_for_test_ = on_flush_callback; | 38 on_flush_callback_for_test_ = on_flush_callback; |
39 } | 39 } |
40 | 40 |
| 41 void PauseForTest(); |
| 42 void ResumeForTest(); |
| 43 |
41 private: | 44 private: |
42 // Job for the flushing requests. | 45 // Job for the flushing requests. |
43 class Job; | 46 class Job; |
44 | 47 |
45 // Starts the first job in |jobs_|. | 48 // Starts the first job in |jobs_|. |
46 void ScheduleJob(); | 49 void ScheduleJob(); |
47 | 50 |
48 // Invoked by a Job when it finishes. | 51 // Invoked by a Job when it finishes. |
49 void OnJobDone(Job* job); | 52 void OnJobDone(Job* job); |
50 | 53 |
51 // Not owned. Job manages its own life time. | 54 // Not owned. Job manages its own life time. |
52 std::vector<Job*> jobs_; | 55 std::vector<Job*> jobs_; |
53 | 56 |
54 // A callback for testing to be invoked when a file is flushed. | 57 // A callback for testing to be invoked when a file is flushed. |
55 OnFlushCallback on_flush_callback_for_test_; | 58 OnFlushCallback on_flush_callback_for_test_; |
56 | 59 |
| 60 bool paused_for_test_ = false; |
| 61 |
57 base::WeakPtrFactory<FileFlusher> weak_factory_; | 62 base::WeakPtrFactory<FileFlusher> weak_factory_; |
58 | 63 |
59 DISALLOW_COPY_AND_ASSIGN(FileFlusher); | 64 DISALLOW_COPY_AND_ASSIGN(FileFlusher); |
60 }; | 65 }; |
61 | 66 |
62 } // namespace chromeos | 67 } // namespace chromeos |
63 | 68 |
64 #endif // CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_ | 69 #endif // CHROME_BROWSER_CHROMEOS_BASE_FILE_FLUSHER_H_ |
OLD | NEW |