summaryrefslogtreecommitdiff
path: root/chromium/components/offline_pages/task/task.cc
blob: 419845465db60c575d523b40a90592ea0432e1a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/offline_pages/task/task.h"

#include <utility>

#include "base/logging.h"

namespace offline_pages {

Task::Task() = default;
Task::~Task() {
  // This may happen when tearing-down the |TaskQueue|.
  DLOG_IF(WARNING, started_ && !completed_)
      << "Task being destroyed before completion";
}

void Task::Execute(base::OnceClosure complete_callback) {
  DCHECK(!started_);
  started_ = true;
  task_completion_callback_ = std::move(complete_callback);
  Run();
}

void Task::TaskComplete() {
  DCHECK(started_);
  DCHECK(!completed_);
  completed_ = true;
  if (!task_completion_callback_.is_null())
    std::move(task_completion_callback_).Run();
}

}  // namespace offline_pages