Commit f8e70c7f authored by Hayato Ito's avatar Hayato Ito Committed by Commit Bot

Make slot-assignment-recalc-forbidden scope on a per-document basis

We need to increment (and decrement) a counter on a per-document basis because call
stack can span across different documents.

BUG 776656, 845770

Change-Id: Ib9e89448217e7e335ba3c32c9775c9aa9c8f28cf
Reviewed-on: https://chromium-review.googlesource.com/1069959Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Hayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561014}
parent 8f1112c1
...@@ -676,6 +676,9 @@ Document::Document(const DocumentInit& initializer, ...@@ -676,6 +676,9 @@ Document::Document(const DocumentInit& initializer,
engagement_level_(mojom::blink::EngagementLevel::NONE), engagement_level_(mojom::blink::EngagementLevel::NONE),
secure_context_state_(SecureContextState::kUnknown), secure_context_state_(SecureContextState::kUnknown),
ukm_source_id_(ukm::UkmRecorder::GetNewSourceID()), ukm_source_id_(ukm::UkmRecorder::GetNewSourceID()),
#if DCHECK_IS_ON()
slot_assignment_recalc_forbidden_recursion_depth_(0),
#endif
needs_to_record_ukm_outlive_time_(false) { needs_to_record_ukm_outlive_time_(false) {
if (frame_) { if (frame_) {
DCHECK(frame_->GetPage()); DCHECK(frame_->GetPage());
...@@ -2094,7 +2097,8 @@ void Document::UpdateStyleAndLayoutTree() { ...@@ -2094,7 +2097,8 @@ void Document::UpdateStyleAndLayoutTree() {
GetSlotAssignmentEngine().RecalcSlotAssignments(); GetSlotAssignmentEngine().RecalcSlotAssignments();
} }
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
SlotAssignmentRecalcForbiddenScope forbid_slot_assignment_recalc; NestingLevelIncrementer slot_assignment_recalc_forbidden_scope(
slot_assignment_recalc_forbidden_recursion_depth_);
#endif #endif
if (!NeedsLayoutTreeUpdate()) { if (!NeedsLayoutTreeUpdate()) {
......
...@@ -1412,6 +1412,12 @@ class CORE_EXPORT Document : public ContainerNode, ...@@ -1412,6 +1412,12 @@ class CORE_EXPORT Document : public ContainerNode,
SlotAssignmentEngine& GetSlotAssignmentEngine(); SlotAssignmentEngine& GetSlotAssignmentEngine();
#if DCHECK_IS_ON()
bool IsSlotAssignmentRecalcForbidden() {
return slot_assignment_recalc_forbidden_recursion_depth_ > 0;
}
#endif
protected: protected:
Document(const DocumentInit&, DocumentClassFlags = kDefaultDocumentClass); Document(const DocumentInit&, DocumentClassFlags = kDefaultDocumentClass);
...@@ -1809,6 +1815,10 @@ class CORE_EXPORT Document : public ContainerNode, ...@@ -1809,6 +1815,10 @@ class CORE_EXPORT Document : public ContainerNode,
std::unique_ptr<ukm::UkmRecorder> ukm_recorder_; std::unique_ptr<ukm::UkmRecorder> ukm_recorder_;
int64_t ukm_source_id_; int64_t ukm_source_id_;
#if DCHECK_IS_ON()
unsigned slot_assignment_recalc_forbidden_recursion_depth_;
#endif
bool needs_to_record_ukm_outlive_time_; bool needs_to_record_ukm_outlive_time_;
Member<Policy> policy_; Member<Policy> policy_;
......
...@@ -219,8 +219,7 @@ void SlotAssignment::RecalcAssignment() { ...@@ -219,8 +219,7 @@ void SlotAssignment::RecalcAssignment() {
if (!needs_assignment_recalc_) if (!needs_assignment_recalc_)
return; return;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
DCHECK( DCHECK(!owner_->GetDocument().IsSlotAssignmentRecalcForbidden());
!SlotAssignmentRecalcForbiddenScope::IsSlotAssignmentRecalcForbidden());
#endif #endif
needs_assignment_recalc_ = false; needs_assignment_recalc_ = false;
...@@ -385,18 +384,4 @@ void SlotAssignment::Trace(blink::Visitor* visitor) { ...@@ -385,18 +384,4 @@ void SlotAssignment::Trace(blink::Visitor* visitor) {
visitor->Trace(owner_); visitor->Trace(owner_);
} }
#if DCHECK_IS_ON()
unsigned SlotAssignmentRecalcForbiddenScope::g_main_thread_counter_ = 0;
unsigned& SlotAssignmentRecalcForbiddenScope::GetMutableCounter() {
if (IsMainThread())
return g_main_thread_counter_;
DEFINE_THREAD_SAFE_STATIC_LOCAL(WTF::ThreadSpecific<unsigned>,
slot_assignment_recalc_forbidden_counter_,
());
return *slot_assignment_recalc_forbidden_counter_;
}
#endif
} // namespace blink } // namespace blink
...@@ -87,41 +87,6 @@ class SlotAssignment final : public GarbageCollected<SlotAssignment> { ...@@ -87,41 +87,6 @@ class SlotAssignment final : public GarbageCollected<SlotAssignment> {
unsigned slot_count_ : 30; unsigned slot_count_ : 30;
}; };
#if DCHECK_IS_ON()
class SlotAssignmentRecalcForbiddenScope final {
STACK_ALLOCATED();
DISALLOW_COPY_AND_ASSIGN(SlotAssignmentRecalcForbiddenScope);
public:
SlotAssignmentRecalcForbiddenScope() { Enter(); }
~SlotAssignmentRecalcForbiddenScope() { Exit(); }
static bool IsSlotAssignmentRecalcForbidden() {
return GetMutableCounter() > 0;
}
private:
static void Enter() {
if (IsMainThread()) {
++g_main_thread_counter_;
} else {
++GetMutableCounter();
}
}
static void Exit() {
DCHECK(IsSlotAssignmentRecalcForbidden());
if (IsMainThread()) {
--g_main_thread_counter_;
} else {
--GetMutableCounter();
}
}
static unsigned& GetMutableCounter();
static unsigned g_main_thread_counter_;
};
#endif
} // namespace blink } // namespace blink
#endif // HTMLSlotAssignment_h #endif // HTMLSlotAssignment_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment