#include "content/browser/accessibility/accessibility_tree_snapshot_combiner.h"
#include "base/metrics/histogram_macros.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
namespace content {
AccessibilityTreeSnapshotCombiner::AccessibilityTreeSnapshotCombiner(
base::OnceCallback<void(ui::AXTreeUpdate&)> callback,
mojom::SnapshotAccessibilityTreeParamsPtr params)
: callback_(std::move(callback)), params_(std::move(params)) {}
void AccessibilityTreeSnapshotCombiner::RequestSnapshotOnRenderFrameHost(
RenderFrameHostImpl* rfhi) {
rfhi->RequestAXTreeSnapshot(
base::BindOnce(&AccessibilityTreeSnapshotCombiner::
ReceiveSnapshotFromRenderFrameHost,
this, rfhi->AccessibilityIsRootFrame()),
params_.Clone());
}
void AccessibilityTreeSnapshotCombiner::ReceiveSnapshotFromRenderFrameHost(
bool is_root_frame,
ui::AXTreeUpdate& snapshot) {
combiner_.AddTree(snapshot, is_root_frame);
}
AccessibilityTreeSnapshotCombiner::~AccessibilityTreeSnapshotCombiner() {
combiner_.Combine();
CHECK(combiner_.combined());
ui::AXTreeUpdate update = std::move(combiner_.combined().value());
std::move(callback_).Run(update);
}
}