| OLD | NEW |
| (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_ |
| OLD | NEW |