| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/timing/PerformanceServerTiming.h" | 5 #include "core/timing/PerformanceServerTiming.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8ObjectBuilder.h" | 7 #include "bindings/core/v8/V8ObjectBuilder.h" |
| 8 #include "core/timing/PerformanceBase.h" | 8 #include "platform/loader/fetch/ResourceTimingInfo.h" |
| 9 #include "platform/wtf/text/WTFString.h" | 9 #include "platform/wtf/text/WTFString.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 PerformanceServerTiming::PerformanceServerTiming(const String& name, | 13 PerformanceServerTiming::PerformanceServerTiming( |
| 14 const String& metric, | 14 const String& metric, |
| 15 double duration, | 15 double value, |
| 16 const String& description) | 16 const String& description, |
| 17 : PerformanceEntry(name, "server", 0.0, duration), | 17 ShouldAllowTimingDetails shouldAllowTimingDetails) |
| 18 metric_(metric), | 18 : metric_(metric), |
| 19 description_(description) {} | 19 value_(value), |
| 20 description_(description), |
| 21 shouldAllowTimingDetails_(shouldAllowTimingDetails) {} |
| 20 | 22 |
| 21 PerformanceServerTiming::~PerformanceServerTiming() {} | 23 PerformanceServerTiming::~PerformanceServerTiming() {} |
| 22 | 24 |
| 23 String PerformanceServerTiming::metric() const { | 25 String PerformanceServerTiming::metric() const { |
| 24 return metric_; | 26 return metric_; |
| 25 } | 27 } |
| 26 | 28 |
| 27 String PerformanceServerTiming::description() const { | 29 double PerformanceServerTiming::value() const { |
| 28 return description_; | 30 return shouldAllowTimingDetails_ == ShouldAllowTimingDetails::Yes ? value_ |
| 31 : 0.0; |
| 29 } | 32 } |
| 30 | 33 |
| 31 void PerformanceServerTiming::BuildJSONValue(V8ObjectBuilder& builder) const { | 34 String PerformanceServerTiming::description() const { |
| 32 PerformanceEntry::BuildJSONValue(builder); | 35 return shouldAllowTimingDetails_ == ShouldAllowTimingDetails::Yes |
| 36 ? description_ |
| 37 : ""; |
| 38 } |
| 39 |
| 40 ScriptValue PerformanceServerTiming::toJSONForBinding( |
| 41 ScriptState* script_state) const { |
| 42 V8ObjectBuilder builder(script_state); |
| 33 builder.AddString("metric", metric()); | 43 builder.AddString("metric", metric()); |
| 44 builder.AddNumber("value", value()); |
| 34 builder.AddString("description", description()); | 45 builder.AddString("description", description()); |
| 46 return builder.GetScriptValue(); |
| 47 } |
| 48 |
| 49 PerformanceServerTimingVector PerformanceServerTiming::ParseServerTiming( |
| 50 const ResourceTimingInfo& info, |
| 51 ShouldAllowTimingDetails shouldAllowTimingDetails) { |
| 52 PerformanceServerTimingVector entries; |
| 53 if (RuntimeEnabledFeatures::ServerTimingEnabled()) { |
| 54 const ResourceResponse& response = info.FinalResponse(); |
| 55 std::unique_ptr<ServerTimingHeaderVector> headers = ParseServerTimingHeader( |
| 56 response.HttpHeaderField(HTTPNames::Server_Timing)); |
| 57 for (const auto& header : *headers) { |
| 58 entries.push_back(new PerformanceServerTiming( |
| 59 header->metric, header->value, header->description, |
| 60 shouldAllowTimingDetails)); |
| 61 } |
| 62 } |
| 63 return entries; |
| 35 } | 64 } |
| 36 | 65 |
| 37 } // namespace blink | 66 } // namespace blink |
| OLD | NEW |