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