Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef ThreadableLoaderClientWrapper_h | 31 #ifndef ThreadableLoaderClientWrapper_h |
| 32 #define ThreadableLoaderClientWrapper_h | 32 #define ThreadableLoaderClientWrapper_h |
| 33 | 33 |
| 34 #include "core/loader/ThreadableLoaderClient.h" | 34 #include "core/loader/ThreadableLoaderClient.h" |
| 35 #include "core/timing/WorkerGlobalScopePerformance.h" | |
| 36 #include "core/workers/WorkerGlobalScope.h" | |
| 37 #include "platform/heap/Handle.h" | |
| 35 #include "platform/network/ResourceResponse.h" | 38 #include "platform/network/ResourceResponse.h" |
| 36 #include "platform/network/ResourceTimingInfo.h" | 39 #include "platform/network/ResourceTimingInfo.h" |
| 37 #include "wtf/Noncopyable.h" | |
| 38 #include "wtf/PassRefPtr.h" | |
| 39 #include "wtf/ThreadSafeRefCounted.h" | |
| 40 #include "wtf/Threading.h" | 40 #include "wtf/Threading.h" |
| 41 #include "wtf/Vector.h" | 41 #include "wtf/Vector.h" |
| 42 #include <memory> | 42 #include <memory> |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 class ThreadableLoaderClientWrapper : public ThreadSafeRefCounted<ThreadableLoad erClientWrapper> { | 46 class ThreadableLoaderClientWrapper final : public GarbageCollected<ThreadableLo aderClientWrapper> { |
| 47 public: | 47 public: |
| 48 class ResourceTimingClient { | 48 ThreadableLoaderClientWrapper(WorkerGlobalScope& workerGlobalScope, Threadab leLoaderClient* client) |
| 49 public: | 49 : m_workerGlobalScope(workerGlobalScope) |
| 50 virtual void didReceiveResourceTiming(const ResourceTimingInfo&) = 0; | 50 , m_client(client) |
| 51 }; | |
| 52 | |
| 53 static PassRefPtr<ThreadableLoaderClientWrapper> create(ThreadableLoaderClie nt* client) | |
| 54 { | 51 { |
| 55 return adoptRef(new ThreadableLoaderClientWrapper(client)); | |
| 56 } | 52 } |
| 57 | 53 |
| 58 void clearClient() | 54 void clearClient() |
| 59 { | 55 { |
| 60 m_done = true; | 56 m_done = true; |
| 61 m_client = 0; | 57 m_client = nullptr; |
| 62 clearResourceTimingClient(); | |
| 63 } | 58 } |
| 64 | 59 |
| 65 bool done() const | 60 bool done() const { return m_done; } |
| 66 { | |
| 67 return m_done; | |
| 68 } | |
| 69 | |
| 70 void setResourceTimingClient(ResourceTimingClient* client) | |
| 71 { | |
| 72 m_resourceTimingClient = client; | |
| 73 } | |
| 74 | |
| 75 void clearResourceTimingClient() | |
| 76 { | |
| 77 m_resourceTimingClient = nullptr; | |
| 78 } | |
| 79 | 61 |
| 80 void didSendData(unsigned long long bytesSent, unsigned long long totalBytes ToBeSent) | 62 void didSendData(unsigned long long bytesSent, unsigned long long totalBytes ToBeSent) |
| 81 { | 63 { |
| 82 if (m_client) | 64 if (m_client) |
| 83 m_client->didSendData(bytesSent, totalBytesToBeSent); | 65 m_client->didSendData(bytesSent, totalBytesToBeSent); |
| 84 } | 66 } |
| 85 | 67 |
| 86 void didReceiveResponse(unsigned long identifier, std::unique_ptr<CrossThrea dResourceResponseData> responseData, std::unique_ptr<WebDataConsumerHandle> hand le) | 68 void didReceiveResponse(unsigned long identifier, std::unique_ptr<CrossThrea dResourceResponseData> responseData, std::unique_ptr<WebDataConsumerHandle> hand le) |
| 87 { | 69 { |
| 88 ResourceResponse response(responseData.get()); | 70 ResourceResponse response(responseData.get()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 117 |
| 136 void didDownloadData(int dataLength) | 118 void didDownloadData(int dataLength) |
| 137 { | 119 { |
| 138 if (m_client) | 120 if (m_client) |
| 139 m_client->didDownloadData(dataLength); | 121 m_client->didDownloadData(dataLength); |
| 140 } | 122 } |
| 141 | 123 |
| 142 void didReceiveResourceTiming(std::unique_ptr<CrossThreadResourceTimingInfoD ata> timingData) | 124 void didReceiveResourceTiming(std::unique_ptr<CrossThreadResourceTimingInfoD ata> timingData) |
| 143 { | 125 { |
| 144 std::unique_ptr<ResourceTimingInfo> info(ResourceTimingInfo::adopt(std:: move(timingData))); | 126 std::unique_ptr<ResourceTimingInfo> info(ResourceTimingInfo::adopt(std:: move(timingData))); |
| 145 | 127 if (m_client) { |
| 146 if (m_resourceTimingClient) | 128 WorkerGlobalScopePerformance::performance(*m_workerGlobalScope)->add ResourceTiming(*info); |
| 147 m_resourceTimingClient->didReceiveResourceTiming(*info); | 129 m_client->didReceiveResourceTiming(*info); |
| 130 } | |
| 148 } | 131 } |
| 149 | 132 |
| 150 protected: | 133 DEFINE_INLINE_TRACE() |
| 151 explicit ThreadableLoaderClientWrapper(ThreadableLoaderClient* client) | |
| 152 : m_client(client) | |
| 153 , m_resourceTimingClient(nullptr) | |
| 154 , m_done(false) | |
| 155 { | 134 { |
| 135 visitor->trace(m_workerGlobalScope); | |
| 156 } | 136 } |
| 157 | 137 |
| 158 ThreadableLoaderClient* m_client; | 138 private: |
| 159 ResourceTimingClient* m_resourceTimingClient; | 139 Member<WorkerGlobalScope> m_workerGlobalScope; |
| 160 bool m_done; | 140 ThreadableLoaderClient* m_client = nullptr; |
|
haraken
2016/07/14 08:33:17
Is it guaranteed that clearClient() is explicitly
yhirano
2016/07/14 08:55:41
This class is inistantiated only in WorkerThreadab
| |
| 141 bool m_done = false; | |
| 161 }; | 142 }; |
| 162 | 143 |
| 163 } // namespace blink | 144 } // namespace blink |
| 164 | 145 |
| 165 #endif // ThreadableLoaderClientWrapper_h | 146 #endif // ThreadableLoaderClientWrapper_h |
| OLD | NEW |