• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 #ifndef BASE_TASK_SEQUENCE_MANAGER_LAZY_NOW_H_
6 #define BASE_TASK_SEQUENCE_MANAGER_LAZY_NOW_H_
7 
8 #include "base/base_export.h"
9 #include "base/optional.h"
10 #include "base/time/time.h"
11 
12 namespace base {
13 
14 class TickClock;
15 
16 namespace sequence_manager {
17 
18 // Now() is somewhat expensive so it makes sense not to call Now() unless we
19 // really need to and to avoid subsequent calls if already called once.
20 // LazyNow objects are expected to be short-living to represent accurate time.
21 class BASE_EXPORT LazyNow {
22  public:
23   explicit LazyNow(TimeTicks now);
24   explicit LazyNow(const TickClock* tick_clock);
25 
26   LazyNow(LazyNow&& move_from) noexcept;
27 
28   // Result will not be updated on any subsesequent calls.
29   TimeTicks Now();
30 
31  private:
32   const TickClock* tick_clock_;  // Not owned.
33   Optional<TimeTicks> now_;
34 
35   DISALLOW_COPY_AND_ASSIGN(LazyNow);
36 };
37 
38 }  // namespace sequence_manager
39 }  // namespace base
40 
41 #endif  // BASE_TASK_SEQUENCE_MANAGER_LAZY_NOW_H_
42