OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sync_file_system/drive_backend/sync_task_manager.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/sync_task_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 if (!foreground_task_token) { | 284 if (!foreground_task_token) { |
285 PushPendingTask( | 285 PushPendingTask( |
286 base::Bind(&SyncTaskManager::UpdateTaskBlockerBody, | 286 base::Bind(&SyncTaskManager::UpdateTaskBlockerBody, |
287 AsWeakPtr(), | 287 AsWeakPtr(), |
288 base::Passed(&foreground_task_token), | 288 base::Passed(&foreground_task_token), |
289 base::Passed(&background_task_token), | 289 base::Passed(&background_task_token), |
290 base::Passed(&task_log), | 290 base::Passed(&task_log), |
291 base::Passed(&task_blocker), | 291 base::Passed(&task_blocker), |
292 continuation), | 292 continuation), |
293 PRIORITY_HIGH); | 293 PRIORITY_HIGH); |
294 MaybeStartNextForegroundTask(scoped_ptr<SyncTaskToken>()); | 294 MaybeStartNextForegroundTask(nullptr); |
295 return; | 295 return; |
296 } | 296 } |
297 } | 297 } |
298 | 298 |
299 // Check if the task can run as a background task now. | 299 // Check if the task can run as a background task now. |
300 // If there are too many task running or any other task blocks current | 300 // If there are too many task running or any other task blocks current |
301 // task, wait for any other task to finish. | 301 // task, wait for any other task to finish. |
302 bool task_number_limit_exceeded = | 302 bool task_number_limit_exceeded = |
303 !background_task_token && | 303 !background_task_token && |
304 running_background_tasks_.size() >= maximum_background_task_; | 304 running_background_tasks_.size() >= maximum_background_task_; |
(...skipping 25 matching lines...) Expand all Loading... |
330 SyncTaskToken::CreateForBackgroundTask(AsWeakPtr(), | 330 SyncTaskToken::CreateForBackgroundTask(AsWeakPtr(), |
331 task_runner_.get(), | 331 task_runner_.get(), |
332 task_token_seq_++, | 332 task_token_seq_++, |
333 task_blocker.Pass()); | 333 task_blocker.Pass()); |
334 background_task_token->UpdateTask(from_here, callback); | 334 background_task_token->UpdateTask(from_here, callback); |
335 running_background_tasks_.set(background_task_token->token_id(), | 335 running_background_tasks_.set(background_task_token->token_id(), |
336 running_foreground_task_.Pass()); | 336 running_foreground_task_.Pass()); |
337 } | 337 } |
338 | 338 |
339 token_ = foreground_task_token.Pass(); | 339 token_ = foreground_task_token.Pass(); |
340 MaybeStartNextForegroundTask(scoped_ptr<SyncTaskToken>()); | 340 MaybeStartNextForegroundTask(nullptr); |
341 background_task_token->SetTaskLog(task_log.Pass()); | 341 background_task_token->SetTaskLog(task_log.Pass()); |
342 continuation.Run(background_task_token.Pass()); | 342 continuation.Run(background_task_token.Pass()); |
343 } | 343 } |
344 | 344 |
345 scoped_ptr<SyncTaskToken> SyncTaskManager::GetToken( | 345 scoped_ptr<SyncTaskToken> SyncTaskManager::GetToken( |
346 const tracked_objects::Location& from_here, | 346 const tracked_objects::Location& from_here, |
347 const SyncStatusCallback& callback) { | 347 const SyncStatusCallback& callback) { |
348 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 348 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
349 | 349 |
350 if (!token_) | 350 if (!token_) |
351 return scoped_ptr<SyncTaskToken>(); | 351 return nullptr; |
352 token_->UpdateTask(from_here, callback); | 352 token_->UpdateTask(from_here, callback); |
353 return token_.Pass(); | 353 return token_.Pass(); |
354 } | 354 } |
355 | 355 |
356 void SyncTaskManager::PushPendingTask( | 356 void SyncTaskManager::PushPendingTask( |
357 const base::Closure& closure, Priority priority) { | 357 const base::Closure& closure, Priority priority) { |
358 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 358 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
359 | 359 |
360 pending_tasks_.push(PendingTask(closure, priority, pending_task_seq_++)); | 360 pending_tasks_.push(PendingTask(closure, priority, pending_task_seq_++)); |
361 } | 361 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 closure.Run(); | 394 closure.Run(); |
395 return; | 395 return; |
396 } | 396 } |
397 | 397 |
398 if (client_) | 398 if (client_) |
399 client_->MaybeScheduleNextTask(); | 399 client_->MaybeScheduleNextTask(); |
400 } | 400 } |
401 | 401 |
402 } // namespace drive_backend | 402 } // namespace drive_backend |
403 } // namespace sync_file_system | 403 } // namespace sync_file_system |
OLD | NEW |