| 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 #include "chrome/browser/chromeos/base/file_flusher.h" | 5 #include "chrome/browser/chromeos/base/file_flusher.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 delete this; | 160 delete this; |
| 161 } | 161 } |
| 162 | 162 |
| 163 //////////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////////// |
| 164 // FileFlusher | 164 // FileFlusher |
| 165 | 165 |
| 166 FileFlusher::FileFlusher() : weak_factory_(this) {} | 166 FileFlusher::FileFlusher() : weak_factory_(this) {} |
| 167 | 167 |
| 168 FileFlusher::~FileFlusher() { | 168 FileFlusher::~FileFlusher() { |
| 169 for (const auto& job : jobs_) | 169 for (auto* job : jobs_) |
| 170 job->Cancel(); | 170 job->Cancel(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void FileFlusher::RequestFlush(const base::FilePath& path, | 173 void FileFlusher::RequestFlush(const base::FilePath& path, |
| 174 const std::vector<base::FilePath>& excludes, | 174 const std::vector<base::FilePath>& excludes, |
| 175 const base::Closure& callback) { | 175 const base::Closure& callback) { |
| 176 for (const auto& job : jobs_) { | 176 for (auto* job : jobs_) { |
| 177 if (path == job->path() || path.IsParent(job->path())) | 177 if (path == job->path() || path.IsParent(job->path())) |
| 178 job->Cancel(); | 178 job->Cancel(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 jobs_.push_back(new Job(weak_factory_.GetWeakPtr(), path, excludes, | 181 jobs_.push_back(new Job(weak_factory_.GetWeakPtr(), path, excludes, |
| 182 on_flush_callback_for_test_, callback)); | 182 on_flush_callback_for_test_, callback)); |
| 183 ScheduleJob(); | 183 ScheduleJob(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void FileFlusher::ScheduleJob() { | 186 void FileFlusher::ScheduleJob() { |
| 187 if (jobs_.empty()) | 187 if (jobs_.empty()) |
| 188 return; | 188 return; |
| 189 | 189 |
| 190 auto job = jobs_.front(); | 190 auto* job = jobs_.front(); |
| 191 if (!job->started()) | 191 if (!job->started()) |
| 192 job->Start(); | 192 job->Start(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void FileFlusher::OnJobDone(FileFlusher::Job* job) { | 195 void FileFlusher::OnJobDone(FileFlusher::Job* job) { |
| 196 for (auto it = jobs_.begin(); it != jobs_.end(); ++it) { | 196 for (auto it = jobs_.begin(); it != jobs_.end(); ++it) { |
| 197 if (*it == job) { | 197 if (*it == job) { |
| 198 jobs_.erase(it); | 198 jobs_.erase(it); |
| 199 break; | 199 break; |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 ScheduleJob(); | 203 ScheduleJob(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace chromeos | 206 } // namespace chromeos |
| OLD | NEW |