Coverage Report

Created: 2018-09-25 14:53

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