Skip to content

Commit

Permalink
Use DCHECKs to prevent recursive calls in AXObjectCacheImpl
Browse files Browse the repository at this point in the history
Add DCHECKs to prevent recursion for ProcessDeferredAccessibilityEvents() and UpdateAXForAllDocuments().
By adding the DCHECK to ProcessDeferredAccessibilityEvents(), we
prove that we can remove an early return that was added.

Bug: None
Change-Id: I53c3e500c0a98ea6e273cf887c511d9bc150c797
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3970627
Reviewed-by: David Tseng <dtseng@chromium.org>
Commit-Queue: Aaron Leventhal <aleventhal@chromium.org>
Auto-Submit: Aaron Leventhal <aleventhal@chromium.org>
Reviewed-by: Aaron Leventhal <aleventhal@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1063131}
  • Loading branch information
aleventhal authored and Chromium LUCI CQ committed Oct 25, 2022
1 parent 3a8cf5c commit faed33f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,13 @@ void AXObjectCacheImpl::UpdateLifecycleIfNeeded(Document& document) {
}

void AXObjectCacheImpl::UpdateAXForAllDocuments() {
#if DCHECK_IS_ON()
DCHECK(!IsFrozen())
<< "Don't call UpdateAXForAllDocuments() here; layout and a11y are "
"already clean at the start of serialization.";
DCHECK(!updating_layout_and_ax_) << "Undesirable recursion.";
base::AutoReset<bool> updating(&updating_layout_and_ax_, true);
#endif

// First update the layout for the main and popup document.
UpdateLifecycleIfNeeded(GetDocument());
Expand Down Expand Up @@ -2466,11 +2470,7 @@ void AXObjectCacheImpl::ProcessDeferredAccessibilityEvents(Document& document) {

DCHECK_EQ(document, GetDocument());

if (processing_deferred_events_) {
// TODO(aleventhal) Perhaps the caller should be responsible for this:
// consider changing to a DCHECK.
return;
}
DCHECK(!processing_deferred_events_);

if (IsDirty()) {
if (GetPopupDocumentIfShowing()) {
Expand Down Expand Up @@ -2915,7 +2915,6 @@ void AXObjectCacheImpl::FireAXEventImmediately(
ax::mojom::blink::Action event_from_action,
const BlinkAXEventIntentsSet& event_intents) {
#if DCHECK_IS_ON()
DCHECK(processing_deferred_events_);
// Make sure none of the layout views are in the process of being laid out.
// Notifications should only be sent after the layoutObject has finished
auto* ax_layout_object = DynamicTo<AXLayoutObject>(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ class MODULES_EXPORT AXObjectCacheImpl
std::unique_ptr<AXRelationCache> relation_cache_;

bool processing_deferred_events_ = false;
#if DCHECK_IS_ON()
bool updating_layout_and_ax_ = false;
#endif

// Verified when finalizing.
bool has_been_disposed_ = false;
Expand Down

0 comments on commit faed33f

Please sign in to comment.