| 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::SetTaskCompletionCallback( |
| 17 scoped_refptr<base::SingleThreadTaskRunner> task_completion_runner, |
| 18 const TaskCompletionCallback& task_completion_callback) { |
| 19 // Attempts to enforce that SetTaskCompletionCallback is at most called once |
| 20 // and enforces that reasonable values are set once that happens. |
| 21 DCHECK(!task_completion_runner_); |
| 22 DCHECK(task_completion_runner); |
| 23 DCHECK(task_completion_callback_.is_null()); |
| 24 DCHECK(!task_completion_callback.is_null()); |
| 25 task_completion_runner_ = task_completion_runner; |
| 26 task_completion_callback_ = task_completion_callback; |
| 27 } |
| 28 |
| 29 void Task::TaskComplete() { |
| 30 if (task_completion_callback_.is_null() || !task_completion_runner_) |
| 31 return; |
| 32 |
| 33 task_completion_runner_->PostTask( |
| 34 FROM_HERE, base::Bind(task_completion_callback_, this)); |
| 35 } |
| 36 |
| 37 } // namespace offline_pages |
| OLD | NEW |