// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/timer/elapsed_timer.h"

#include "base/check.h"

namespace base {

namespace {
bool g_mock_elapsed_timers_for_test = false;
}  // namespace

ElapsedTimer::ElapsedTimer() : begin_(TimeTicks::Now()) {}

ElapsedTimer::ElapsedTimer(ElapsedTimer&& other) : begin_(other.begin_) {}

void ElapsedTimer::operator=(ElapsedTimer&& other) {
  begin_ = other.begin_;
}

TimeDelta ElapsedTimer::Elapsed() const {
  if (g_mock_elapsed_timers_for_test)
    return ScopedMockElapsedTimersForTest::kMockElapsedTime;
  return TimeTicks::Now() - begin_;
}

ElapsedThreadTimer::ElapsedThreadTimer()
    : is_supported_(ThreadTicks::IsSupported()),
      begin_(is_supported_ ? ThreadTicks::Now() : ThreadTicks()) {}

TimeDelta ElapsedThreadTimer::Elapsed() const {
  if (!is_supported_)
    return TimeDelta();
  if (g_mock_elapsed_timers_for_test)
    return ScopedMockElapsedTimersForTest::kMockElapsedTime;
  return ThreadTicks::Now() - begin_;
}

// static
constexpr TimeDelta ScopedMockElapsedTimersForTest::kMockElapsedTime;

ScopedMockElapsedTimersForTest::ScopedMockElapsedTimersForTest() {
  DCHECK(!g_mock_elapsed_timers_for_test);
  g_mock_elapsed_timers_for_test = true;
}

ScopedMockElapsedTimersForTest::~ScopedMockElapsedTimersForTest() {
  DCHECK(g_mock_elapsed_timers_for_test);
  g_mock_elapsed_timers_for_test = false;
}

}  // namespace base
