Skip to content

Commit

Permalink
Move where performance entry's reponseEnd is recorded. (#3782)
Browse files Browse the repository at this point in the history
b/231748800
  • Loading branch information
aee-google authored Jul 10, 2024
1 parent 8c1fce2 commit 8e1e3ca
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
</head>
<body>
<script>
const checkNextHopProtocol = expectedValues => {
const entries = window.performance.getEntries();
assertEqual(expectedValues.length, entries.length);
expectedValues.forEach((expectedValue, i) => {
assertEqual(expectedValue, entries[i].nextHopProtocol);
});
};

setupFinished();
checkNextHopProtocol([undefined]);
const entries = window.performance.getEntries();
assertEqual(1, entries.length);
assertEqual(undefined, entries[0].responseEnd);
assertEqual(undefined, entries[0].nextHopProtocol);
fetch('performance_resource_timing_test.html')
.then(() => {
checkNextHopProtocol([undefined, 'http/1.0']);
const entries = window.performance.getEntries();
assertEqual(2, entries.length);
assertEqual(undefined, entries[0].responseEnd);
assertEqual(undefined, entries[0].nextHopProtocol);
assertTrue(entries[1].responseEnd > 0);
assertEqual('http/1.0', entries[1].nextHopProtocol);
}).then(onEndTest).catch(notReached);
</script>
</body>
Expand Down
8 changes: 6 additions & 2 deletions cobalt/dom/performance_resource_timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ PerformanceResourceTiming::PerformanceResourceTiming(
cache_mode_(kPerformanceResourceTimingCacheMode),
timing_info_(timing_info),
time_origin_(time_origin),
timing_info_response_end_(performance->Now()) {}
fallback_response_end_(performance->Now()) {}

std::string PerformanceResourceTiming::initiator_type() const {
return initiator_type_;
Expand Down Expand Up @@ -114,7 +114,11 @@ DOMHighResTimeStamp PerformanceResourceTiming::response_start() const {
}

DOMHighResTimeStamp PerformanceResourceTiming::response_end() const {
return timing_info_response_end_;
if (timing_info_.response_end.is_null()) {
return fallback_response_end_;
}
return Performance::MonotonicTimeToDOMHighResTimeStamp(
time_origin_, timing_info_.response_end);
}

uint64_t PerformanceResourceTiming::transfer_size() const {
Expand Down
2 changes: 1 addition & 1 deletion cobalt/dom/performance_resource_timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PerformanceResourceTiming : public PerformanceEntry {
std::string requested_url_;
net::LoadTimingInfo timing_info_;
base::TimeTicks time_origin_;
DOMHighResTimeStamp timing_info_response_end_;
DOMHighResTimeStamp fallback_response_end_;

DISALLOW_COPY_AND_ASSIGN(PerformanceResourceTiming);
};
Expand Down
1 change: 1 addition & 0 deletions net/base/load_timing_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ struct NET_EXPORT LoadTimingInfo {
uint64_t encoded_body_size;
std::string alpn_negotiated_protocol;
std::string connection_info_string;
base::TimeTicks response_end;
#endif // defined(STARBOARD)
};

Expand Down
1 change: 1 addition & 0 deletions net/url_request/url_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ void URLRequest::NotifyRequestCompleted() {
load_timing_info_.encoded_body_size = static_cast<uint64_t>(GetTotalReceivedBytes());
load_timing_info_.alpn_negotiated_protocol = response_info_.alpn_negotiated_protocol;
load_timing_info_.connection_info_string = HttpResponseInfo::ConnectionInfoToString(response_info_.connection_info);
load_timing_info_.response_end = base::TimeTicks::Now();
if (load_timing_info_callback_) {
load_timing_info_callback_.Run(load_timing_info_);
}
Expand Down

0 comments on commit 8e1e3ca

Please sign in to comment.