summaryrefslogtreecommitdiffstats
path: root/components/scheduler/base/virtual_time_domain.cc
blob: 97c63da5cdaba218d07f2acd5e69ca7d36ff2cab (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2015 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/scheduler/base/virtual_time_domain.h"

#include "base/bind.h"
#include "components/scheduler/base/task_queue_impl.h"
#include "components/scheduler/base/task_queue_manager.h"
#include "components/scheduler/base/task_queue_manager_delegate.h"

namespace scheduler {

VirtualTimeDomain::VirtualTimeDomain(TimeDomain::Observer* observer,
                                     base::TimeTicks initial_time)
    : TimeDomain(observer), now_(initial_time), task_queue_manager_(nullptr) {}

VirtualTimeDomain::~VirtualTimeDomain() {}

void VirtualTimeDomain::OnRegisterWithTaskQueueManager(
    TaskQueueManager* task_queue_manager) {
  task_queue_manager_ = task_queue_manager;
  DCHECK(task_queue_manager_);
}

LazyNow VirtualTimeDomain::CreateLazyNow() {
  base::AutoLock lock(lock_);
  return LazyNow(now_);
}

base::TimeTicks VirtualTimeDomain::ComputeDelayedRunTime(
    base::TimeTicks time_domain_now,
    base::TimeDelta delay) const {
  return time_domain_now + delay;
}

void VirtualTimeDomain::RequestWakeup(LazyNow* lazy_now,
                                      base::TimeDelta delay) {
  // We don't need to do anything here because the caller of AdvanceTo is
  // responsible for calling TaskQueueManager::MaybeScheduleImmediateWork if
  // needed.
}

bool VirtualTimeDomain::MaybeAdvanceTime() {
  return false;
}

void VirtualTimeDomain::AsValueIntoInternal(
    base::trace_event::TracedValue* state) const {}

void VirtualTimeDomain::AdvanceTo(base::TimeTicks now) {
  base::AutoLock lock(lock_);
  DCHECK_GE(now, now_);
  now_ = now;
}

void VirtualTimeDomain::RequestDoWork() {
  task_queue_manager_->MaybeScheduleImmediateWork(FROM_HERE);
}

const char* VirtualTimeDomain::GetName() const {
  return "VirtualTimeDomain";
}

}  // namespace scheduler