OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * Copyright (C) 2012 Intel Inc. All rights reserved. | 3 * Copyright (C) 2012 Intel Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "platform/Timer.h" | 42 #include "platform/Timer.h" |
43 #include "platform/heap/Handle.h" | 43 #include "platform/heap/Handle.h" |
44 #include "wtf/Forward.h" | 44 #include "wtf/Forward.h" |
45 #include "wtf/HashSet.h" | 45 #include "wtf/HashSet.h" |
46 #include "wtf/ListHashSet.h" | 46 #include "wtf/ListHashSet.h" |
47 #include "wtf/Vector.h" | 47 #include "wtf/Vector.h" |
48 | 48 |
49 namespace blink { | 49 namespace blink { |
50 | 50 |
51 class ExceptionState; | 51 class ExceptionState; |
52 class LocalFrame; | |
53 class PerformanceObserver; | 52 class PerformanceObserver; |
54 class PerformanceTiming; | 53 class PerformanceTiming; |
55 class ResourceResponse; | 54 class ResourceResponse; |
56 class ResourceTimingInfo; | 55 class ResourceTimingInfo; |
57 class SecurityOrigin; | 56 class SecurityOrigin; |
58 class UserTiming; | 57 class UserTiming; |
59 | 58 |
60 using PerformanceEntryVector = HeapVector<Member<PerformanceEntry>>; | 59 using PerformanceEntryVector = HeapVector<Member<PerformanceEntry>>; |
61 using PerformanceObservers = HeapListHashSet<Member<PerformanceObserver>>; | 60 using PerformanceObservers = HeapListHashSet<Member<PerformanceObserver>>; |
62 | 61 |
63 class CORE_EXPORT PerformanceBase : public EventTargetWithInlineData { | 62 class CORE_EXPORT PerformanceBase : public EventTargetWithInlineData { |
64 friend class PerformanceBaseTest; | |
65 | 63 |
66 public: | 64 public: |
67 ~PerformanceBase() override; | 65 ~PerformanceBase() override; |
68 | 66 |
69 const AtomicString& interfaceName() const override; | 67 const AtomicString& interfaceName() const override; |
70 | 68 |
71 virtual PerformanceTiming* timing() const; | 69 virtual PerformanceTiming* timing() const; |
72 | 70 |
73 virtual void updateLongTaskInstrumentation() {} | 71 virtual void updateLongTaskInstrumentation() {} |
74 | 72 |
75 // Reduce the resolution to 5µs to prevent timing attacks. See: | 73 // Reduce the resolution to 5µs to prevent timing attacks. See: |
76 // http://www.w3.org/TR/hr-time-2/#privacy-security | 74 // http://www.w3.org/TR/hr-time-2/#privacy-security |
77 static double clampTimeResolution(double timeSeconds); | 75 static double clampTimeResolution(double timeSeconds); |
78 | 76 |
79 static DOMHighResTimeStamp monotonicTimeToDOMHighResTimeStamp( | 77 static DOMHighResTimeStamp monotonicTimeToDOMHighResTimeStamp( |
80 double timeOrigin, | 78 double timeOrigin, |
81 double monotonicTime); | 79 double monotonicTime); |
82 | 80 |
83 // Translate given platform monotonic time in seconds into a high resolution | 81 // Translate given platform monotonic time in seconds into a high resolution |
84 // DOMHighResTimeStamp in milliseconds. The result timestamp is relative to | 82 // DOMHighResTimeStamp in milliseconds. The result timestamp is relative to |
85 // document's time origin and has a time resolution that is safe for | 83 // document's time origin and has a time resolution that is safe for |
86 // exposing to web. | 84 // exposing to web. |
87 DOMHighResTimeStamp monotonicTimeToDOMHighResTimeStamp(double) const; | 85 DOMHighResTimeStamp monotonicTimeToDOMHighResTimeStamp(double) const; |
88 DOMHighResTimeStamp now() const; | 86 DOMHighResTimeStamp now() const; |
89 | 87 |
90 double timeOrigin() const { return m_timeOrigin; } | 88 double timeOrigin() const { return m_timeOrigin; } |
91 | 89 |
92 PerformanceEntryVector getEntries() const; | 90 PerformanceEntryVector getEntries(); |
93 PerformanceEntryVector getEntriesByType(const String& entryType); | 91 PerformanceEntryVector getEntriesByType(const String& entryType); |
94 PerformanceEntryVector getEntriesByName(const String& name, | 92 PerformanceEntryVector getEntriesByName(const String& name, |
95 const String& entryType); | 93 const String& entryType); |
96 | 94 |
97 void clearResourceTimings(); | 95 void clearResourceTimings(); |
98 void setResourceTimingBufferSize(unsigned); | 96 void setResourceTimingBufferSize(unsigned); |
99 | 97 |
100 DEFINE_ATTRIBUTE_EVENT_LISTENER(resourcetimingbufferfull); | 98 DEFINE_ATTRIBUTE_EVENT_LISTENER(resourcetimingbufferfull); |
101 | 99 |
102 void clearFrameTimings(); | 100 void clearFrameTimings(); |
103 void setFrameTimingBufferSize(unsigned); | 101 void setFrameTimingBufferSize(unsigned); |
104 | 102 |
105 DEFINE_ATTRIBUTE_EVENT_LISTENER(frametimingbufferfull); | 103 DEFINE_ATTRIBUTE_EVENT_LISTENER(frametimingbufferfull); |
106 | 104 |
107 void addLongTaskTiming(double startTime, | 105 void addLongTaskTiming(double startTime, |
108 double endTime, | 106 double endTime, |
109 const String& name, | 107 const String& name, |
110 const String& culpritFrameSrc, | 108 const String& culpritFrameSrc, |
111 const String& culpritFrameId, | 109 const String& culpritFrameId, |
112 const String& culpritFrameName); | 110 const String& culpritFrameName); |
113 | 111 |
114 void addResourceTiming(const ResourceTimingInfo&); | 112 void addResourceTiming(const ResourceTimingInfo&); |
115 | 113 |
116 void addNavigationTiming(LocalFrame*); | 114 void notifyNavigationTimingToObservers(); |
117 | 115 |
118 void addFirstPaintTiming(double startTime); | 116 void addFirstPaintTiming(double startTime); |
119 | 117 |
120 void addFirstContentfulPaintTiming(double startTime); | 118 void addFirstContentfulPaintTiming(double startTime); |
121 | 119 |
122 void mark(const String& markName, ExceptionState&); | 120 void mark(const String& markName, ExceptionState&); |
123 void clearMarks(const String& markName); | 121 void clearMarks(const String& markName); |
124 | 122 |
125 void measure(const String& measureName, | 123 void measure(const String& measureName, |
126 const String& startMark, | 124 const String& startMark, |
127 const String& endMark, | 125 const String& endMark, |
128 ExceptionState&); | 126 ExceptionState&); |
129 void clearMeasures(const String& measureName); | 127 void clearMeasures(const String& measureName); |
130 | 128 |
131 void unregisterPerformanceObserver(PerformanceObserver&); | 129 void unregisterPerformanceObserver(PerformanceObserver&); |
132 void registerPerformanceObserver(PerformanceObserver&); | 130 void registerPerformanceObserver(PerformanceObserver&); |
133 void updatePerformanceObserverFilterOptions(); | 131 void updatePerformanceObserverFilterOptions(); |
134 void activateObserver(PerformanceObserver&); | 132 void activateObserver(PerformanceObserver&); |
135 void resumeSuspendedObservers(); | 133 void resumeSuspendedObservers(); |
136 | 134 |
137 DECLARE_VIRTUAL_TRACE(); | |
138 | |
139 private: | |
140 static PerformanceNavigationTiming::NavigationType getNavigationType( | |
141 NavigationType, | |
142 const Document*); | |
143 | |
144 static bool allowsTimingRedirect(const Vector<ResourceResponse>&, | 135 static bool allowsTimingRedirect(const Vector<ResourceResponse>&, |
145 const ResourceResponse&, | 136 const ResourceResponse&, |
146 const SecurityOrigin&, | 137 const SecurityOrigin&, |
147 ExecutionContext*); | 138 ExecutionContext*); |
148 | 139 |
| 140 static PerformanceNavigationTiming::NavigationType getNavigationType( |
| 141 NavigationType, |
| 142 const Document*); |
| 143 |
| 144 DECLARE_VIRTUAL_TRACE(); |
| 145 |
| 146 private: |
149 static bool passesTimingAllowCheck(const ResourceResponse&, | 147 static bool passesTimingAllowCheck(const ResourceResponse&, |
150 const SecurityOrigin&, | 148 const SecurityOrigin&, |
151 const AtomicString&, | 149 const AtomicString&, |
152 ExecutionContext*); | 150 ExecutionContext*); |
153 | 151 |
154 void addPaintTiming(PerformancePaintTiming::PaintType, double startTime); | 152 void addPaintTiming(PerformancePaintTiming::PaintType, double startTime); |
155 | 153 |
156 protected: | 154 protected: |
157 explicit PerformanceBase(double timeOrigin, RefPtr<WebTaskRunner>); | 155 explicit PerformanceBase(double timeOrigin, RefPtr<WebTaskRunner>); |
158 | 156 |
| 157 // Expect Performance to override this method, |
| 158 // WorkerPerformance doesn't have to override this. |
| 159 virtual PerformanceNavigationTiming* createNavigationTimingInstance() { |
| 160 return nullptr; |
| 161 } |
| 162 |
159 bool isResourceTimingBufferFull(); | 163 bool isResourceTimingBufferFull(); |
160 void addResourceTimingBuffer(PerformanceEntry&); | 164 void addResourceTimingBuffer(PerformanceEntry&); |
161 | 165 |
162 bool isFrameTimingBufferFull(); | 166 bool isFrameTimingBufferFull(); |
163 void addFrameTimingBuffer(PerformanceEntry&); | 167 void addFrameTimingBuffer(PerformanceEntry&); |
164 | 168 |
165 void notifyObserversOfEntry(PerformanceEntry&); | 169 void notifyObserversOfEntry(PerformanceEntry&); |
166 bool hasObserverFor(PerformanceEntry::EntryType) const; | 170 bool hasObserverFor(PerformanceEntry::EntryType) const; |
167 | 171 |
168 void deliverObservationsTimerFired(TimerBase*); | 172 void deliverObservationsTimerFired(TimerBase*); |
(...skipping 10 matching lines...) Expand all Loading... |
179 PerformanceEntryTypeMask m_observerFilterOptions; | 183 PerformanceEntryTypeMask m_observerFilterOptions; |
180 PerformanceObservers m_observers; | 184 PerformanceObservers m_observers; |
181 PerformanceObservers m_activeObservers; | 185 PerformanceObservers m_activeObservers; |
182 PerformanceObservers m_suspendedObservers; | 186 PerformanceObservers m_suspendedObservers; |
183 TaskRunnerTimer<PerformanceBase> m_deliverObservationsTimer; | 187 TaskRunnerTimer<PerformanceBase> m_deliverObservationsTimer; |
184 }; | 188 }; |
185 | 189 |
186 } // namespace blink | 190 } // namespace blink |
187 | 191 |
188 #endif // PerformanceBase_h | 192 #endif // PerformanceBase_h |
OLD | NEW |