1 // Copyright 2015 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 "base/task/sequence_manager/real_time_domain.h" 6 7 #include "base/task/sequence_manager/sequence_manager.h" 8 9 namespace base { 10 namespace sequence_manager { 11 namespace internal { 12 RealTimeDomain()13RealTimeDomain::RealTimeDomain() {} 14 15 RealTimeDomain::~RealTimeDomain() = default; 16 CreateLazyNow() const17LazyNow RealTimeDomain::CreateLazyNow() const { 18 return LazyNow(sequence_manager()->GetTickClock()); 19 } 20 Now() const21TimeTicks RealTimeDomain::Now() const { 22 return sequence_manager()->NowTicks(); 23 } 24 DelayTillNextTask(LazyNow * lazy_now)25Optional<TimeDelta> RealTimeDomain::DelayTillNextTask(LazyNow* lazy_now) { 26 Optional<TimeTicks> next_run_time = NextScheduledRunTime(); 27 if (!next_run_time) 28 return nullopt; 29 30 TimeTicks now = lazy_now->Now(); 31 if (now >= next_run_time) { 32 // Overdue work needs to be run immediately. 33 return TimeDelta(); 34 } 35 36 TimeDelta delay = *next_run_time - now; 37 TRACE_EVENT1("sequence_manager", "RealTimeDomain::DelayTillNextTask", 38 "delay_ms", delay.InMillisecondsF()); 39 return delay; 40 } 41 GetName() const42const char* RealTimeDomain::GetName() const { 43 return "RealTimeDomain"; 44 } 45 46 } // namespace internal 47 } // namespace sequence_manager 48 } // namespace base 49