| 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 ExecutionContext* execution_context, | 20 ExecutionContext* execution_context, |
| 21 PerformanceBase* performance, | 21 PerformanceBase* performance, |
| 22 PerformanceObserverCallback* callback) { | 22 PerformanceObserverCallback* callback) { |
| 23 ASSERT(IsMainThread()); | 23 DCHECK(IsMainThread()); |
| 24 return new PerformanceObserver(execution_context, performance, callback); | 24 return new PerformanceObserver(execution_context, performance, callback); |
| 25 } | 25 } |
| 26 | 26 |
| 27 PerformanceObserver::PerformanceObserver(ExecutionContext* execution_context, | 27 PerformanceObserver::PerformanceObserver(ExecutionContext* execution_context, |
| 28 PerformanceBase* performance, | 28 PerformanceBase* performance, |
| 29 PerformanceObserverCallback* callback) | 29 PerformanceObserverCallback* callback) |
| 30 : execution_context_(execution_context), | 30 : execution_context_(execution_context), |
| 31 callback_(this, callback), | 31 callback_(this, callback), |
| 32 performance_(performance), | 32 performance_(performance), |
| 33 filter_options_(PerformanceEntry::kInvalid), | 33 filter_options_(PerformanceEntry::kInvalid), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 63 | 63 |
| 64 void PerformanceObserver::disconnect() { | 64 void PerformanceObserver::disconnect() { |
| 65 if (performance_) { | 65 if (performance_) { |
| 66 performance_->UnregisterPerformanceObserver(*this); | 66 performance_->UnregisterPerformanceObserver(*this); |
| 67 } | 67 } |
| 68 performance_entries_.clear(); | 68 performance_entries_.clear(); |
| 69 is_registered_ = false; | 69 is_registered_ = false; |
| 70 } | 70 } |
| 71 | 71 |
| 72 void PerformanceObserver::EnqueuePerformanceEntry(PerformanceEntry& entry) { | 72 void PerformanceObserver::EnqueuePerformanceEntry(PerformanceEntry& entry) { |
| 73 ASSERT(IsMainThread()); | 73 DCHECK(IsMainThread()); |
| 74 performance_entries_.push_back(&entry); | 74 performance_entries_.push_back(&entry); |
| 75 if (performance_) | 75 if (performance_) |
| 76 performance_->ActivateObserver(*this); | 76 performance_->ActivateObserver(*this); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool PerformanceObserver::ShouldBeSuspended() const { | 79 bool PerformanceObserver::ShouldBeSuspended() const { |
| 80 return execution_context_->IsContextSuspended(); | 80 return execution_context_->IsContextSuspended(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void PerformanceObserver::Deliver() { | 83 void PerformanceObserver::Deliver() { |
| 84 ASSERT(!ShouldBeSuspended()); | 84 DCHECK(!ShouldBeSuspended()); |
| 85 | 85 |
| 86 if (performance_entries_.IsEmpty()) | 86 if (performance_entries_.IsEmpty()) |
| 87 return; | 87 return; |
| 88 | 88 |
| 89 PerformanceEntryVector performance_entries; | 89 PerformanceEntryVector performance_entries; |
| 90 performance_entries.swap(performance_entries_); | 90 performance_entries.swap(performance_entries_); |
| 91 PerformanceObserverEntryList* entry_list = | 91 PerformanceObserverEntryList* entry_list = |
| 92 new PerformanceObserverEntryList(performance_entries); | 92 new PerformanceObserverEntryList(performance_entries); |
| 93 callback_->call(this, entry_list, this); | 93 callback_->call(this, entry_list, this); |
| 94 } | 94 } |
| 95 | 95 |
| 96 DEFINE_TRACE(PerformanceObserver) { | 96 DEFINE_TRACE(PerformanceObserver) { |
| 97 visitor->Trace(execution_context_); | 97 visitor->Trace(execution_context_); |
| 98 visitor->Trace(callback_); | 98 visitor->Trace(callback_); |
| 99 visitor->Trace(performance_); | 99 visitor->Trace(performance_); |
| 100 visitor->Trace(performance_entries_); | 100 visitor->Trace(performance_entries_); |
| 101 } | 101 } |
| 102 | 102 |
| 103 DEFINE_TRACE_WRAPPERS(PerformanceObserver) { | 103 DEFINE_TRACE_WRAPPERS(PerformanceObserver) { |
| 104 visitor->TraceWrappers(callback_); | 104 visitor->TraceWrappers(callback_); |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace blink | 107 } // namespace blink |
| OLD | NEW |