Chromium Code Reviews| 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 | |
| 7 #include "bindings/core/v8/V8ObjectBuilder.h" | 6 #include "bindings/core/v8/V8ObjectBuilder.h" |
| 8 #include "core/timing/PerformanceBase.h" | 7 #include "platform/loader/fetch/ResourceTimingInfo.h" |
| 9 #include "platform/wtf/text/WTFString.h" | 8 #include "platform/wtf/text/WTFString.h" |
| 10 | 9 |
| 11 namespace blink { | 10 namespace blink { |
| 12 | 11 |
| 13 PerformanceServerTiming::PerformanceServerTiming(const String& name, | 12 PerformanceServerTiming::PerformanceServerTiming(const String& metric, |
| 14 const String& metric, | 13 double value, |
| 15 double duration, | 14 const String& description, |
| 16 const String& description) | 15 bool allow_timing_details) |
| 17 : PerformanceEntry(name, "server", 0.0, duration), | 16 : metric_(metric), |
| 18 metric_(metric), | 17 value_(value), |
| 19 description_(description) {} | 18 description_(description), |
| 19 allow_timing_details_(allow_timing_details) {} | |
| 20 | 20 |
| 21 PerformanceServerTiming::~PerformanceServerTiming() {} | 21 PerformanceServerTiming::~PerformanceServerTiming() {} |
| 22 | 22 |
| 23 String PerformanceServerTiming::metric() const { | 23 String PerformanceServerTiming::metric() const { |
| 24 return metric_; | 24 return metric_; |
| 25 } | 25 } |
| 26 | 26 |
| 27 double PerformanceServerTiming::value() const { | |
| 28 return allow_timing_details_ ? value_ : 0.0; | |
| 29 } | |
| 30 | |
| 27 String PerformanceServerTiming::description() const { | 31 String PerformanceServerTiming::description() const { |
| 28 return description_; | 32 return allow_timing_details_ ? description_ : ""; |
| 29 } | 33 } |
| 30 | 34 |
| 31 void PerformanceServerTiming::BuildJSONValue(V8ObjectBuilder& builder) const { | 35 void PerformanceServerTiming::BuildJSONValue(V8ObjectBuilder& builder) const { |
| 32 PerformanceEntry::BuildJSONValue(builder); | |
| 33 builder.AddString("metric", metric()); | 36 builder.AddString("metric", metric()); |
| 37 builder.AddNumber("value", value()); | |
| 34 builder.AddString("description", description()); | 38 builder.AddString("description", description()); |
| 35 } | 39 } |
| 36 | 40 |
| 41 PerformanceServerTimingVector PerformanceServerTiming::ParseServerTiming( | |
| 42 const ResourceTimingInfo& info, | |
| 43 ShouldAllowTimingDetails shouldAllowTimingDetails) { | |
| 44 PerformanceServerTimingVector entries; | |
| 45 if (RuntimeEnabledFeatures::ServerTimingEnabled()) { | |
| 46 const ResourceResponse& response = info.FinalResponse(); | |
| 47 std::unique_ptr<ServerTimingHeaderVector> headers = ParseServerTimingHeader( | |
| 48 response.HttpHeaderField(HTTPNames::Server_Timing)); | |
| 49 for (const auto& header : *headers) { | |
| 50 entries.push_back(new PerformanceServerTiming( | |
| 51 header->metric, header->value, header->description, | |
| 52 shouldAllowTimingDetails == ShouldAllowTimingDetails::Yes ? true | |
| 53 : false)); | |
|
Yoav Weiss
2017/06/29 16:23:21
Might be better to avoid translating the enum back
| |
| 54 } | |
| 55 } | |
| 56 return entries; | |
| 57 } | |
| 58 | |
| 37 } // namespace blink | 59 } // namespace blink |
| OLD | NEW |