1 /* -*- Mode: C++; tab-width: 2; 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 #ifndef PageInformation_h
8 #define PageInformation_h
10 #include "mozilla/Atomics.h"
11 #include "mozilla/Maybe.h"
12 #include "mozilla/MemoryReporting.h"
17 namespace baseprofiler
{
19 class SpliceableJSONWriter
;
21 // This class contains information that's relevant to a single page only
22 // while the page information is important and registered with the profiler,
23 // but regardless of whether the profiler is running. All accesses to it are
24 // protected by the profiler state lock.
25 // When the page gets unregistered, we keep the profiler buffer position
26 // to determine if we are still using this page. If not, we unregister
27 // it in the next page registration.
28 class PageInformation final
{
30 PageInformation(uint64_t aTabID
, uint64_t aInnerWindowID
,
31 const std::string
& aUrl
, uint64_t aEmbedderInnerWindowID
);
33 // Using hand-rolled ref-counting, because RefCounted.h macros don't produce
34 // the same code between mozglue and libxul, see bug 1536656.
35 MFBT_API
void AddRef() const { ++mRefCnt
; }
36 MFBT_API
void Release() const {
37 MOZ_ASSERT(int32_t(mRefCnt
) > 0);
43 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf
) const;
44 bool Equals(PageInformation
* aOtherPageInfo
) const;
45 void StreamJSON(SpliceableJSONWriter
& aWriter
) const;
47 uint64_t InnerWindowID() const { return mInnerWindowID
; }
48 uint64_t TabID() const { return mTabID
; }
49 const std::string
& Url() const { return mUrl
; }
50 uint64_t EmbedderInnerWindowID() const { return mEmbedderInnerWindowID
; }
52 Maybe
<uint64_t> BufferPositionWhenUnregistered() const {
53 return mBufferPositionWhenUnregistered
;
56 void NotifyUnregistered(uint64_t aBufferPosition
) {
57 mBufferPositionWhenUnregistered
= Some(aBufferPosition
);
61 const uint64_t mTabID
;
62 const uint64_t mInnerWindowID
;
63 const std::string mUrl
;
64 const uint64_t mEmbedderInnerWindowID
;
66 // Holds the buffer position when page is unregistered.
67 // It's used to determine if we still use this page in the profiler or
69 Maybe
<uint64_t> mBufferPositionWhenUnregistered
;
71 mutable Atomic
<int32_t, MemoryOrdering::ReleaseAcquire
> mRefCnt
;
74 } // namespace baseprofiler
75 } // namespace mozilla
77 #endif // PageInformation_h