Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 #include "core/timing/PerformanceUserTiming.h" | 44 #include "core/timing/PerformanceUserTiming.h" |
| 45 #include "platform/RuntimeEnabledFeatures.h" | 45 #include "platform/RuntimeEnabledFeatures.h" |
| 46 #include "platform/network/ResourceResponse.h" | 46 #include "platform/network/ResourceResponse.h" |
| 47 #include "platform/network/ResourceTimingInfo.h" | 47 #include "platform/network/ResourceTimingInfo.h" |
| 48 #include "platform/weborigin/SecurityOrigin.h" | 48 #include "platform/weborigin/SecurityOrigin.h" |
| 49 #include "wtf/CurrentTime.h" | 49 #include "wtf/CurrentTime.h" |
| 50 #include <algorithm> | 50 #include <algorithm> |
| 51 | 51 |
| 52 namespace blink { | 52 namespace blink { |
| 53 | 53 |
| 54 namespace { | |
| 55 | |
| 56 SecurityOrigin* getSecurityOrigin(ExecutionContext* context) { | |
| 57 if (context) | |
| 58 return context->getSecurityOrigin(); | |
| 59 return nullptr; | |
| 60 } | |
| 61 | |
| 62 } // namespace | |
| 63 | |
| 64 using PerformanceObserverVector = HeapVector<Member<PerformanceObserver>>; | 54 using PerformanceObserverVector = HeapVector<Member<PerformanceObserver>>; |
| 65 | 55 |
| 66 static const size_t defaultResourceTimingBufferSize = 150; | 56 static const size_t defaultResourceTimingBufferSize = 150; |
| 67 static const size_t defaultFrameTimingBufferSize = 150; | 57 static const size_t defaultFrameTimingBufferSize = 150; |
| 68 | 58 |
| 69 PerformanceBase::PerformanceBase(double timeOrigin, | 59 PerformanceBase::PerformanceBase(double timeOrigin, |
| 70 RefPtr<WebTaskRunner> taskRunner) | 60 RefPtr<WebTaskRunner> taskRunner) |
| 71 : m_frameTimingBufferSize(defaultFrameTimingBufferSize), | 61 : m_frameTimingBufferSize(defaultFrameTimingBufferSize), |
| 72 m_resourceTimingBufferSize(defaultResourceTimingBufferSize), | 62 m_resourceTimingBufferSize(defaultResourceTimingBufferSize), |
| 73 m_userTiming(nullptr), | 63 m_userTiming(nullptr), |
| 74 m_timeOrigin(timeOrigin), | 64 m_timeOrigin(timeOrigin), |
| 75 m_observerFilterOptions(PerformanceEntry::Invalid), | 65 m_observerFilterOptions(PerformanceEntry::Invalid), |
| 76 m_deliverObservationsTimer( | 66 m_deliverObservationsTimer( |
| 77 std::move(taskRunner), | 67 std::move(taskRunner), |
| 78 this, | 68 this, |
| 79 &PerformanceBase::deliverObservationsTimerFired) {} | 69 &PerformanceBase::deliverObservationsTimerFired) {} |
| 80 | 70 |
| 81 PerformanceBase::~PerformanceBase() {} | 71 PerformanceBase::~PerformanceBase() {} |
| 82 | 72 |
| 83 PerformanceNavigationTiming::NavigationType PerformanceBase::getNavigationType( | 73 const AtomicString& PerformanceBase::interfaceName() const { |
| 84 NavigationType type, | 74 return EventTargetNames::Performance; |
|
panicker
2017/02/03 23:53:52
could you move this to a separate CL?
sunjian
2017/02/10 18:32:46
It's actually easier to keep this change. getNavig
| |
| 85 const Document* document) { | |
| 86 if (document && | |
| 87 document->pageVisibilityState() == PageVisibilityStatePrerender) { | |
| 88 return PerformanceNavigationTiming::NavigationType::Prerender; | |
| 89 } | |
| 90 switch (type) { | |
| 91 case NavigationTypeReload: | |
| 92 return PerformanceNavigationTiming::NavigationType::Reload; | |
| 93 case NavigationTypeBackForward: | |
| 94 return PerformanceNavigationTiming::NavigationType::BackForward; | |
| 95 case NavigationTypeLinkClicked: | |
| 96 case NavigationTypeFormSubmitted: | |
| 97 case NavigationTypeFormResubmitted: | |
| 98 case NavigationTypeOther: | |
| 99 return PerformanceNavigationTiming::NavigationType::Navigate; | |
| 100 } | |
| 101 NOTREACHED(); | |
| 102 return PerformanceNavigationTiming::NavigationType::Navigate; | |
| 103 } | 75 } |
| 104 | 76 |
| 105 const AtomicString& PerformanceBase::interfaceName() const { | 77 SecurityOrigin* PerformanceBase::getSecurityOrigin(ExecutionContext* context) { |
| 106 return EventTargetNames::Performance; | 78 if (context) |
| 79 return context->getSecurityOrigin(); | |
| 80 return nullptr; | |
| 107 } | 81 } |
| 108 | 82 |
| 109 PerformanceTiming* PerformanceBase::timing() const { | 83 PerformanceTiming* PerformanceBase::timing() const { |
| 110 return nullptr; | 84 return nullptr; |
| 111 } | 85 } |
| 112 | 86 |
| 113 PerformanceEntryVector PerformanceBase::getEntries() const { | 87 PerformanceEntryVector PerformanceBase::getEntries() { |
| 114 PerformanceEntryVector entries; | 88 PerformanceEntryVector entries; |
| 115 | 89 |
| 116 entries.appendVector(m_resourceTimingBuffer); | 90 entries.appendVector(m_resourceTimingBuffer); |
| 91 if (!m_navigationTiming) | |
| 92 m_navigationTiming = getNavigationTimingInstance(); | |
| 93 // This extra checking is needed when WorkerPerformance | |
| 94 // calls this method. | |
| 117 if (m_navigationTiming) | 95 if (m_navigationTiming) |
| 118 entries.push_back(m_navigationTiming); | 96 entries.push_back(m_navigationTiming); |
| 119 entries.appendVector(m_frameTimingBuffer); | 97 entries.appendVector(m_frameTimingBuffer); |
| 120 | 98 |
| 121 if (m_userTiming) { | 99 if (m_userTiming) { |
| 122 entries.appendVector(m_userTiming->getMarks()); | 100 entries.appendVector(m_userTiming->getMarks()); |
| 123 entries.appendVector(m_userTiming->getMeasures()); | 101 entries.appendVector(m_userTiming->getMeasures()); |
| 124 } | 102 } |
| 125 | 103 |
| 126 std::sort(entries.begin(), entries.end(), | 104 std::sort(entries.begin(), entries.end(), |
| 127 PerformanceEntry::startTimeCompareLessThan); | 105 PerformanceEntry::startTimeCompareLessThan); |
| 128 return entries; | 106 return entries; |
| 129 } | 107 } |
| 130 | 108 |
| 131 PerformanceEntryVector PerformanceBase::getEntriesByType( | 109 PerformanceEntryVector PerformanceBase::getEntriesByType( |
| 132 const String& entryType) { | 110 const String& entryType) { |
| 133 PerformanceEntryVector entries; | 111 PerformanceEntryVector entries; |
| 134 PerformanceEntry::EntryType type = | 112 PerformanceEntry::EntryType type = |
| 135 PerformanceEntry::toEntryTypeEnum(entryType); | 113 PerformanceEntry::toEntryTypeEnum(entryType); |
| 136 | 114 |
| 137 switch (type) { | 115 switch (type) { |
| 138 case PerformanceEntry::Resource: | 116 case PerformanceEntry::Resource: |
| 139 for (const auto& resource : m_resourceTimingBuffer) | 117 for (const auto& resource : m_resourceTimingBuffer) |
| 140 entries.push_back(resource); | 118 entries.push_back(resource); |
| 141 break; | 119 break; |
| 142 case PerformanceEntry::Navigation: | 120 case PerformanceEntry::Navigation: |
| 121 if (!m_navigationTiming) | |
| 122 m_navigationTiming = getNavigationTimingInstance(); | |
| 143 if (m_navigationTiming) | 123 if (m_navigationTiming) |
| 144 entries.push_back(m_navigationTiming); | 124 entries.push_back(m_navigationTiming); |
| 145 break; | 125 break; |
| 146 case PerformanceEntry::Composite: | 126 case PerformanceEntry::Composite: |
| 147 case PerformanceEntry::Render: | 127 case PerformanceEntry::Render: |
| 148 for (const auto& frame : m_frameTimingBuffer) { | 128 for (const auto& frame : m_frameTimingBuffer) { |
| 149 if (type == frame->entryTypeEnum()) { | 129 if (type == frame->entryTypeEnum()) { |
| 150 entries.push_back(frame); | 130 entries.push_back(frame); |
| 151 } | 131 } |
| 152 } | 132 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 return entries; | 168 return entries; |
| 189 | 169 |
| 190 if (entryType.isNull() || type == PerformanceEntry::Resource) { | 170 if (entryType.isNull() || type == PerformanceEntry::Resource) { |
| 191 for (const auto& resource : m_resourceTimingBuffer) { | 171 for (const auto& resource : m_resourceTimingBuffer) { |
| 192 if (resource->name() == name) | 172 if (resource->name() == name) |
| 193 entries.push_back(resource); | 173 entries.push_back(resource); |
| 194 } | 174 } |
| 195 } | 175 } |
| 196 | 176 |
| 197 if (entryType.isNull() || type == PerformanceEntry::Navigation) { | 177 if (entryType.isNull() || type == PerformanceEntry::Navigation) { |
| 178 if (!m_navigationTiming) | |
| 179 m_navigationTiming = getNavigationTimingInstance(); | |
| 198 if (m_navigationTiming && m_navigationTiming->name() == name) | 180 if (m_navigationTiming && m_navigationTiming->name() == name) |
| 199 entries.push_back(m_navigationTiming); | 181 entries.push_back(m_navigationTiming); |
| 200 } | 182 } |
| 201 | 183 |
| 202 if (entryType.isNull() || type == PerformanceEntry::Composite || | 184 if (entryType.isNull() || type == PerformanceEntry::Composite || |
| 203 type == PerformanceEntry::Render) { | 185 type == PerformanceEntry::Render) { |
| 204 for (const auto& frame : m_frameTimingBuffer) { | 186 for (const auto& frame : m_frameTimingBuffer) { |
| 205 if (frame->name() == name && | 187 if (frame->name() == name && |
| 206 (entryType.isNull() || entryType == frame->entryType())) | 188 (entryType.isNull() || entryType == frame->entryType())) |
| 207 entries.push_back(frame); | 189 entries.push_back(frame); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); | 319 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); |
| 338 | 320 |
| 339 PerformanceEntry* entry = PerformanceResourceTiming::create( | 321 PerformanceEntry* entry = PerformanceResourceTiming::create( |
| 340 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, | 322 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, |
| 341 allowRedirectDetails); | 323 allowRedirectDetails); |
| 342 notifyObserversOfEntry(*entry); | 324 notifyObserversOfEntry(*entry); |
| 343 if (!isResourceTimingBufferFull()) | 325 if (!isResourceTimingBufferFull()) |
| 344 addResourceTimingBuffer(*entry); | 326 addResourceTimingBuffer(*entry); |
| 345 } | 327 } |
| 346 | 328 |
| 347 void PerformanceBase::addNavigationTiming(LocalFrame* frame) { | 329 // Called after loadEventEnd happens. |
| 348 if (!RuntimeEnabledFeatures::performanceNavigationTiming2Enabled()) | 330 void PerformanceBase::notifyNavigationTimingToObserver() { |
|
panicker
2017/02/03 23:53:52
s/ToObserver/ToObservers/
sunjian
2017/02/10 18:32:46
Done.
| |
| 349 return; | 331 if (!m_navigationTiming) |
| 350 DCHECK(frame); | 332 m_navigationTiming = getNavigationTimingInstance(); |
| 351 const DocumentLoader* documentLoader = frame->loader().documentLoader(); | 333 if (m_navigationTiming) |
| 352 DCHECK(documentLoader); | 334 notifyObserversOfEntry(*m_navigationTiming); |
| 353 | |
| 354 const DocumentLoadTiming& documentLoadTiming = documentLoader->timing(); | |
| 355 | |
| 356 const DocumentTiming* documentTiming = | |
| 357 frame->document() ? &(frame->document()->timing()) : nullptr; | |
| 358 | |
| 359 ResourceTimingInfo* navigationTimingInfo = | |
| 360 documentLoader->getNavigationTimingInfo(); | |
| 361 if (!navigationTimingInfo) | |
| 362 return; | |
| 363 | |
| 364 const ResourceResponse& finalResponse = navigationTimingInfo->finalResponse(); | |
| 365 | |
| 366 ResourceLoadTiming* resourceLoadTiming = finalResponse.resourceLoadTiming(); | |
| 367 // Don't create a navigation timing instance when | |
| 368 // resourceLoadTiming is null, which could happen when visiting non-http sites | |
| 369 // such as about:blank or in some error cases. | |
| 370 if (!resourceLoadTiming) | |
| 371 return; | |
| 372 double lastRedirectEndTime = documentLoadTiming.redirectEnd(); | |
| 373 double finishTime = documentLoadTiming.loadEventEnd(); | |
| 374 | |
| 375 ExecutionContext* context = getExecutionContext(); | |
| 376 SecurityOrigin* securityOrigin = getSecurityOrigin(context); | |
| 377 if (!securityOrigin) | |
| 378 return; | |
| 379 | |
| 380 bool allowRedirectDetails = | |
| 381 allowsTimingRedirect(navigationTimingInfo->redirectChain(), finalResponse, | |
| 382 *securityOrigin, context); | |
| 383 | |
| 384 unsigned long long transferSize = navigationTimingInfo->transferSize(); | |
| 385 unsigned long long encodedBodyLength = finalResponse.encodedBodyLength(); | |
| 386 unsigned long long decodedBodyLength = finalResponse.decodedBodyLength(); | |
| 387 bool didReuseConnection = finalResponse.connectionReused(); | |
| 388 PerformanceNavigationTiming::NavigationType type = | |
| 389 getNavigationType(documentLoader->getNavigationType(), frame->document()); | |
| 390 | |
| 391 m_navigationTiming = new PerformanceNavigationTiming( | |
| 392 timeOrigin(), documentLoadTiming.unloadEventStart(), | |
| 393 documentLoadTiming.unloadEventEnd(), documentLoadTiming.loadEventStart(), | |
| 394 documentLoadTiming.loadEventEnd(), documentLoadTiming.redirectCount(), | |
| 395 documentTiming ? documentTiming->domInteractive() : 0, | |
| 396 documentTiming ? documentTiming->domContentLoadedEventStart() : 0, | |
| 397 documentTiming ? documentTiming->domContentLoadedEventEnd() : 0, | |
| 398 documentTiming ? documentTiming->domComplete() : 0, type, | |
| 399 documentLoadTiming.redirectStart(), documentLoadTiming.redirectEnd(), | |
| 400 documentLoadTiming.fetchStart(), documentLoadTiming.responseEnd(), | |
| 401 allowRedirectDetails, | |
| 402 documentLoadTiming.hasSameOriginAsPreviousDocument(), resourceLoadTiming, | |
| 403 lastRedirectEndTime, finishTime, transferSize, encodedBodyLength, | |
| 404 decodedBodyLength, didReuseConnection); | |
| 405 notifyObserversOfEntry(*m_navigationTiming); | |
| 406 } | 335 } |
| 407 | 336 |
| 408 void PerformanceBase::addFirstPaintTiming(double startTime) { | 337 void PerformanceBase::addFirstPaintTiming(double startTime) { |
| 409 addPaintTiming(PerformancePaintTiming::PaintType::FirstPaint, startTime); | 338 addPaintTiming(PerformancePaintTiming::PaintType::FirstPaint, startTime); |
| 410 } | 339 } |
| 411 | 340 |
| 412 void PerformanceBase::addFirstContentfulPaintTiming(double startTime) { | 341 void PerformanceBase::addFirstContentfulPaintTiming(double startTime) { |
| 413 addPaintTiming(PerformancePaintTiming::PaintType::FirstContentfulPaint, | 342 addPaintTiming(PerformancePaintTiming::PaintType::FirstContentfulPaint, |
| 414 startTime); | 343 startTime); |
| 415 } | 344 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 visitor->trace(m_resourceTimingBuffer); | 529 visitor->trace(m_resourceTimingBuffer); |
| 601 visitor->trace(m_navigationTiming); | 530 visitor->trace(m_navigationTiming); |
| 602 visitor->trace(m_userTiming); | 531 visitor->trace(m_userTiming); |
| 603 visitor->trace(m_observers); | 532 visitor->trace(m_observers); |
| 604 visitor->trace(m_activeObservers); | 533 visitor->trace(m_activeObservers); |
| 605 visitor->trace(m_suspendedObservers); | 534 visitor->trace(m_suspendedObservers); |
| 606 EventTargetWithInlineData::trace(visitor); | 535 EventTargetWithInlineData::trace(visitor); |
| 607 } | 536 } |
| 608 | 537 |
| 609 } // namespace blink | 538 } // namespace blink |
| OLD | NEW |