Line data Source code
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/. */
6 :
7 : #ifndef dom_performance_PerformanceService_h
8 : #define dom_performance_PerformanceService_h
9 :
10 : #include "mozilla/TimeStamp.h"
11 : #include "nsCOMPtr.h"
12 : #include "nsDOMNavigationTiming.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : // This class is thread-safe.
18 :
19 : // We use this singleton for having the correct value of performance.timeOrigin.
20 : // This value must be calculated on top of the pair:
21 : // - mCreationTimeStamp (monotonic clock)
22 : // - mCreationEpochTime (unix epoch time)
23 : // These 2 values must be taken "at the same time" in order to be used
24 : // correctly.
25 :
26 : class PerformanceService
27 : {
28 : public:
29 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PerformanceService)
30 :
31 : static PerformanceService*
32 : GetOrCreate();
33 :
34 : DOMHighResTimeStamp
35 : TimeOrigin(const TimeStamp& aCreationTimeStamp) const;
36 :
37 : private:
38 : PerformanceService();
39 : ~PerformanceService() = default;
40 :
41 : TimeStamp mCreationTimeStamp;
42 : PRTime mCreationEpochTime;
43 : };
44 :
45 : } // dom namespace
46 : } // mozilla namespace
47 :
48 : #endif // dom_performance_PerformanceService_h
|