tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PageInformation.h (2623B)


      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/. */
      6 
      7 #ifndef PageInformation_h
      8 #define PageInformation_h
      9 
     10 #include "mozilla/Atomics.h"
     11 #include "mozilla/Maybe.h"
     12 #include "mozilla/MemoryReporting.h"
     13 
     14 #include <string>
     15 
     16 namespace mozilla {
     17 namespace baseprofiler {
     18 
     19 class SpliceableJSONWriter;
     20 
     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 {
     29 public:
     30  PageInformation(uint64_t aTabID, uint64_t aInnerWindowID,
     31                  const std::string& aUrl, uint64_t aEmbedderInnerWindowID);
     32 
     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);
     38    if (--mRefCnt) {
     39      delete this;
     40    }
     41  }
     42 
     43  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
     44  bool Equals(PageInformation* aOtherPageInfo) const;
     45  void StreamJSON(SpliceableJSONWriter& aWriter) const;
     46 
     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; }
     51 
     52  Maybe<uint64_t> BufferPositionWhenUnregistered() const {
     53    return mBufferPositionWhenUnregistered;
     54  }
     55 
     56  void NotifyUnregistered(uint64_t aBufferPosition) {
     57    mBufferPositionWhenUnregistered = Some(aBufferPosition);
     58  }
     59 
     60 private:
     61  const uint64_t mTabID;
     62  const uint64_t mInnerWindowID;
     63  const std::string mUrl;
     64  const uint64_t mEmbedderInnerWindowID;
     65 
     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
     68  // not.
     69  Maybe<uint64_t> mBufferPositionWhenUnregistered;
     70 
     71  mutable Atomic<int32_t, MemoryOrdering::ReleaseAcquire> mRefCnt;
     72 };
     73 
     74 }  // namespace baseprofiler
     75 }  // namespace mozilla
     76 
     77 #endif  // PageInformation_h