OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/location.h" | 6 #include "base/location.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "chrome/browser/chromeos/file_system_provider/queue.h" | 10 #include "chrome/browser/chromeos/file_system_provider/queue.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // If not completed, then it must have been aborted. | 68 // If not completed, then it must have been aborted. |
69 const auto aborted_it = aborted_.find(token); | 69 const auto aborted_it = aborted_.find(token); |
70 DCHECK(aborted_it != aborted_.end()); | 70 DCHECK(aborted_it != aborted_.end()); |
71 aborted_.erase(aborted_it); | 71 aborted_.erase(aborted_it); |
72 | 72 |
73 base::ThreadTaskRunnerHandle::Get()->PostTask( | 73 base::ThreadTaskRunnerHandle::Get()->PostTask( |
74 FROM_HERE, base::Bind(&Queue::MaybeRun, weak_ptr_factory_.GetWeakPtr())); | 74 FROM_HERE, base::Bind(&Queue::MaybeRun, weak_ptr_factory_.GetWeakPtr())); |
75 } | 75 } |
76 | 76 |
77 void Queue::MaybeRun() { | 77 void Queue::MaybeRun() { |
78 if (executed_.size() == max_in_parallel_ || !pending_.size()) { | 78 if (executed_.size() + completed_.size() == max_in_parallel_ || |
| 79 !pending_.size()) { |
79 return; | 80 return; |
80 } | 81 } |
81 | 82 |
82 DCHECK_GT(max_in_parallel_, executed_.size()); | 83 DCHECK_GT(max_in_parallel_, executed_.size() + completed_.size()); |
83 Task task = pending_.front(); | 84 Task task = pending_.front(); |
84 pending_.pop_front(); | 85 pending_.pop_front(); |
85 | 86 |
86 executed_[task.token] = task; | 87 executed_[task.token] = task; |
87 AbortCallback abort_callback = task.callback.Run(); | 88 AbortCallback abort_callback = task.callback.Run(); |
88 | 89 |
89 // It may happen that the task is completed and removed synchronously. Hence, | 90 // It may happen that the task is completed and removed synchronously. Hence, |
90 // we need to check if the task is still in the executed collection. | 91 // we need to check if the task is still in the executed collection. |
91 const auto executed_task_it = executed_.find(task.token); | 92 const auto executed_task_it = executed_.find(task.token); |
92 if (executed_task_it != executed_.end()) | 93 if (executed_task_it != executed_.end()) |
(...skipping 26 matching lines...) Expand all Loading... |
119 return; | 120 return; |
120 } | 121 } |
121 } | 122 } |
122 | 123 |
123 // The task is already removed, marked as completed or aborted. | 124 // The task is already removed, marked as completed or aborted. |
124 NOTREACHED(); | 125 NOTREACHED(); |
125 } | 126 } |
126 | 127 |
127 } // namespace file_system_provider | 128 } // namespace file_system_provider |
128 } // namespace chromeos | 129 } // namespace chromeos |
OLD | NEW |