forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base: Add override mechanism for Time/TimeTicks/ThreadTicks::Now.
Allows clients to provide functions to override the return values of Time::Now(), TimeTicks::Now(), ThreadTicks::Now(). Also adds a way to bypass the override in places where real timestamps should be used even if an override is set. Bug: 802217, 751993 Change-Id: I76ce536caf9bf0ef5e580abcc23215ce9851ee34 Reviewed-on: https://chromium-review.googlesource.com/867911 Commit-Queue: Eric Seckler <eseckler@chromium.org> Reviewed-by: Gabriel Charette <gab@chromium.org> Reviewed-by: Yuri Wiitala <miu@chromium.org> Cr-Commit-Position: refs/heads/master@{#531923}
- Loading branch information
Showing
9 changed files
with
473 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2018 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 "base/time/time_override.h" | ||
|
||
namespace base { | ||
namespace subtle { | ||
|
||
#if DCHECK_IS_ON() | ||
// static | ||
bool ScopedTimeClockOverrides::overrides_active_ = false; | ||
#endif | ||
|
||
ScopedTimeClockOverrides::ScopedTimeClockOverrides( | ||
TimeNowFunction time_override, | ||
TimeTicksNowFunction time_ticks_override, | ||
ThreadTicksNowFunction thread_ticks_override) { | ||
#if DCHECK_IS_ON() | ||
DCHECK(!overrides_active_); | ||
overrides_active_ = true; | ||
#endif | ||
if (time_override) { | ||
internal::g_time_now_function = time_override; | ||
internal::g_time_now_from_system_time_function = time_override; | ||
} | ||
if (time_ticks_override) | ||
internal::g_time_ticks_now_function = time_ticks_override; | ||
if (thread_ticks_override) | ||
internal::g_thread_ticks_now_function = thread_ticks_override; | ||
} | ||
|
||
ScopedTimeClockOverrides::~ScopedTimeClockOverrides() { | ||
internal::g_time_now_function = &TimeNowIgnoringOverride; | ||
internal::g_time_now_from_system_time_function = | ||
&TimeNowFromSystemTimeIgnoringOverride; | ||
internal::g_time_ticks_now_function = &TimeTicksNowIgnoringOverride; | ||
internal::g_thread_ticks_now_function = &ThreadTicksNowIgnoringOverride; | ||
#if DCHECK_IS_ON() | ||
overrides_active_ = false; | ||
#endif | ||
} | ||
|
||
} // namespace subtle | ||
} // namespace base |
Oops, something went wrong.