| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 namespace blink { | 49 namespace blink { |
| 50 | 50 |
| 51 class ResourceError; | 51 class ResourceError; |
| 52 class ResourceRequest; | 52 class ResourceRequest; |
| 53 class ResourceResponse; | 53 class ResourceResponse; |
| 54 class WorkerGlobalScope; | 54 class WorkerGlobalScope; |
| 55 class WorkerLoaderProxy; | 55 class WorkerLoaderProxy; |
| 56 struct CrossThreadResourceRequestData; | 56 struct CrossThreadResourceRequestData; |
| 57 struct CrossThreadResourceTimingInfoData; | 57 struct CrossThreadResourceTimingInfoData; |
| 58 | 58 |
| 59 // TODO(yhirano): Draw a diagram to illustrate the class relationship. | 59 // A WorkerThreadableLoader is a ThreadableLoader implementation intended to |
| 60 // TODO(yhirano): Rename inner classes so that readers can see in which thread | 60 // be used in a WebWorker thread. Because Blink's ResourceFetcher and |
| 61 // they are living easily. | 61 // ResourceLoader work only in the main thread, a WorkerThreadableLoader holds |
| 62 // a ThreadableLoader in the main thread and delegates tasks asynchronously |
| 63 // to the loader. |
| 64 // |
| 65 // CTP: CrossThreadPersistent |
| 66 // CTWP: CrossThreadWeakPersistent |
| 67 // |
| 68 // ---------------------------------------------------------------- |
| 69 // +------------------------+ |
| 70 // raw ptr | ThreadableLoaderClient | |
| 71 // +--------> | worker thread | |
| 72 // | +------------------------+ |
| 73 // | |
| 74 // +----+------------------+ CTP +------------------------+ |
| 75 // + WorkerThreadableLoader|<--------+ MainThreadLoaderHolder | |
| 76 // | worker thread +-------->| main thread | |
| 77 // +-----------------------+ CTWP +----------------------+-+ |
| 78 // | |
| 79 // +------------------+ | Member |
| 80 // | ThreadableLoader | <---+ |
| 81 // | main thread | |
| 82 // +------------------+ |
| 83 // |
| 62 class WorkerThreadableLoader final : public ThreadableLoader { | 84 class WorkerThreadableLoader final : public ThreadableLoader { |
| 63 public: | 85 public: |
| 64 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ
est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa
derOptions&); | 86 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ
est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa
derOptions&); |
| 65 static WorkerThreadableLoader* create(WorkerGlobalScope& workerGlobalScope,
ThreadableLoaderClient* client, const ThreadableLoaderOptions& options, const Re
sourceLoaderOptions& resourceLoaderOptions) | 87 static WorkerThreadableLoader* create(WorkerGlobalScope& workerGlobalScope,
ThreadableLoaderClient* client, const ThreadableLoaderOptions& options, const Re
sourceLoaderOptions& resourceLoaderOptions) |
| 66 { | 88 { |
| 67 return new WorkerThreadableLoader(workerGlobalScope, client, options, re
sourceLoaderOptions, LoadAsynchronously); | 89 return new WorkerThreadableLoader(workerGlobalScope, client, options, re
sourceLoaderOptions, LoadAsynchronously); |
| 68 } | 90 } |
| 69 | 91 |
| 70 ~WorkerThreadableLoader() override; | 92 ~WorkerThreadableLoader() override; |
| 71 | 93 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 94 }; | 116 }; |
| 95 class AsyncTaskForwarder; | 117 class AsyncTaskForwarder; |
| 96 struct TaskWithLocation; | 118 struct TaskWithLocation; |
| 97 class WaitableEventWithTasks; | 119 class WaitableEventWithTasks; |
| 98 class SyncTaskForwarder; | 120 class SyncTaskForwarder; |
| 99 | 121 |
| 100 // An instance of this class lives in the main thread. It is a | 122 // An instance of this class lives in the main thread. It is a |
| 101 // ThreadableLoaderClient for a DocumentThreadableLoader and forward | 123 // ThreadableLoaderClient for a DocumentThreadableLoader and forward |
| 102 // notifications to the associated WorkerThreadableLoader living in the | 124 // notifications to the associated WorkerThreadableLoader living in the |
| 103 // worker thread. | 125 // worker thread. |
| 104 class Peer final : public GarbageCollectedFinalized<Peer>, public Threadable
LoaderClient, public WorkerThreadLifecycleObserver { | 126 class MainThreadLoaderHolder final : public GarbageCollectedFinalized<MainTh
readLoaderHolder>, public ThreadableLoaderClient, public WorkerThreadLifecycleOb
server { |
| 105 USING_GARBAGE_COLLECTED_MIXIN(Peer); | 127 USING_GARBAGE_COLLECTED_MIXIN(MainThreadLoaderHolder); |
| 106 public: | 128 public: |
| 107 static void createAndStart( | 129 static void createAndStart( |
| 108 WorkerThreadableLoader*, | 130 WorkerThreadableLoader*, |
| 109 PassRefPtr<WorkerLoaderProxy>, | 131 PassRefPtr<WorkerLoaderProxy>, |
| 110 WorkerThreadLifecycleContext*, | 132 WorkerThreadLifecycleContext*, |
| 111 std::unique_ptr<CrossThreadResourceRequestData>, | 133 std::unique_ptr<CrossThreadResourceRequestData>, |
| 112 const ThreadableLoaderOptions&, | 134 const ThreadableLoaderOptions&, |
| 113 const ResourceLoaderOptions&, | 135 const ResourceLoaderOptions&, |
| 114 PassRefPtr<WaitableEventWithTasks>, | 136 PassRefPtr<WaitableEventWithTasks>, |
| 115 ExecutionContext*); | 137 ExecutionContext*); |
| 116 ~Peer() override; | 138 ~MainThreadLoaderHolder() override; |
| 117 | 139 |
| 118 void overrideTimeout(unsigned long timeoutMillisecond); | 140 void overrideTimeout(unsigned long timeoutMillisecond); |
| 119 void cancel(); | 141 void cancel(); |
| 120 | 142 |
| 121 void didSendData(unsigned long long bytesSent, unsigned long long totalB
ytesToBeSent) override; | 143 void didSendData(unsigned long long bytesSent, unsigned long long totalB
ytesToBeSent) override; |
| 122 void didReceiveResponse(unsigned long identifier, const ResourceResponse
&, std::unique_ptr<WebDataConsumerHandle>) override; | 144 void didReceiveResponse(unsigned long identifier, const ResourceResponse
&, std::unique_ptr<WebDataConsumerHandle>) override; |
| 123 void didReceiveData(const char*, unsigned dataLength) override; | 145 void didReceiveData(const char*, unsigned dataLength) override; |
| 124 void didDownloadData(int dataLength) override; | 146 void didDownloadData(int dataLength) override; |
| 125 void didReceiveCachedMetadata(const char*, int dataLength) override; | 147 void didReceiveCachedMetadata(const char*, int dataLength) override; |
| 126 void didFinishLoading(unsigned long identifier, double finishTime) overr
ide; | 148 void didFinishLoading(unsigned long identifier, double finishTime) overr
ide; |
| 127 void didFail(const ResourceError&) override; | 149 void didFail(const ResourceError&) override; |
| 128 void didFailAccessControlCheck(const ResourceError&) override; | 150 void didFailAccessControlCheck(const ResourceError&) override; |
| 129 void didFailRedirectCheck() override; | 151 void didFailRedirectCheck() override; |
| 130 void didReceiveResourceTiming(const ResourceTimingInfo&) override; | 152 void didReceiveResourceTiming(const ResourceTimingInfo&) override; |
| 131 | 153 |
| 132 void contextDestroyed() override; | 154 void contextDestroyed() override; |
| 133 | 155 |
| 134 DECLARE_TRACE(); | 156 DECLARE_TRACE(); |
| 135 | 157 |
| 136 private: | 158 private: |
| 137 Peer(TaskForwarder*, WorkerThreadLifecycleContext*); | 159 MainThreadLoaderHolder(TaskForwarder*, WorkerThreadLifecycleContext*); |
| 138 void start(Document&, std::unique_ptr<CrossThreadResourceRequestData>, c
onst ThreadableLoaderOptions&, const ResourceLoaderOptions&); | 160 void start(Document&, std::unique_ptr<CrossThreadResourceRequestData>, c
onst ThreadableLoaderOptions&, const ResourceLoaderOptions&); |
| 139 | 161 |
| 140 Member<TaskForwarder> m_forwarder; | 162 Member<TaskForwarder> m_forwarder; |
| 141 Member<ThreadableLoader> m_mainThreadLoader; | 163 Member<ThreadableLoader> m_mainThreadLoader; |
| 142 | 164 |
| 143 // |*m_workerLoader| lives in the worker thread. | 165 // |*m_workerLoader| lives in the worker thread. |
| 144 CrossThreadWeakPersistent<WorkerThreadableLoader> m_workerLoader; | 166 CrossThreadWeakPersistent<WorkerThreadableLoader> m_workerLoader; |
| 145 }; | 167 }; |
| 146 | 168 |
| 147 WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient*, const Th
readableLoaderOptions&, const ResourceLoaderOptions&, BlockingBehavior); | 169 WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient*, const Th
readableLoaderOptions&, const ResourceLoaderOptions&, BlockingBehavior); |
| 148 void didStart(Peer*); | 170 void didStart(MainThreadLoaderHolder*); |
| 149 | 171 |
| 150 void didSendData(unsigned long long bytesSent, unsigned long long totalBytes
ToBeSent); | 172 void didSendData(unsigned long long bytesSent, unsigned long long totalBytes
ToBeSent); |
| 151 void didReceiveResponse(unsigned long identifier, std::unique_ptr<CrossThrea
dResourceResponseData>, std::unique_ptr<WebDataConsumerHandle>); | 173 void didReceiveResponse(unsigned long identifier, std::unique_ptr<CrossThrea
dResourceResponseData>, std::unique_ptr<WebDataConsumerHandle>); |
| 152 void didReceiveData(std::unique_ptr<Vector<char>> data); | 174 void didReceiveData(std::unique_ptr<Vector<char>> data); |
| 153 void didReceiveCachedMetadata(std::unique_ptr<Vector<char>> data); | 175 void didReceiveCachedMetadata(std::unique_ptr<Vector<char>> data); |
| 154 void didFinishLoading(unsigned long identifier, double finishTime); | 176 void didFinishLoading(unsigned long identifier, double finishTime); |
| 155 void didFail(const ResourceError&); | 177 void didFail(const ResourceError&); |
| 156 void didFailAccessControlCheck(const ResourceError&); | 178 void didFailAccessControlCheck(const ResourceError&); |
| 157 void didFailRedirectCheck(); | 179 void didFailRedirectCheck(); |
| 158 void didDownloadData(int dataLength); | 180 void didDownloadData(int dataLength); |
| 159 void didReceiveResourceTiming(std::unique_ptr<CrossThreadResourceTimingInfoD
ata>); | 181 void didReceiveResourceTiming(std::unique_ptr<CrossThreadResourceTimingInfoD
ata>); |
| 160 | 182 |
| 161 Member<WorkerGlobalScope> m_workerGlobalScope; | 183 Member<WorkerGlobalScope> m_workerGlobalScope; |
| 162 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; | 184 RefPtr<WorkerLoaderProxy> m_workerLoaderProxy; |
| 163 ThreadableLoaderClient* m_client; | 185 ThreadableLoaderClient* m_client; |
| 164 | 186 |
| 165 ThreadableLoaderOptions m_threadableLoaderOptions; | 187 ThreadableLoaderOptions m_threadableLoaderOptions; |
| 166 ResourceLoaderOptions m_resourceLoaderOptions; | 188 ResourceLoaderOptions m_resourceLoaderOptions; |
| 167 BlockingBehavior m_blockingBehavior; | 189 BlockingBehavior m_blockingBehavior; |
| 168 | 190 |
| 169 // |*m_peer| lives in the main thread. | 191 // |*m_mainThreadLoaderHolder| lives in the main thread. |
| 170 CrossThreadPersistent<Peer> m_peer; | 192 CrossThreadPersistent<MainThreadLoaderHolder> m_mainThreadLoaderHolder; |
| 171 }; | 193 }; |
| 172 | 194 |
| 173 } // namespace blink | 195 } // namespace blink |
| 174 | 196 |
| 175 #endif // WorkerThreadableLoader_h | 197 #endif // WorkerThreadableLoader_h |
| OLD | NEW |