OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 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 28 matching lines...) Expand all Loading... |
39 #include "core/workers/WorkerThread.h" | 39 #include "core/workers/WorkerThread.h" |
40 #include "platform/ThreadSafeFunctional.h" | 40 #include "platform/ThreadSafeFunctional.h" |
41 #include "platform/WaitableEvent.h" | 41 #include "platform/WaitableEvent.h" |
42 #include "platform/heap/SafePoint.h" | 42 #include "platform/heap/SafePoint.h" |
43 #include "platform/network/ResourceError.h" | 43 #include "platform/network/ResourceError.h" |
44 #include "platform/network/ResourceRequest.h" | 44 #include "platform/network/ResourceRequest.h" |
45 #include "platform/network/ResourceResponse.h" | 45 #include "platform/network/ResourceResponse.h" |
46 #include "platform/network/ResourceTimingInfo.h" | 46 #include "platform/network/ResourceTimingInfo.h" |
47 #include "platform/weborigin/SecurityPolicy.h" | 47 #include "platform/weborigin/SecurityPolicy.h" |
48 #include "public/platform/Platform.h" | 48 #include "public/platform/Platform.h" |
49 #include "wtf/OwnPtr.h" | 49 #include "wtf/PtrUtil.h" |
50 #include "wtf/Vector.h" | 50 #include "wtf/Vector.h" |
| 51 #include <memory> |
51 | 52 |
52 namespace blink { | 53 namespace blink { |
53 | 54 |
54 static PassOwnPtr<Vector<char>> createVectorFromMemoryRegion(const char* data, u
nsigned dataLength) | 55 static std::unique_ptr<Vector<char>> createVectorFromMemoryRegion(const char* da
ta, unsigned dataLength) |
55 { | 56 { |
56 OwnPtr<Vector<char>> buffer = adoptPtr(new Vector<char>(dataLength)); | 57 std::unique_ptr<Vector<char>> buffer = wrapUnique(new Vector<char>(dataLengt
h)); |
57 memcpy(buffer->data(), data, dataLength); | 58 memcpy(buffer->data(), data, dataLength); |
58 return buffer; | 59 return buffer; |
59 } | 60 } |
60 | 61 |
61 WorkerThreadableLoader::WorkerThreadableLoader(WorkerGlobalScope& workerGlobalSc
ope, ThreadableLoaderClient* client, const ThreadableLoaderOptions& options, con
st ResourceLoaderOptions& resourceLoaderOptions, BlockingBehavior blockingBehavi
or) | 62 WorkerThreadableLoader::WorkerThreadableLoader(WorkerGlobalScope& workerGlobalSc
ope, ThreadableLoaderClient* client, const ThreadableLoaderOptions& options, con
st ResourceLoaderOptions& resourceLoaderOptions, BlockingBehavior blockingBehavi
or) |
62 : m_workerGlobalScope(&workerGlobalScope) | 63 : m_workerGlobalScope(&workerGlobalScope) |
63 , m_workerClientWrapper(ThreadableLoaderClientWrapper::create(client)) | 64 , m_workerClientWrapper(ThreadableLoaderClientWrapper::create(client)) |
64 { | 65 { |
65 m_workerClientWrapper->setResourceTimingClient(this); | 66 m_workerClientWrapper->setResourceTimingClient(this); |
66 if (blockingBehavior == LoadAsynchronously) { | 67 if (blockingBehavior == LoadAsynchronously) { |
67 m_bridge = new MainThreadAsyncBridge(workerGlobalScope, m_workerClientWr
apper, options, resourceLoaderOptions); | 68 m_bridge = new MainThreadAsyncBridge(workerGlobalScope, m_workerClientWr
apper, options, resourceLoaderOptions); |
68 } else { | 69 } else { |
69 m_bridge = new MainThreadSyncBridge(workerGlobalScope, m_workerClientWra
pper, options, resourceLoaderOptions); | 70 m_bridge = new MainThreadSyncBridge(workerGlobalScope, m_workerClientWra
pper, options, resourceLoaderOptions); |
70 } | 71 } |
71 } | 72 } |
72 | 73 |
73 void WorkerThreadableLoader::loadResourceSynchronously(WorkerGlobalScope& worker
GlobalScope, const ResourceRequest& request, ThreadableLoaderClient& client, con
st ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoader
Options) | 74 void WorkerThreadableLoader::loadResourceSynchronously(WorkerGlobalScope& worker
GlobalScope, const ResourceRequest& request, ThreadableLoaderClient& client, con
st ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoader
Options) |
74 { | 75 { |
75 OwnPtr<WorkerThreadableLoader> loader = adoptPtr(new WorkerThreadableLoader(
workerGlobalScope, &client, options, resourceLoaderOptions, LoadSynchronously)); | 76 std::unique_ptr<WorkerThreadableLoader> loader = wrapUnique(new WorkerThread
ableLoader(workerGlobalScope, &client, options, resourceLoaderOptions, LoadSynch
ronously)); |
76 loader->start(request); | 77 loader->start(request); |
77 } | 78 } |
78 | 79 |
79 WorkerThreadableLoader::~WorkerThreadableLoader() | 80 WorkerThreadableLoader::~WorkerThreadableLoader() |
80 { | 81 { |
81 m_workerClientWrapper->clearResourceTimingClient(); | 82 m_workerClientWrapper->clearResourceTimingClient(); |
82 m_bridge->destroy(); | 83 m_bridge->destroy(); |
83 m_bridge = nullptr; | 84 m_bridge = nullptr; |
84 } | 85 } |
85 | 86 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadCreateLoader(Thread
ableLoaderOptions options, ResourceLoaderOptions resourceLoaderOptions, Executio
nContext* context) | 127 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadCreateLoader(Thread
ableLoaderOptions options, ResourceLoaderOptions resourceLoaderOptions, Executio
nContext* context) |
127 { | 128 { |
128 ASSERT(isMainThread()); | 129 ASSERT(isMainThread()); |
129 Document* document = toDocument(context); | 130 Document* document = toDocument(context); |
130 | 131 |
131 resourceLoaderOptions.requestInitiatorContext = WorkerContext; | 132 resourceLoaderOptions.requestInitiatorContext = WorkerContext; |
132 m_mainThreadLoader = DocumentThreadableLoader::create(*document, this, optio
ns, resourceLoaderOptions); | 133 m_mainThreadLoader = DocumentThreadableLoader::create(*document, this, optio
ns, resourceLoaderOptions); |
133 ASSERT(m_mainThreadLoader); | 134 ASSERT(m_mainThreadLoader); |
134 } | 135 } |
135 | 136 |
136 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadStart(PassOwnPtr<Cr
ossThreadResourceRequestData> requestData) | 137 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadStart(std::unique_p
tr<CrossThreadResourceRequestData> requestData) |
137 { | 138 { |
138 ASSERT(isMainThread()); | 139 ASSERT(isMainThread()); |
139 ASSERT(m_mainThreadLoader); | 140 ASSERT(m_mainThreadLoader); |
140 m_mainThreadLoader->start(ResourceRequest(requestData.get())); | 141 m_mainThreadLoader->start(ResourceRequest(requestData.get())); |
141 } | 142 } |
142 | 143 |
143 void WorkerThreadableLoader::MainThreadBridgeBase::createLoaderInMainThread(cons
t ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderO
ptions) | 144 void WorkerThreadableLoader::MainThreadBridgeBase::createLoaderInMainThread(cons
t ThreadableLoaderOptions& options, const ResourceLoaderOptions& resourceLoaderO
ptions) |
144 { | 145 { |
145 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase:
:mainThreadCreateLoader, AllowCrossThreadAccess(this), options, resourceLoaderOp
tions)); | 146 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase:
:mainThreadCreateLoader, AllowCrossThreadAccess(this), options, resourceLoaderOp
tions)); |
146 } | 147 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // Therefore we call clearClient() directly, rather than calling | 210 // Therefore we call clearClient() directly, rather than calling |
210 // this->m_workerClientWrapper->clearClient(). | 211 // this->m_workerClientWrapper->clearClient(). |
211 clientWrapper->clearClient(); | 212 clientWrapper->clearClient(); |
212 } | 213 } |
213 | 214 |
214 void WorkerThreadableLoader::MainThreadBridgeBase::didSendData(unsigned long lon
g bytesSent, unsigned long long totalBytesToBeSent) | 215 void WorkerThreadableLoader::MainThreadBridgeBase::didSendData(unsigned long lon
g bytesSent, unsigned long long totalBytesToBeSent) |
215 { | 216 { |
216 forwardTaskToWorker(createCrossThreadTask(&ThreadableLoaderClientWrapper::di
dSendData, m_workerClientWrapper, bytesSent, totalBytesToBeSent)); | 217 forwardTaskToWorker(createCrossThreadTask(&ThreadableLoaderClientWrapper::di
dSendData, m_workerClientWrapper, bytesSent, totalBytesToBeSent)); |
217 } | 218 } |
218 | 219 |
219 void WorkerThreadableLoader::MainThreadBridgeBase::didReceiveResponse(unsigned l
ong identifier, const ResourceResponse& response, PassOwnPtr<WebDataConsumerHand
le> handle) | 220 void WorkerThreadableLoader::MainThreadBridgeBase::didReceiveResponse(unsigned l
ong identifier, const ResourceResponse& response, std::unique_ptr<WebDataConsume
rHandle> handle) |
220 { | 221 { |
221 forwardTaskToWorker(createCrossThreadTask(&ThreadableLoaderClientWrapper::di
dReceiveResponse, m_workerClientWrapper, identifier, response, passed(std::move(
handle)))); | 222 forwardTaskToWorker(createCrossThreadTask(&ThreadableLoaderClientWrapper::di
dReceiveResponse, m_workerClientWrapper, identifier, response, passed(std::move(
handle)))); |
222 } | 223 } |
223 | 224 |
224 void WorkerThreadableLoader::MainThreadBridgeBase::didReceiveData(const char* da
ta, unsigned dataLength) | 225 void WorkerThreadableLoader::MainThreadBridgeBase::didReceiveData(const char* da
ta, unsigned dataLength) |
225 { | 226 { |
226 forwardTaskToWorker(createCrossThreadTask(&ThreadableLoaderClientWrapper::di
dReceiveData, m_workerClientWrapper, passed(createVectorFromMemoryRegion(data, d
ataLength)))); | 227 forwardTaskToWorker(createCrossThreadTask(&ThreadableLoaderClientWrapper::di
dReceiveData, m_workerClientWrapper, passed(createVectorFromMemoryRegion(data, d
ataLength)))); |
227 } | 228 } |
228 | 229 |
229 void WorkerThreadableLoader::MainThreadBridgeBase::didDownloadData(int dataLengt
h) | 230 void WorkerThreadableLoader::MainThreadBridgeBase::didDownloadData(int dataLengt
h) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 const ResourceLoaderOptions& resourceLoaderOptions) | 298 const ResourceLoaderOptions& resourceLoaderOptions) |
298 : MainThreadBridgeBase(workerClientWrapper, workerGlobalScope.thread()->work
erLoaderProxy()) | 299 : MainThreadBridgeBase(workerClientWrapper, workerGlobalScope.thread()->work
erLoaderProxy()) |
299 , m_done(false) | 300 , m_done(false) |
300 { | 301 { |
301 createLoaderInMainThread(options, resourceLoaderOptions); | 302 createLoaderInMainThread(options, resourceLoaderOptions); |
302 } | 303 } |
303 | 304 |
304 void WorkerThreadableLoader::MainThreadSyncBridge::start(const ResourceRequest&
request, const WorkerGlobalScope& workerGlobalScope) | 305 void WorkerThreadableLoader::MainThreadSyncBridge::start(const ResourceRequest&
request, const WorkerGlobalScope& workerGlobalScope) |
305 { | 306 { |
306 WaitableEvent* terminationEvent = workerGlobalScope.thread()->terminationEve
nt(); | 307 WaitableEvent* terminationEvent = workerGlobalScope.thread()->terminationEve
nt(); |
307 m_loaderDoneEvent = adoptPtr(new WaitableEvent()); | 308 m_loaderDoneEvent = wrapUnique(new WaitableEvent()); |
308 | 309 |
309 startInMainThread(request, workerGlobalScope); | 310 startInMainThread(request, workerGlobalScope); |
310 | 311 |
311 size_t signaledIndex; | 312 size_t signaledIndex; |
312 { | 313 { |
313 Vector<WaitableEvent*> events; | 314 Vector<WaitableEvent*> events; |
314 // Order is important; indicies are used later. | 315 // Order is important; indicies are used later. |
315 events.append(terminationEvent); | 316 events.append(terminationEvent); |
316 events.append(m_loaderDoneEvent.get()); | 317 events.append(m_loaderDoneEvent.get()); |
317 | 318 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 362 |
362 MutexLocker lock(m_lock); | 363 MutexLocker lock(m_lock); |
363 RELEASE_ASSERT(!m_done); | 364 RELEASE_ASSERT(!m_done); |
364 | 365 |
365 m_clientTasks.append(std::move(task)); | 366 m_clientTasks.append(std::move(task)); |
366 m_done = true; | 367 m_done = true; |
367 m_loaderDoneEvent->signal(); | 368 m_loaderDoneEvent->signal(); |
368 } | 369 } |
369 | 370 |
370 } // namespace blink | 371 } // namespace blink |
OLD | NEW |