Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: third_party/WebKit/Source/core/loader/WorkerThreadableLoader.h

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 19 matching lines...) Expand all
30 30
31 #ifndef WorkerThreadableLoader_h 31 #ifndef WorkerThreadableLoader_h
32 #define WorkerThreadableLoader_h 32 #define WorkerThreadableLoader_h
33 33
34 #include "core/loader/ThreadableLoader.h" 34 #include "core/loader/ThreadableLoader.h"
35 #include "core/loader/ThreadableLoaderClient.h" 35 #include "core/loader/ThreadableLoaderClient.h"
36 #include "core/loader/ThreadableLoaderClientWrapper.h" 36 #include "core/loader/ThreadableLoaderClientWrapper.h"
37 #include "platform/heap/Handle.h" 37 #include "platform/heap/Handle.h"
38 #include "platform/weborigin/Referrer.h" 38 #include "platform/weborigin/Referrer.h"
39 #include "wtf/Functional.h" 39 #include "wtf/Functional.h"
40 #include "wtf/OwnPtr.h"
41 #include "wtf/PassOwnPtr.h"
40 #include "wtf/PassRefPtr.h" 42 #include "wtf/PassRefPtr.h"
41 #include "wtf/PtrUtil.h"
42 #include "wtf/RefPtr.h" 43 #include "wtf/RefPtr.h"
43 #include "wtf/Threading.h" 44 #include "wtf/Threading.h"
44 #include "wtf/ThreadingPrimitives.h" 45 #include "wtf/ThreadingPrimitives.h"
45 #include "wtf/Vector.h" 46 #include "wtf/Vector.h"
46 #include "wtf/text/WTFString.h" 47 #include "wtf/text/WTFString.h"
47 #include <memory>
48 48
49 namespace blink { 49 namespace blink {
50 50
51 class ExecutionContextTask; 51 class ExecutionContextTask;
52 class ResourceError; 52 class ResourceError;
53 class ResourceRequest; 53 class ResourceRequest;
54 class ResourceResponse; 54 class ResourceResponse;
55 class WaitableEvent; 55 class WaitableEvent;
56 class WorkerGlobalScope; 56 class WorkerGlobalScope;
57 class WorkerLoaderProxy; 57 class WorkerLoaderProxy;
58 struct CrossThreadResourceRequestData; 58 struct CrossThreadResourceRequestData;
59 59
60 class WorkerThreadableLoader final : public ThreadableLoader, private Threadable LoaderClientWrapper::ResourceTimingClient { 60 class WorkerThreadableLoader final : public ThreadableLoader, private Threadable LoaderClientWrapper::ResourceTimingClient {
61 USING_FAST_MALLOC(WorkerThreadableLoader); 61 USING_FAST_MALLOC(WorkerThreadableLoader);
62 public: 62 public:
63 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa derOptions&); 63 static void loadResourceSynchronously(WorkerGlobalScope&, const ResourceRequ est&, ThreadableLoaderClient&, const ThreadableLoaderOptions&, const ResourceLoa derOptions&);
64 static std::unique_ptr<WorkerThreadableLoader> create(WorkerGlobalScope& wor kerGlobalScope, ThreadableLoaderClient* client, const ThreadableLoaderOptions& o ptions, const ResourceLoaderOptions& resourceLoaderOptions) 64 static PassOwnPtr<WorkerThreadableLoader> create(WorkerGlobalScope& workerGl obalScope, ThreadableLoaderClient* client, const ThreadableLoaderOptions& option s, const ResourceLoaderOptions& resourceLoaderOptions)
65 { 65 {
66 return wrapUnique(new WorkerThreadableLoader(workerGlobalScope, client, options, resourceLoaderOptions, LoadAsynchronously)); 66 return adoptPtr(new WorkerThreadableLoader(workerGlobalScope, client, op tions, resourceLoaderOptions, LoadAsynchronously));
67 } 67 }
68 68
69 ~WorkerThreadableLoader() override; 69 ~WorkerThreadableLoader() override;
70 70
71 void start(const ResourceRequest&) override; 71 void start(const ResourceRequest&) override;
72 72
73 void overrideTimeout(unsigned long timeout) override; 73 void overrideTimeout(unsigned long timeout) override;
74 74
75 void cancel() override; 75 void cancel() override;
76 76
(...skipping 26 matching lines...) Expand all
103 public: 103 public:
104 // All executed on the worker context's thread. 104 // All executed on the worker context's thread.
105 MainThreadBridgeBase(PassRefPtr<ThreadableLoaderClientWrapper>, PassRefP tr<WorkerLoaderProxy>); 105 MainThreadBridgeBase(PassRefPtr<ThreadableLoaderClientWrapper>, PassRefP tr<WorkerLoaderProxy>);
106 virtual void start(const ResourceRequest&, const WorkerGlobalScope&) = 0 ; 106 virtual void start(const ResourceRequest&, const WorkerGlobalScope&) = 0 ;
107 void overrideTimeout(unsigned long timeoutMilliseconds); 107 void overrideTimeout(unsigned long timeoutMilliseconds);
108 void cancel(); 108 void cancel();
109 void destroy(); 109 void destroy();
110 110
111 // All executed on the main thread. 111 // All executed on the main thread.
112 void didSendData(unsigned long long bytesSent, unsigned long long totalB ytesToBeSent) final; 112 void didSendData(unsigned long long bytesSent, unsigned long long totalB ytesToBeSent) final;
113 void didReceiveResponse(unsigned long identifier, const ResourceResponse &, std::unique_ptr<WebDataConsumerHandle>) final; 113 void didReceiveResponse(unsigned long identifier, const ResourceResponse &, PassOwnPtr<WebDataConsumerHandle>) final;
114 void didReceiveData(const char*, unsigned dataLength) final; 114 void didReceiveData(const char*, unsigned dataLength) final;
115 void didDownloadData(int dataLength) final; 115 void didDownloadData(int dataLength) final;
116 void didReceiveCachedMetadata(const char*, int dataLength) final; 116 void didReceiveCachedMetadata(const char*, int dataLength) final;
117 void didFinishLoading(unsigned long identifier, double finishTime) final ; 117 void didFinishLoading(unsigned long identifier, double finishTime) final ;
118 void didFail(const ResourceError&) final; 118 void didFail(const ResourceError&) final;
119 void didFailAccessControlCheck(const ResourceError&) final; 119 void didFailAccessControlCheck(const ResourceError&) final;
120 void didFailRedirectCheck() final; 120 void didFailRedirectCheck() final;
121 void didReceiveResourceTiming(const ResourceTimingInfo&) final; 121 void didReceiveResourceTiming(const ResourceTimingInfo&) final;
122 122
123 protected: 123 protected:
(...skipping 11 matching lines...) Expand all
135 135
136 private: 136 private:
137 // The following methods are overridden by the subclasses to implement 137 // The following methods are overridden by the subclasses to implement
138 // code to forward did.* method invocations to the worker context's 138 // code to forward did.* method invocations to the worker context's
139 // thread which is specialized for sync and async case respectively. 139 // thread which is specialized for sync and async case respectively.
140 virtual void forwardTaskToWorker(std::unique_ptr<ExecutionContextTask>) = 0; 140 virtual void forwardTaskToWorker(std::unique_ptr<ExecutionContextTask>) = 0;
141 virtual void forwardTaskToWorkerOnLoaderDone(std::unique_ptr<ExecutionCo ntextTask>) = 0; 141 virtual void forwardTaskToWorkerOnLoaderDone(std::unique_ptr<ExecutionCo ntextTask>) = 0;
142 142
143 // All executed on the main thread. 143 // All executed on the main thread.
144 void mainThreadCreateLoader(ThreadableLoaderOptions, ResourceLoaderOptio ns, ExecutionContext*); 144 void mainThreadCreateLoader(ThreadableLoaderOptions, ResourceLoaderOptio ns, ExecutionContext*);
145 void mainThreadStart(std::unique_ptr<CrossThreadResourceRequestData>); 145 void mainThreadStart(PassOwnPtr<CrossThreadResourceRequestData>);
146 void mainThreadDestroy(ExecutionContext*); 146 void mainThreadDestroy(ExecutionContext*);
147 void mainThreadOverrideTimeout(unsigned long timeoutMilliseconds, Execut ionContext*); 147 void mainThreadOverrideTimeout(unsigned long timeoutMilliseconds, Execut ionContext*);
148 void mainThreadCancel(ExecutionContext*); 148 void mainThreadCancel(ExecutionContext*);
149 149
150 // Only to be used on the main thread. 150 // Only to be used on the main thread.
151 std::unique_ptr<ThreadableLoader> m_mainThreadLoader; 151 OwnPtr<ThreadableLoader> m_mainThreadLoader;
152 152
153 // ThreadableLoaderClientWrapper is to be used on the worker context thr ead. 153 // ThreadableLoaderClientWrapper is to be used on the worker context thr ead.
154 // The ref counting is done on either thread: 154 // The ref counting is done on either thread:
155 // - worker context's thread: held by the tasks 155 // - worker context's thread: held by the tasks
156 // - main thread: held by MainThreadBridgeBase 156 // - main thread: held by MainThreadBridgeBase
157 // Therefore, this must be a ThreadSafeRefCounted. 157 // Therefore, this must be a ThreadSafeRefCounted.
158 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; 158 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper;
159 159
160 // Used on the worker context thread. 160 // Used on the worker context thread.
161 RefPtr<WorkerLoaderProxy> m_loaderProxy; 161 RefPtr<WorkerLoaderProxy> m_loaderProxy;
(...skipping 16 matching lines...) Expand all
178 MainThreadSyncBridge(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderClie ntWrapper>, const ThreadableLoaderOptions&, const ResourceLoaderOptions&); 178 MainThreadSyncBridge(WorkerGlobalScope&, PassRefPtr<ThreadableLoaderClie ntWrapper>, const ThreadableLoaderOptions&, const ResourceLoaderOptions&);
179 void start(const ResourceRequest&, const WorkerGlobalScope&) override; 179 void start(const ResourceRequest&, const WorkerGlobalScope&) override;
180 180
181 private: 181 private:
182 ~MainThreadSyncBridge() override; 182 ~MainThreadSyncBridge() override;
183 183
184 void forwardTaskToWorker(std::unique_ptr<ExecutionContextTask>) override ; 184 void forwardTaskToWorker(std::unique_ptr<ExecutionContextTask>) override ;
185 void forwardTaskToWorkerOnLoaderDone(std::unique_ptr<ExecutionContextTas k>) override; 185 void forwardTaskToWorkerOnLoaderDone(std::unique_ptr<ExecutionContextTas k>) override;
186 186
187 bool m_done; 187 bool m_done;
188 std::unique_ptr<WaitableEvent> m_loaderDoneEvent; 188 OwnPtr<WaitableEvent> m_loaderDoneEvent;
189 // Thread-safety: |m_clientTasks| can be written (i.e. Closures are adde d) 189 // Thread-safety: |m_clientTasks| can be written (i.e. Closures are adde d)
190 // on the main thread only before |m_loaderDoneEvent| is signaled and ca n be read 190 // on the main thread only before |m_loaderDoneEvent| is signaled and ca n be read
191 // on the worker context thread only after |m_loaderDoneEvent| is signal ed. 191 // on the worker context thread only after |m_loaderDoneEvent| is signal ed.
192 Vector<std::unique_ptr<ExecutionContextTask>> m_clientTasks; 192 Vector<std::unique_ptr<ExecutionContextTask>> m_clientTasks;
193 Mutex m_lock; 193 Mutex m_lock;
194 }; 194 };
195 195
196 WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient*, const Th readableLoaderOptions&, const ResourceLoaderOptions&, BlockingBehavior); 196 WorkerThreadableLoader(WorkerGlobalScope&, ThreadableLoaderClient*, const Th readableLoaderOptions&, const ResourceLoaderOptions&, BlockingBehavior);
197 197
198 void didReceiveResourceTiming(const ResourceTimingInfo&) override; 198 void didReceiveResourceTiming(const ResourceTimingInfo&) override;
199 199
200 Persistent<WorkerGlobalScope> m_workerGlobalScope; 200 Persistent<WorkerGlobalScope> m_workerGlobalScope;
201 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper; 201 RefPtr<ThreadableLoaderClientWrapper> m_workerClientWrapper;
202 202
203 MainThreadBridgeBase* m_bridge; 203 MainThreadBridgeBase* m_bridge;
204 }; 204 };
205 205
206 } // namespace blink 206 } // namespace blink
207 207
208 #endif // WorkerThreadableLoader_h 208 #endif // WorkerThreadableLoader_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698