OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "core/timing/PerformanceObserver.h" | |
7 | |
8 #include "bindings/core/v8/ExceptionState.h" | |
9 #include "core/dom/ExceptionCode.h" | |
10 #include "core/inspector/InspectorInstrumentation.h" | |
11 #include "core/timing/PerformanceBase.h" | |
12 #include "core/timing/PerformanceEntry.h" | |
13 #include "core/timing/PerformanceObserverCallback.h" | |
14 #include "core/timing/PerformanceObserverEntryList.h" | |
15 #include "core/timing/PerformanceObserverInit.h" | |
16 #include "platform/Timer.h" | |
17 #include "wtf/MainThread.h" | |
18 #include <algorithm> | |
19 | |
20 namespace blink { | |
21 | |
22 PerformanceObserver* PerformanceObserver::create(PerformanceBase* performance, P erformanceObserverCallback* callback) | |
23 { | |
24 ASSERT(isMainThread()); | |
25 return new PerformanceObserver(performance, callback); | |
26 } | |
27 | |
28 PerformanceObserver::PerformanceObserver(PerformanceBase* performance, Performan ceObserverCallback* callback) | |
29 : m_callback(callback) | |
30 , m_performance(performance) | |
31 , m_filterOptions(PerformanceEntry::Invalid) | |
32 , m_isRegistered(false) | |
33 { | |
34 } | |
35 | |
36 PerformanceObserver::~PerformanceObserver() | |
37 { | |
38 if (!m_performanceEntries.isEmpty()) | |
39 InspectorInstrumentation::didClearAllPerformanceObservations(m_callback- >executionContext(), this); | |
40 } | |
41 | |
42 void PerformanceObserver::observe(const PerformanceObserverInit& observerInit, E xceptionState& exceptionState) | |
43 { | |
44 if (!m_performance) { | |
45 exceptionState.throwTypeError("Window may be destroyed? Performance targ et is invalid."); | |
46 return; | |
47 } | |
48 | |
49 PerformanceEntryTypeMask entryTypes = PerformanceEntry::Invalid; | |
50 if (observerInit.hasEntryTypes() && observerInit.entryTypes().size()) { | |
51 const Vector<String>& sequence = observerInit.entryTypes(); | |
52 for (unsigned i = 0; i < sequence.size(); ++i) | |
esprehn
2015/08/20 08:33:48
You can use range loops.
for (const auto& item :
MikeB
2015/08/25 19:42:42
Done.
| |
53 entryTypes |= PerformanceEntry::toEntryTypeEnum(sequence[i]); | |
54 } | |
55 if (entryTypes == PerformanceEntry::Invalid) { | |
56 exceptionState.throwTypeError("A Performance Observer MUST have a non-em pty entryTypes attribute."); | |
57 return; | |
58 } | |
59 if (m_isRegistered) | |
60 m_performance->unregisterPerformanceObserver(*this); | |
esprehn
2015/08/20 08:33:48
Why unregister? I think you just want to only regi
MikeB
2015/08/25 19:42:42
Done.
| |
61 m_filterOptions = entryTypes; | |
62 m_performance->registerPerformanceObserver(*this); | |
63 m_isRegistered = true; | |
64 } | |
65 | |
66 void PerformanceObserver::disconnect() | |
67 { | |
68 m_performanceEntries.clear(); | |
69 InspectorInstrumentation::didClearAllPerformanceObservations(m_callback->exe cutionContext(), this); | |
70 if (m_performance) | |
71 m_performance->unregisterPerformanceObserver(*this); | |
72 m_isRegistered = false; | |
73 } | |
74 | |
75 void PerformanceObserver::enqueuePerformanceEntry(PerformanceEntry& entry) | |
76 { | |
77 ASSERT(isMainThread()); | |
78 m_performanceEntries.append(&entry); | |
79 if (m_performance) | |
80 m_performance->activateObserver(*this); | |
81 InspectorInstrumentation::didEnqueuePerformanceObserverEntries(m_callback->e xecutionContext(), this); | |
82 } | |
83 | |
84 bool PerformanceObserver::shouldBeSuspended() const | |
85 { | |
86 return m_callback->executionContext() && m_callback->executionContext()->act iveDOMObjectsAreSuspended(); | |
87 } | |
88 | |
89 void PerformanceObserver::deliver() | |
90 { | |
91 ASSERT(!shouldBeSuspended()); | |
92 | |
93 if (m_performanceEntries.isEmpty()) | |
94 return; | |
95 | |
96 PerformanceEntryVector performanceEntries; | |
97 performanceEntries.swap(m_performanceEntries); | |
98 Member<PerformanceObserverEntryList> entryList(new PerformanceObserverEntryL ist(performanceEntries)); | |
99 | |
100 InspectorInstrumentation::willDeliverPerformanceObservations(m_callback->exe cutionContext(), this); | |
101 m_callback->handleEvent(entryList, this); | |
102 InspectorInstrumentation::didDeliverPerformanceObservations(m_callback->exec utionContext()); | |
103 } | |
104 | |
105 DEFINE_TRACE(PerformanceObserver) | |
106 { | |
107 visitor->trace(m_callback); | |
108 visitor->trace(m_performance); | |
109 visitor->trace(m_performanceEntries); | |
110 } | |
111 | |
112 } // namespace blink | |
OLD | NEW |