LCOV - code coverage report
Current view: top level - gfx/layers/apz/util - CheckerboardReportService.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 15 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef mozilla_dom_CheckerboardReportService_h
       7             : #define mozilla_dom_CheckerboardReportService_h
       8             : 
       9             : #include <string>
      10             : 
      11             : #include "js/TypeDecls.h" // for JSContext, JSObject
      12             : #include "mozilla/ErrorResult.h" // for ErrorResult
      13             : #include "mozilla/StaticPtr.h" // for StaticRefPtr
      14             : #include "nsCOMPtr.h" // for nsCOMPtr
      15             : #include "nsISupports.h" // for NS_INLINE_DECL_REFCOUNTING
      16             : #include "nsWrapperCache.h" // for nsWrapperCache
      17             : 
      18             : namespace mozilla {
      19             : 
      20             : namespace dom {
      21             : struct CheckerboardReport;
      22             : }
      23             : 
      24             : namespace layers {
      25             : 
      26             : // CheckerboardEventStorage is a singleton that stores info on checkerboard
      27             : // events, so that they can be accessed from about:checkerboard and visualized.
      28             : // Note that this class is NOT threadsafe, and all methods must be called on
      29             : // the main thread.
      30             : class CheckerboardEventStorage
      31             : {
      32           0 :   NS_INLINE_DECL_REFCOUNTING(CheckerboardEventStorage)
      33             : 
      34             : public:
      35             :   /**
      36             :    * Get the singleton instance.
      37             :    */
      38             :   static already_AddRefed<CheckerboardEventStorage> GetInstance();
      39             : 
      40             :   /**
      41             :    * Get the stored checkerboard reports.
      42             :    */
      43             :   void GetReports(nsTArray<dom::CheckerboardReport>& aOutReports);
      44             : 
      45             :   /**
      46             :    * Save a checkerboard event log, optionally dropping older ones that were
      47             :    * less severe or less recent. Zero-severity reports may be ignored entirely.
      48             :    */
      49             :   static void Report(uint32_t aSeverity, const std::string& aLog);
      50             : 
      51             : private:
      52             :   /* Stuff for refcounted singleton */
      53           0 :   CheckerboardEventStorage() {}
      54           0 :   virtual ~CheckerboardEventStorage() {}
      55             : 
      56             :   static StaticRefPtr<CheckerboardEventStorage> sInstance;
      57             : 
      58             :   void ReportCheckerboard(uint32_t aSeverity, const std::string& aLog);
      59             : 
      60             : private:
      61             :   /**
      62             :    * Struct that this class uses internally to store a checkerboard report.
      63             :    */
      64           0 :   struct CheckerboardReport {
      65             :       uint32_t mSeverity; // if 0, this report is empty
      66             :       int64_t mTimestamp; // microseconds since epoch, as from JS_Now()
      67             :       std::string mLog;
      68             : 
      69           0 :       CheckerboardReport()
      70           0 :         : mSeverity(0)
      71           0 :         , mTimestamp(0)
      72           0 :       {}
      73             : 
      74           0 :       CheckerboardReport(uint32_t aSeverity, int64_t aTimestamp,
      75             :                          const std::string& aLog)
      76           0 :         : mSeverity(aSeverity)
      77             :         , mTimestamp(aTimestamp)
      78           0 :         , mLog(aLog)
      79           0 :       {}
      80             :   };
      81             : 
      82             :   // The first 5 (indices 0-4) are the most severe ones in decreasing order
      83             :   // of severity; the next 5 (indices 5-9) are the most recent ones that are
      84             :   // not already in the "severe" list.
      85             :   static const int SEVERITY_MAX_INDEX = 5;
      86             :   static const int RECENT_MAX_INDEX = 10;
      87             :   CheckerboardReport mCheckerboardReports[RECENT_MAX_INDEX];
      88             : };
      89             : 
      90             : } // namespace layers
      91             : 
      92             : namespace dom {
      93             : 
      94             : class GlobalObject;
      95             : 
      96             : /**
      97             :  * CheckerboardReportService is a wrapper object that allows access to the
      98             :  * stuff in CheckerboardEventStorage (above). We need this wrapper for proper
      99             :  * garbage/cycle collection, since this can be accessed from JS.
     100             :  */
     101             : class CheckerboardReportService : public nsWrapperCache
     102             : {
     103             : public:
     104             :   /**
     105             :    * Check if the given page is allowed to access this object via the WebIDL
     106             :    * bindings. It only returns true if the page is about:checkerboard.
     107             :    */
     108             :   static bool IsEnabled(JSContext* aCtx, JSObject* aGlobal);
     109             : 
     110             :   /*
     111             :    * Other standard WebIDL binding glue.
     112             :    */
     113             : 
     114             :   static already_AddRefed<CheckerboardReportService>
     115             :     Constructor(const dom::GlobalObject& aGlobal, ErrorResult& aRv);
     116             : 
     117             :   explicit CheckerboardReportService(nsISupports* aSupports);
     118             : 
     119             :   JSObject* WrapObject(JSContext* aCtx, JS::Handle<JSObject*> aGivenProto) override;
     120             : 
     121             :   nsISupports* GetParentObject();
     122             : 
     123           0 :   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CheckerboardReportService)
     124           0 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CheckerboardReportService)
     125             : 
     126             : public:
     127             :   /*
     128             :    * The methods exposed via the webidl.
     129             :    */
     130             :   void GetReports(nsTArray<dom::CheckerboardReport>& aOutReports);
     131             :   bool IsRecordingEnabled() const;
     132             :   void SetRecordingEnabled(bool aEnabled);
     133             :   void FlushActiveReports();
     134             : 
     135             : private:
     136           0 :   virtual ~CheckerboardReportService() {}
     137             : 
     138             :   nsCOMPtr<nsISupports> mParent;
     139             : };
     140             : 
     141             : } // namespace dom
     142             : } // namespace mozilla
     143             : 
     144             : #endif /* mozilla_layers_CheckerboardReportService_h */

Generated by: LCOV version 1.13