Commit 43751d36 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Use LocalFrame consistently in MeasureMemoryDelegate

Bug: 1049093
Change-Id: I0aff32daa6558e0984c75f93b5de744859e14d01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2098786
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749766}
parent 701b28b7
...@@ -76,7 +76,7 @@ bool MeasureMemoryDelegate::ShouldMeasure(v8::Local<v8::Context> context) { ...@@ -76,7 +76,7 @@ bool MeasureMemoryDelegate::ShouldMeasure(v8::Local<v8::Context> context) {
namespace { namespace {
// Helper functions for constructing a memory measurement result. // Helper functions for constructing a memory measurement result.
const Frame* GetFrame(v8::Local<v8::Context> context) { const LocalFrame* GetFrame(v8::Local<v8::Context> context) {
ExecutionContext* execution_context = ExecutionContext::From(context); ExecutionContext* execution_context = ExecutionContext::From(context);
if (!execution_context) { if (!execution_context) {
// The context was detached. Ignore it. // The context was detached. Ignore it.
...@@ -86,18 +86,17 @@ const Frame* GetFrame(v8::Local<v8::Context> context) { ...@@ -86,18 +86,17 @@ const Frame* GetFrame(v8::Local<v8::Context> context) {
return Document::From(execution_context)->GetFrame(); return Document::From(execution_context)->GetFrame();
} }
String GetUrl(const Frame* frame) { String GetUrl(const LocalFrame* frame) {
// TODO(ulan): Refactor the rest of the code to make the parameter LocalFrame. if (frame->IsCrossOriginToParentFrame()) {
const LocalFrame* local_frame = To<LocalFrame>(frame);
if (local_frame->IsCrossOriginToParentFrame()) {
// The function must be called only for the first cross-origin iframe on // The function must be called only for the first cross-origin iframe on
// the path down from the main frame. Thus the parent frame is guaranteed // the path down from the main frame. Thus the parent frame is guaranteed
// to be the same origin as the main frame. // to be the same origin as the main frame.
DCHECK(!local_frame->Tree().Parent()->IsCrossOriginToMainFrame()); DCHECK(!frame->Tree().Parent() ||
base::Optional<String> url = local_frame->FirstUrlCrossOriginToParent(); !frame->Tree().Parent()->IsCrossOriginToMainFrame());
base::Optional<String> url = frame->FirstUrlCrossOriginToParent();
return url ? url.value() : ""; return url ? url.value() : "";
} }
return local_frame->GetDocument()->Url().GetString(); return frame->GetDocument()->Url().GetString();
} }
// To avoid information leaks cross-origin iframes are considered opaque for // To avoid information leaks cross-origin iframes are considered opaque for
...@@ -111,9 +110,9 @@ String GetUrl(const Frame* frame) { ...@@ -111,9 +110,9 @@ String GetUrl(const Frame* frame) {
// so the frame corresponding to the current context is returned. // so the frame corresponding to the current context is returned.
// //
// The function returns nullptr if the context was detached. // The function returns nullptr if the context was detached.
const Frame* GetAttributionFrame(const Frame* main_frame, const LocalFrame* GetAttributionFrame(const LocalFrame* main_frame,
v8::Local<v8::Context> context) { v8::Local<v8::Context> context) {
const Frame* frame = GetFrame(context); const LocalFrame* frame = GetFrame(context);
if (!frame) { if (!frame) {
// The context was detached. Ignore it. // The context was detached. Ignore it.
return nullptr; return nullptr;
...@@ -124,12 +123,14 @@ const Frame* GetAttributionFrame(const Frame* main_frame, ...@@ -124,12 +123,14 @@ const Frame* GetAttributionFrame(const Frame* main_frame,
return nullptr; return nullptr;
} }
// Walk up the tree and find the topmost cross-origin ancestor frame. // Walk up the tree and find the topmost cross-origin ancestor frame.
const Frame* result = frame; const LocalFrame* result = frame;
frame = frame->Tree().Parent(); // The parent is guaranteed to be LocalFrame because |frame| and
// |main_frame| belong to the same JS agent.
frame = To<LocalFrame>(frame->Tree().Parent());
while (frame) { while (frame) {
if (frame->IsCrossOriginToMainFrame()) if (frame->IsCrossOriginToMainFrame())
result = frame; result = frame;
frame = frame->Tree().Parent(); frame = To<LocalFrame>(frame->Tree().Parent());
} }
return result; return result;
} }
...@@ -137,13 +138,14 @@ const Frame* GetAttributionFrame(const Frame* main_frame, ...@@ -137,13 +138,14 @@ const Frame* GetAttributionFrame(const Frame* main_frame,
// Return per-frame sizes based on the given per-context size. // Return per-frame sizes based on the given per-context size.
// TODO(ulan): Revisit this after Origin Trial and see if the results // TODO(ulan): Revisit this after Origin Trial and see if the results
// are precise enough or if we need to additionally group by JS agent. // are precise enough or if we need to additionally group by JS agent.
HeapHashMap<Member<const Frame>, size_t> GroupByFrame( HeapHashMap<Member<const LocalFrame>, size_t> GroupByFrame(
const Frame* main_frame, const LocalFrame* main_frame,
const std::vector<std::pair<v8::Local<v8::Context>, size_t>>& const std::vector<std::pair<v8::Local<v8::Context>, size_t>>&
context_sizes) { context_sizes) {
HeapHashMap<Member<const Frame>, size_t> per_frame; HeapHashMap<Member<const LocalFrame>, size_t> per_frame;
for (const auto& context_size : context_sizes) { for (const auto& context_size : context_sizes) {
const Frame* frame = GetAttributionFrame(main_frame, context_size.first); const LocalFrame* frame =
GetAttributionFrame(main_frame, context_size.first);
if (!frame) { if (!frame) {
// The context was detached. Ignore it. // The context was detached. Ignore it.
continue; continue;
...@@ -181,7 +183,7 @@ void MeasureMemoryDelegate::MeasurementComplete( ...@@ -181,7 +183,7 @@ void MeasureMemoryDelegate::MeasurementComplete(
return; return;
} }
v8::Local<v8::Context> context = context_.NewLocal(isolate_); v8::Local<v8::Context> context = context_.NewLocal(isolate_);
const Frame* frame = GetFrame(context); const LocalFrame* frame = GetFrame(context);
if (!frame) { if (!frame) {
// The context was detached in the meantime. // The context was detached in the meantime.
return; return;
...@@ -195,7 +197,7 @@ void MeasureMemoryDelegate::MeasurementComplete( ...@@ -195,7 +197,7 @@ void MeasureMemoryDelegate::MeasurementComplete(
MeasureMemory* result = MeasureMemory::Create(); MeasureMemory* result = MeasureMemory::Create();
result->setBytes(total_size + unattributed_size); result->setBytes(total_size + unattributed_size);
HeapVector<Member<MeasureMemoryBreakdown>> breakdown; HeapVector<Member<MeasureMemoryBreakdown>> breakdown;
HeapHashMap<Member<const Frame>, size_t> per_frame( HeapHashMap<Member<const LocalFrame>, size_t> per_frame(
GroupByFrame(frame, context_sizes)); GroupByFrame(frame, context_sizes));
size_t attributed_size = 0; size_t attributed_size = 0;
const String kWindow("Window"); const String kWindow("Window");
......
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