OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/timing/PerformanceObserver.h" | 5 #include "core/timing/PerformanceObserver.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "bindings/core/v8/PerformanceObserverCallback.h" | 8 #include "bindings/core/v8/PerformanceObserverCallback.h" |
9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
10 #include "core/timing/PerformanceBase.h" | 10 #include "core/timing/PerformanceBase.h" |
11 #include "core/timing/PerformanceEntry.h" | 11 #include "core/timing/PerformanceEntry.h" |
12 #include "core/timing/PerformanceObserverEntryList.h" | 12 #include "core/timing/PerformanceObserverEntryList.h" |
13 #include "core/timing/PerformanceObserverInit.h" | 13 #include "core/timing/PerformanceObserverInit.h" |
14 #include "platform/Timer.h" | 14 #include "platform/Timer.h" |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 PerformanceObserver* PerformanceObserver::create( | 19 PerformanceObserver* PerformanceObserver::create( |
20 ScriptState* scriptState, | 20 ExecutionContext* executionContext, |
21 PerformanceBase* performance, | 21 PerformanceBase* performance, |
22 PerformanceObserverCallback* callback) { | 22 PerformanceObserverCallback* callback) { |
23 ASSERT(isMainThread()); | 23 ASSERT(isMainThread()); |
24 return new PerformanceObserver(scriptState, performance, callback); | 24 return new PerformanceObserver(executionContext, performance, callback); |
25 } | 25 } |
26 | 26 |
27 PerformanceObserver::PerformanceObserver(ScriptState* scriptState, | 27 PerformanceObserver::PerformanceObserver(ExecutionContext* executionContext, |
28 PerformanceBase* performance, | 28 PerformanceBase* performance, |
29 PerformanceObserverCallback* callback) | 29 PerformanceObserverCallback* callback) |
30 : m_scriptState(scriptState), | 30 : m_executionContext(executionContext), |
31 m_callback(this, callback), | 31 m_callback(this, callback), |
32 m_performance(performance), | 32 m_performance(performance), |
33 m_filterOptions(PerformanceEntry::Invalid), | 33 m_filterOptions(PerformanceEntry::Invalid), |
34 m_isRegistered(false) {} | 34 m_isRegistered(false) {} |
35 | 35 |
36 void PerformanceObserver::observe(const PerformanceObserverInit& observerInit, | 36 void PerformanceObserver::observe(const PerformanceObserverInit& observerInit, |
37 ExceptionState& exceptionState) { | 37 ExceptionState& exceptionState) { |
38 if (!m_performance) { | 38 if (!m_performance) { |
39 exceptionState.throwTypeError( | 39 exceptionState.throwTypeError( |
40 "Window may be destroyed? Performance target is invalid."); | 40 "Window may be destroyed? Performance target is invalid."); |
(...skipping 29 matching lines...) Expand all Loading... |
70 } | 70 } |
71 | 71 |
72 void PerformanceObserver::enqueuePerformanceEntry(PerformanceEntry& entry) { | 72 void PerformanceObserver::enqueuePerformanceEntry(PerformanceEntry& entry) { |
73 ASSERT(isMainThread()); | 73 ASSERT(isMainThread()); |
74 m_performanceEntries.append(&entry); | 74 m_performanceEntries.append(&entry); |
75 if (m_performance) | 75 if (m_performance) |
76 m_performance->activateObserver(*this); | 76 m_performance->activateObserver(*this); |
77 } | 77 } |
78 | 78 |
79 bool PerformanceObserver::shouldBeSuspended() const { | 79 bool PerformanceObserver::shouldBeSuspended() const { |
80 return m_scriptState->getExecutionContext() && | 80 return m_executionContext->activeDOMObjectsAreSuspended(); |
81 m_scriptState->getExecutionContext()->activeDOMObjectsAreSuspended(); | |
82 } | 81 } |
83 | 82 |
84 void PerformanceObserver::deliver() { | 83 void PerformanceObserver::deliver() { |
85 ASSERT(!shouldBeSuspended()); | 84 ASSERT(!shouldBeSuspended()); |
86 | 85 |
87 if (m_performanceEntries.isEmpty()) | 86 if (m_performanceEntries.isEmpty()) |
88 return; | 87 return; |
89 | 88 |
90 PerformanceEntryVector performanceEntries; | 89 PerformanceEntryVector performanceEntries; |
91 performanceEntries.swap(m_performanceEntries); | 90 performanceEntries.swap(m_performanceEntries); |
92 PerformanceObserverEntryList* entryList = | 91 PerformanceObserverEntryList* entryList = |
93 new PerformanceObserverEntryList(performanceEntries); | 92 new PerformanceObserverEntryList(performanceEntries); |
94 m_callback->call(this, entryList, this); | 93 m_callback->call(this, entryList, this); |
95 } | 94 } |
96 | 95 |
97 DEFINE_TRACE(PerformanceObserver) { | 96 DEFINE_TRACE(PerformanceObserver) { |
| 97 visitor->trace(m_executionContext); |
98 visitor->trace(m_callback); | 98 visitor->trace(m_callback); |
99 visitor->trace(m_performance); | 99 visitor->trace(m_performance); |
100 visitor->trace(m_performanceEntries); | 100 visitor->trace(m_performanceEntries); |
101 } | 101 } |
102 | 102 |
103 DEFINE_TRACE_WRAPPERS(PerformanceObserver) { | 103 DEFINE_TRACE_WRAPPERS(PerformanceObserver) { |
104 visitor->traceWrappers(m_callback); | 104 visitor->traceWrappers(m_callback); |
105 } | 105 } |
106 | 106 |
107 } // namespace blink | 107 } // namespace blink |
OLD | NEW |