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