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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 m_userTiming(nullptr), | 73 m_userTiming(nullptr), |
| 74 m_timeOrigin(timeOrigin), | 74 m_timeOrigin(timeOrigin), |
| 75 m_observerFilterOptions(PerformanceEntry::Invalid), | 75 m_observerFilterOptions(PerformanceEntry::Invalid), |
| 76 m_deliverObservationsTimer( | 76 m_deliverObservationsTimer( |
| 77 std::move(taskRunner), | 77 std::move(taskRunner), |
| 78 this, | 78 this, |
| 79 &PerformanceBase::deliverObservationsTimerFired) {} | 79 &PerformanceBase::deliverObservationsTimerFired) {} |
| 80 | 80 |
| 81 PerformanceBase::~PerformanceBase() {} | 81 PerformanceBase::~PerformanceBase() {} |
| 82 | 82 |
| 83 PerformanceNavigationTiming::NavigationType PerformanceBase::getNavigationType( | |
| 84 NavigationType type, | |
| 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 } | |
| 104 | |
| 105 const AtomicString& PerformanceBase::interfaceName() const { | 83 const AtomicString& PerformanceBase::interfaceName() const { |
| 106 return EventTargetNames::Performance; | 84 return EventTargetNames::Performance; |
| 107 } | 85 } |
| 108 | 86 |
| 109 PerformanceTiming* PerformanceBase::timing() const { | 87 PerformanceTiming* PerformanceBase::timing() const { |
| 110 return nullptr; | 88 return nullptr; |
| 111 } | 89 } |
| 112 | 90 |
| 113 PerformanceEntryVector PerformanceBase::getEntries() const { | 91 PerformanceEntryVector PerformanceBase::getEntries() { |
| 114 PerformanceEntryVector entries; | 92 PerformanceEntryVector entries; |
| 115 | 93 |
| 116 entries.appendVector(m_resourceTimingBuffer); | 94 entries.appendVector(m_resourceTimingBuffer); |
| 95 if (!m_navigationTiming) | |
| 96 m_navigationTiming = createNavigationTimingInstance(); | |
| 97 // This extra checking is needed when WorkerPerformance | |
| 98 // calls this method. | |
| 117 if (m_navigationTiming) | 99 if (m_navigationTiming) |
| 118 entries.push_back(m_navigationTiming); | 100 entries.push_back(m_navigationTiming); |
| 119 entries.appendVector(m_frameTimingBuffer); | 101 entries.appendVector(m_frameTimingBuffer); |
| 120 | 102 |
| 121 if (m_userTiming) { | 103 if (m_userTiming) { |
| 122 entries.appendVector(m_userTiming->getMarks()); | 104 entries.appendVector(m_userTiming->getMarks()); |
| 123 entries.appendVector(m_userTiming->getMeasures()); | 105 entries.appendVector(m_userTiming->getMeasures()); |
| 124 } | 106 } |
| 125 | 107 |
| 126 std::sort(entries.begin(), entries.end(), | 108 std::sort(entries.begin(), entries.end(), |
| 127 PerformanceEntry::startTimeCompareLessThan); | 109 PerformanceEntry::startTimeCompareLessThan); |
| 128 return entries; | 110 return entries; |
| 129 } | 111 } |
| 130 | 112 |
| 131 PerformanceEntryVector PerformanceBase::getEntriesByType( | 113 PerformanceEntryVector PerformanceBase::getEntriesByType( |
| 132 const String& entryType) { | 114 const String& entryType) { |
| 133 PerformanceEntryVector entries; | 115 PerformanceEntryVector entries; |
| 134 PerformanceEntry::EntryType type = | 116 PerformanceEntry::EntryType type = |
| 135 PerformanceEntry::toEntryTypeEnum(entryType); | 117 PerformanceEntry::toEntryTypeEnum(entryType); |
| 136 | 118 |
| 137 switch (type) { | 119 switch (type) { |
| 138 case PerformanceEntry::Resource: | 120 case PerformanceEntry::Resource: |
| 139 for (const auto& resource : m_resourceTimingBuffer) | 121 for (const auto& resource : m_resourceTimingBuffer) |
| 140 entries.push_back(resource); | 122 entries.push_back(resource); |
| 141 break; | 123 break; |
| 142 case PerformanceEntry::Navigation: | 124 case PerformanceEntry::Navigation: |
| 125 if (!m_navigationTiming) | |
| 126 m_navigationTiming = createNavigationTimingInstance(); | |
| 143 if (m_navigationTiming) | 127 if (m_navigationTiming) |
| 144 entries.push_back(m_navigationTiming); | 128 entries.push_back(m_navigationTiming); |
| 145 break; | 129 break; |
| 146 case PerformanceEntry::Composite: | 130 case PerformanceEntry::Composite: |
| 147 case PerformanceEntry::Render: | 131 case PerformanceEntry::Render: |
| 148 for (const auto& frame : m_frameTimingBuffer) { | 132 for (const auto& frame : m_frameTimingBuffer) { |
| 149 if (type == frame->entryTypeEnum()) { | 133 if (type == frame->entryTypeEnum()) { |
| 150 entries.push_back(frame); | 134 entries.push_back(frame); |
| 151 } | 135 } |
| 152 } | 136 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 return entries; | 172 return entries; |
| 189 | 173 |
| 190 if (entryType.isNull() || type == PerformanceEntry::Resource) { | 174 if (entryType.isNull() || type == PerformanceEntry::Resource) { |
| 191 for (const auto& resource : m_resourceTimingBuffer) { | 175 for (const auto& resource : m_resourceTimingBuffer) { |
| 192 if (resource->name() == name) | 176 if (resource->name() == name) |
| 193 entries.push_back(resource); | 177 entries.push_back(resource); |
| 194 } | 178 } |
| 195 } | 179 } |
| 196 | 180 |
| 197 if (entryType.isNull() || type == PerformanceEntry::Navigation) { | 181 if (entryType.isNull() || type == PerformanceEntry::Navigation) { |
| 182 if (!m_navigationTiming) | |
| 183 m_navigationTiming = createNavigationTimingInstance(); | |
| 198 if (m_navigationTiming && m_navigationTiming->name() == name) | 184 if (m_navigationTiming && m_navigationTiming->name() == name) |
| 199 entries.push_back(m_navigationTiming); | 185 entries.push_back(m_navigationTiming); |
| 200 } | 186 } |
| 201 | 187 |
| 202 if (entryType.isNull() || type == PerformanceEntry::Composite || | 188 if (entryType.isNull() || type == PerformanceEntry::Composite || |
| 203 type == PerformanceEntry::Render) { | 189 type == PerformanceEntry::Render) { |
| 204 for (const auto& frame : m_frameTimingBuffer) { | 190 for (const auto& frame : m_frameTimingBuffer) { |
| 205 if (frame->name() == name && | 191 if (frame->name() == name && |
| 206 (entryType.isNull() || entryType == frame->entryType())) | 192 (entryType.isNull() || entryType == frame->entryType())) |
| 207 entries.push_back(frame); | 193 entries.push_back(frame); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); | 323 double lastRedirectEndTime = lastRedirectTiming->receiveHeadersEnd(); |
| 338 | 324 |
| 339 PerformanceEntry* entry = PerformanceResourceTiming::create( | 325 PerformanceEntry* entry = PerformanceResourceTiming::create( |
| 340 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, | 326 info, timeOrigin(), startTime, lastRedirectEndTime, allowTimingDetails, |
| 341 allowRedirectDetails); | 327 allowRedirectDetails); |
| 342 notifyObserversOfEntry(*entry); | 328 notifyObserversOfEntry(*entry); |
| 343 if (!isResourceTimingBufferFull()) | 329 if (!isResourceTimingBufferFull()) |
| 344 addResourceTimingBuffer(*entry); | 330 addResourceTimingBuffer(*entry); |
| 345 } | 331 } |
| 346 | 332 |
| 347 void PerformanceBase::addNavigationTiming(LocalFrame* frame) { | 333 // Called after loadEventEnd happens. |
| 348 if (!RuntimeEnabledFeatures::performanceNavigationTiming2Enabled()) | 334 void PerformanceBase::notifyNavigationTimingToObservers() { |
|
Kunihiko Sakamoto
2017/02/13 08:22:29
Does this runtime flag still work after your chang
sunjian
2017/02/14 21:29:03
I don't think we need the flag any more since this
Kunihiko Sakamoto
2017/02/15 06:35:30
The flag makes it easier to unship the feature if
sunjian
2017/02/15 20:30:28
Done.
| |
| 349 return; | 335 if (!m_navigationTiming) |
| 350 DCHECK(frame); | 336 m_navigationTiming = createNavigationTimingInstance(); |
| 351 const DocumentLoader* documentLoader = frame->loader().documentLoader(); | 337 if (m_navigationTiming) |
| 352 DCHECK(documentLoader); | 338 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(), navigationTimingInfo->initialURL().getString(), | |
| 393 documentLoadTiming.unloadEventStart(), | |
| 394 documentLoadTiming.unloadEventEnd(), documentLoadTiming.loadEventStart(), | |
| 395 documentLoadTiming.loadEventEnd(), documentLoadTiming.redirectCount(), | |
| 396 documentTiming ? documentTiming->domInteractive() : 0, | |
| 397 documentTiming ? documentTiming->domContentLoadedEventStart() : 0, | |
| 398 documentTiming ? documentTiming->domContentLoadedEventEnd() : 0, | |
| 399 documentTiming ? documentTiming->domComplete() : 0, type, | |
| 400 documentLoadTiming.redirectStart(), documentLoadTiming.redirectEnd(), | |
| 401 documentLoadTiming.fetchStart(), documentLoadTiming.responseEnd(), | |
| 402 allowRedirectDetails, | |
| 403 documentLoadTiming.hasSameOriginAsPreviousDocument(), resourceLoadTiming, | |
| 404 lastRedirectEndTime, finishTime, transferSize, encodedBodyLength, | |
| 405 decodedBodyLength, didReuseConnection); | |
| 406 notifyObserversOfEntry(*m_navigationTiming); | |
| 407 } | 339 } |
| 408 | 340 |
| 409 void PerformanceBase::addFirstPaintTiming(double startTime) { | 341 void PerformanceBase::addFirstPaintTiming(double startTime) { |
| 410 addPaintTiming(PerformancePaintTiming::PaintType::FirstPaint, startTime); | 342 addPaintTiming(PerformancePaintTiming::PaintType::FirstPaint, startTime); |
| 411 } | 343 } |
| 412 | 344 |
| 413 void PerformanceBase::addFirstContentfulPaintTiming(double startTime) { | 345 void PerformanceBase::addFirstContentfulPaintTiming(double startTime) { |
| 414 addPaintTiming(PerformancePaintTiming::PaintType::FirstContentfulPaint, | 346 addPaintTiming(PerformancePaintTiming::PaintType::FirstContentfulPaint, |
| 415 startTime); | 347 startTime); |
| 416 } | 348 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 visitor->trace(m_resourceTimingBuffer); | 533 visitor->trace(m_resourceTimingBuffer); |
| 602 visitor->trace(m_navigationTiming); | 534 visitor->trace(m_navigationTiming); |
| 603 visitor->trace(m_userTiming); | 535 visitor->trace(m_userTiming); |
| 604 visitor->trace(m_observers); | 536 visitor->trace(m_observers); |
| 605 visitor->trace(m_activeObservers); | 537 visitor->trace(m_activeObservers); |
| 606 visitor->trace(m_suspendedObservers); | 538 visitor->trace(m_suspendedObservers); |
| 607 EventTargetWithInlineData::trace(visitor); | 539 EventTargetWithInlineData::trace(visitor); |
| 608 } | 540 } |
| 609 | 541 |
| 610 } // namespace blink | 542 } // namespace blink |
| OLD | NEW |