| 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 #include "components/offline_pages/core/task.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 |
| 10 namespace offline_pages { |
| 11 |
| 12 Task::Task() {} |
| 13 |
| 14 Task::~Task() {} |
| 15 |
| 16 void Task::SetTaskCompletionCallbackForTesting( |
| 17 scoped_refptr<base::SingleThreadTaskRunner> task_completion_runner, |
| 18 const TaskCompletionCallback& task_completion_callback) { |
| 19 SetTaskCompletionCallback(task_completion_runner, task_completion_callback); |
| 20 } |
| 21 |
| 22 void Task::SetTaskCompletionCallback( |
| 23 scoped_refptr<base::SingleThreadTaskRunner> task_completion_runner, |
| 24 const TaskCompletionCallback& task_completion_callback) { |
| 25 // Attempts to enforce that SetTaskCompletionCallback is at most called once |
| 26 // and enforces that reasonable values are set once that happens. |
| 27 DCHECK(!task_completion_runner_); |
| 28 DCHECK(task_completion_runner); |
| 29 DCHECK(task_completion_callback_.is_null()); |
| 30 DCHECK(!task_completion_callback.is_null()); |
| 31 task_completion_runner_ = task_completion_runner; |
| 32 task_completion_callback_ = task_completion_callback; |
| 33 } |
| 34 |
| 35 void Task::TaskComplete() { |
| 36 if (task_completion_callback_.is_null() || !task_completion_runner_) |
| 37 return; |
| 38 |
| 39 task_completion_runner_->PostTask( |
| 40 FROM_HERE, base::Bind(task_completion_callback_, this)); |
| 41 } |
| 42 |
| 43 } // namespace offline_pages |
| OLD | NEW |