| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Intel Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef ResourceTimingInfo_h | |
| 32 #define ResourceTimingInfo_h | |
| 33 | |
| 34 #include "platform/CrossThreadCopier.h" | |
| 35 #include "platform/network/ResourceRequest.h" | |
| 36 #include "platform/network/ResourceResponse.h" | |
| 37 #include "wtf/Allocator.h" | |
| 38 #include "wtf/Functional.h" | |
| 39 #include "wtf/Noncopyable.h" | |
| 40 #include "wtf/PtrUtil.h" | |
| 41 #include "wtf/text/AtomicString.h" | |
| 42 #include <memory> | |
| 43 | |
| 44 namespace blink { | |
| 45 | |
| 46 struct CrossThreadResourceTimingInfoData; | |
| 47 | |
| 48 class PLATFORM_EXPORT ResourceTimingInfo | |
| 49 : public RefCounted<ResourceTimingInfo> { | |
| 50 USING_FAST_MALLOC(ResourceTimingInfo); | |
| 51 WTF_MAKE_NONCOPYABLE(ResourceTimingInfo); | |
| 52 | |
| 53 public: | |
| 54 static PassRefPtr<ResourceTimingInfo> create(const AtomicString& type, | |
| 55 const double time, | |
| 56 bool isMainResource) { | |
| 57 return adoptRef(new ResourceTimingInfo(type, time, isMainResource)); | |
| 58 } | |
| 59 static PassRefPtr<ResourceTimingInfo> adopt( | |
| 60 std::unique_ptr<CrossThreadResourceTimingInfoData>); | |
| 61 | |
| 62 // Gets a copy of the data suitable for passing to another thread. | |
| 63 std::unique_ptr<CrossThreadResourceTimingInfoData> copyData() const; | |
| 64 | |
| 65 double initialTime() const { return m_initialTime; } | |
| 66 bool isMainResource() const { return m_isMainResource; } | |
| 67 | |
| 68 void setInitiatorType(const AtomicString& type) { m_type = type; } | |
| 69 const AtomicString& initiatorType() const { return m_type; } | |
| 70 | |
| 71 void setOriginalTimingAllowOrigin( | |
| 72 const AtomicString& originalTimingAllowOrigin) { | |
| 73 m_originalTimingAllowOrigin = originalTimingAllowOrigin; | |
| 74 } | |
| 75 const AtomicString& originalTimingAllowOrigin() const { | |
| 76 return m_originalTimingAllowOrigin; | |
| 77 } | |
| 78 | |
| 79 void setLoadFinishTime(double time) { m_loadFinishTime = time; } | |
| 80 double loadFinishTime() const { return m_loadFinishTime; } | |
| 81 | |
| 82 void setInitialURL(const KURL& url) { m_initialURL = url; } | |
| 83 const KURL& initialURL() const { return m_initialURL; } | |
| 84 | |
| 85 void setFinalResponse(const ResourceResponse& response) { | |
| 86 m_finalResponse = response; | |
| 87 } | |
| 88 const ResourceResponse& finalResponse() const { return m_finalResponse; } | |
| 89 | |
| 90 void addRedirect(const ResourceResponse& redirectResponse, bool crossOrigin); | |
| 91 const Vector<ResourceResponse>& redirectChain() const { | |
| 92 return m_redirectChain; | |
| 93 } | |
| 94 | |
| 95 void addFinalTransferSize(long long encodedDataLength) { | |
| 96 m_transferSize += encodedDataLength; | |
| 97 } | |
| 98 long long transferSize() const { return m_transferSize; } | |
| 99 | |
| 100 void clearLoadTimings() { | |
| 101 m_finalResponse.setResourceLoadTiming(nullptr); | |
| 102 for (ResourceResponse& redirect : m_redirectChain) | |
| 103 redirect.setResourceLoadTiming(nullptr); | |
| 104 } | |
| 105 | |
| 106 private: | |
| 107 ResourceTimingInfo(const AtomicString& type, | |
| 108 const double time, | |
| 109 bool isMainResource) | |
| 110 : m_type(type), | |
| 111 m_initialTime(time), | |
| 112 m_transferSize(0), | |
| 113 m_isMainResource(isMainResource), | |
| 114 m_hasCrossOriginRedirect(false) {} | |
| 115 | |
| 116 AtomicString m_type; | |
| 117 AtomicString m_originalTimingAllowOrigin; | |
| 118 double m_initialTime; | |
| 119 double m_loadFinishTime; | |
| 120 KURL m_initialURL; | |
| 121 ResourceResponse m_finalResponse; | |
| 122 Vector<ResourceResponse> m_redirectChain; | |
| 123 long long m_transferSize; | |
| 124 bool m_isMainResource; | |
| 125 bool m_hasCrossOriginRedirect; | |
| 126 }; | |
| 127 | |
| 128 struct CrossThreadResourceTimingInfoData { | |
| 129 WTF_MAKE_NONCOPYABLE(CrossThreadResourceTimingInfoData); | |
| 130 USING_FAST_MALLOC(CrossThreadResourceTimingInfoData); | |
| 131 | |
| 132 public: | |
| 133 CrossThreadResourceTimingInfoData() {} | |
| 134 | |
| 135 String m_type; | |
| 136 String m_originalTimingAllowOrigin; | |
| 137 double m_initialTime; | |
| 138 double m_loadFinishTime; | |
| 139 KURL m_initialURL; | |
| 140 std::unique_ptr<CrossThreadResourceResponseData> m_finalResponse; | |
| 141 Vector<std::unique_ptr<CrossThreadResourceResponseData>> m_redirectChain; | |
| 142 long long m_transferSize; | |
| 143 bool m_isMainResource; | |
| 144 }; | |
| 145 | |
| 146 template <> | |
| 147 struct CrossThreadCopier<ResourceTimingInfo> { | |
| 148 typedef WTF::PassedWrapper<std::unique_ptr<CrossThreadResourceTimingInfoData>> | |
| 149 Type; | |
| 150 static Type copy(const ResourceTimingInfo& info) { | |
| 151 return WTF::passed(info.copyData()); | |
| 152 } | |
| 153 }; | |
| 154 | |
| 155 } // namespace blink | |
| 156 | |
| 157 #endif | |
| OLD | NEW |