Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: third_party/WebKit/Source/core/timing/Performance.cpp

Issue 2539323002: PerformanceMonitor: do not maintain a vector of frames in the monitor, single ExecutionContext memb… (Closed)
Patch Set: off-by-one in depth fixed Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Intel Inc. All rights reserved. 3 * Copyright (C) 2012 Intel Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 28 matching lines...) Expand all
39 #include "core/frame/LocalFrame.h" 39 #include "core/frame/LocalFrame.h"
40 #include "core/frame/UseCounter.h" 40 #include "core/frame/UseCounter.h"
41 #include "core/html/HTMLFrameOwnerElement.h" 41 #include "core/html/HTMLFrameOwnerElement.h"
42 #include "core/loader/DocumentLoader.h" 42 #include "core/loader/DocumentLoader.h"
43 #include "core/origin_trials/OriginTrials.h" 43 #include "core/origin_trials/OriginTrials.h"
44 #include "core/timing/PerformanceTiming.h" 44 #include "core/timing/PerformanceTiming.h"
45 45
46 static const double kLongTaskThreshold = 0.05; 46 static const double kLongTaskThreshold = 0.05;
47 47
48 static const char kUnknownAttribution[] = "unknown"; 48 static const char kUnknownAttribution[] = "unknown";
49 static const char kAmbugiousAttribution[] = "multiple-contexts"; 49 static const char kAmbiguousAttribution[] = "multiple-contexts";
50 static const char kSameOriginAttribution[] = "same-origin"; 50 static const char kSameOriginAttribution[] = "same-origin";
51 static const char kAncestorAttribution[] = "cross-origin-ancestor"; 51 static const char kAncestorAttribution[] = "cross-origin-ancestor";
52 static const char kDescendantAttribution[] = "cross-origin-descendant"; 52 static const char kDescendantAttribution[] = "cross-origin-descendant";
53 static const char kCrossOriginAttribution[] = "cross-origin-unreachable"; 53 static const char kCrossOriginAttribution[] = "cross-origin-unreachable";
54 54
55 namespace blink { 55 namespace blink {
56 56
57 namespace { 57 namespace {
58 58
59 String getFrameAttribute(HTMLFrameOwnerElement* frameOwner, 59 String getFrameAttribute(HTMLFrameOwnerElement* frameOwner,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 frame2->securityContext()->getSecurityOrigin(); 159 frame2->securityContext()->getSecurityOrigin();
160 return securityOrigin1->canAccess(securityOrigin2); 160 return securityOrigin1->canAccess(securityOrigin2);
161 } 161 }
162 162
163 /** 163 /**
164 * Report sanitized name based on cross-origin policy. 164 * Report sanitized name based on cross-origin policy.
165 * See detailed Security doc here: http://bit.ly/2duD3F7 165 * See detailed Security doc here: http://bit.ly/2duD3F7
166 */ 166 */
167 // static 167 // static
168 std::pair<String, DOMWindow*> Performance::sanitizedAttribution( 168 std::pair<String, DOMWindow*> Performance::sanitizedAttribution(
169 const HeapHashSet<Member<Frame>>& frames, 169 ExecutionContext* taskContext,
170 bool hasMultipleContexts,
170 Frame* observerFrame) { 171 Frame* observerFrame) {
171 if (frames.size() == 0) { 172 if (hasMultipleContexts) {
173 // Unable to attribute, multiple script execution contents were involved.
174 return std::make_pair(kAmbiguousAttribution, nullptr);
175 }
176
177 if (!taskContext || !taskContext->isDocument() ||
178 !toDocument(taskContext)->frame()) {
172 // Unable to attribute as no script was involved. 179 // Unable to attribute as no script was involved.
173 return std::make_pair(kUnknownAttribution, nullptr); 180 return std::make_pair(kUnknownAttribution, nullptr);
174 } 181 }
175 if (frames.size() > 1) { 182
176 // Unable to attribute, multiple script execution contents were involved.
177 return std::make_pair(kAmbugiousAttribution, nullptr);
178 }
179 // Exactly one culprit location, attribute based on origin boundary. 183 // Exactly one culprit location, attribute based on origin boundary.
180 DCHECK_EQ(1u, frames.size()); 184 Frame* culpritFrame = toDocument(taskContext)->frame();
181 Frame* culpritFrame = *frames.begin();
182 DCHECK(culpritFrame); 185 DCHECK(culpritFrame);
183 if (canAccessOrigin(observerFrame, culpritFrame)) { 186 if (canAccessOrigin(observerFrame, culpritFrame)) {
184 // From accessible frames or same origin, return culprit location URL. 187 // From accessible frames or same origin, return culprit location URL.
185 return std::make_pair(kSameOriginAttribution, culpritFrame->domWindow()); 188 return std::make_pair(kSameOriginAttribution, culpritFrame->domWindow());
186 } 189 }
187 // For cross-origin, if the culprit is the descendant or ancestor of 190 // For cross-origin, if the culprit is the descendant or ancestor of
188 // observer then indicate the *closest* cross-origin frame between 191 // observer then indicate the *closest* cross-origin frame between
189 // the observer and the culprit, in the corresponding direction. 192 // the observer and the culprit, in the corresponding direction.
190 if (culpritFrame->tree().isDescendantOf(observerFrame)) { 193 if (culpritFrame->tree().isDescendantOf(observerFrame)) {
191 // If the culprit is a descendant of the observer, then walk up the tree 194 // If the culprit is a descendant of the observer, then walk up the tree
192 // from culprit to observer, and report the *last* cross-origin (from 195 // from culprit to observer, and report the *last* cross-origin (from
193 // observer) frame. If no intermediate cross-origin frame is found, then 196 // observer) frame. If no intermediate cross-origin frame is found, then
194 // report the culprit directly. 197 // report the culprit directly.
195 Frame* lastCrossOriginFrame = culpritFrame; 198 Frame* lastCrossOriginFrame = culpritFrame;
196 for (Frame* frame = culpritFrame; frame != observerFrame; 199 for (Frame* frame = culpritFrame; frame != observerFrame;
197 frame = frame->tree().parent()) { 200 frame = frame->tree().parent()) {
198 if (!canAccessOrigin(observerFrame, frame)) { 201 if (!canAccessOrigin(observerFrame, frame)) {
199 lastCrossOriginFrame = frame; 202 lastCrossOriginFrame = frame;
200 } 203 }
201 } 204 }
202 return std::make_pair(kDescendantAttribution, 205 return std::make_pair(kDescendantAttribution,
203 lastCrossOriginFrame->domWindow()); 206 lastCrossOriginFrame->domWindow());
204 } 207 }
205 if (observerFrame->tree().isDescendantOf(culpritFrame)) { 208 if (observerFrame->tree().isDescendantOf(culpritFrame)) {
206 return std::make_pair(kAncestorAttribution, nullptr); 209 return std::make_pair(kAncestorAttribution, nullptr);
207 } 210 }
208 return std::make_pair(kCrossOriginAttribution, nullptr); 211 return std::make_pair(kCrossOriginAttribution, nullptr);
209 } 212 }
210 213
211 void Performance::reportLongTask( 214 void Performance::reportLongTask(double startTime,
212 double startTime, 215 double endTime,
213 double endTime, 216 ExecutionContext* taskContext,
214 const HeapHashSet<Member<Frame>>& contextFrames) { 217 bool hasMultipleContexts) {
215 std::pair<String, DOMWindow*> attribution = 218 std::pair<String, DOMWindow*> attribution = Performance::sanitizedAttribution(
216 Performance::sanitizedAttribution(contextFrames, frame()); 219 taskContext, hasMultipleContexts, frame());
217 DOMWindow* culpritDomWindow = attribution.second; 220 DOMWindow* culpritDomWindow = attribution.second;
218 if (!culpritDomWindow || !culpritDomWindow->document() || 221 if (!culpritDomWindow || !culpritDomWindow->document() ||
219 !culpritDomWindow->document()->localOwner()) { 222 !culpritDomWindow->document()->localOwner()) {
220 addLongTaskTiming(startTime, endTime, attribution.first, "", "", ""); 223 addLongTaskTiming(startTime, endTime, attribution.first, "", "", "");
221 } else { 224 } else {
222 HTMLFrameOwnerElement* frameOwner = 225 HTMLFrameOwnerElement* frameOwner =
223 culpritDomWindow->document()->localOwner(); 226 culpritDomWindow->document()->localOwner();
224 addLongTaskTiming(startTime, endTime, attribution.first, 227 addLongTaskTiming(startTime, endTime, attribution.first,
225 getFrameAttribute(frameOwner, HTMLNames::srcAttr, false), 228 getFrameAttribute(frameOwner, HTMLNames::srcAttr, false),
226 getFrameAttribute(frameOwner, HTMLNames::idAttr, false), 229 getFrameAttribute(frameOwner, HTMLNames::idAttr, false),
227 getFrameAttribute(frameOwner, HTMLNames::nameAttr, true)); 230 getFrameAttribute(frameOwner, HTMLNames::nameAttr, true));
228 } 231 }
229 } 232 }
230 233
231 } // namespace blink 234 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/timing/Performance.h ('k') | third_party/WebKit/Source/core/timing/PerformanceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698