Bug 1874684 - Part 6: Limit day length calculations to safe integers. r=mgaudet
[gecko.git] / dom / performance / PerformanceService.cpp
blob746d278b77ae2c422138f720ac7b48bfb36a2fa1
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "PerformanceService.h"
9 #include "mozilla/ClearOnShutdown.h"
10 #include "mozilla/StaticMutex.h"
11 #include "mozilla/StaticPtr.h"
12 #include "prtime.h"
14 namespace mozilla::dom {
16 static StaticRefPtr<PerformanceService> gPerformanceService;
17 static StaticMutex gPerformanceServiceMutex MOZ_UNANNOTATED;
19 /* static */
20 PerformanceService* PerformanceService::GetOrCreate() {
21 StaticMutexAutoLock al(gPerformanceServiceMutex);
23 if (!gPerformanceService) {
24 gPerformanceService = new PerformanceService();
25 ClearOnShutdown(&gPerformanceService);
28 return gPerformanceService;
31 DOMHighResTimeStamp PerformanceService::TimeOrigin(
32 const TimeStamp& aCreationTimeStamp) const {
33 return (aCreationTimeStamp - mCreationTimeStamp).ToMilliseconds() +
34 (mCreationEpochTime / PR_USEC_PER_MSEC);
37 PerformanceService::PerformanceService() {
38 mCreationTimeStamp = TimeStamp::Now();
39 mCreationEpochTime = PR_Now();
42 } // namespace mozilla::dom