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

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

Issue 1925583003: Replace AllowCrossThreadAccess() + non-GCed pointers with crossThreadUnretained() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Kuroneko_4
Patch Set: Rebase. Created 4 years, 5 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, 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadStart(std::unique_p tr<CrossThreadResourceRequestData> requestData) 137 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadStart(std::unique_p tr<CrossThreadResourceRequestData> requestData)
138 { 138 {
139 ASSERT(isMainThread()); 139 ASSERT(isMainThread());
140 ASSERT(m_mainThreadLoader); 140 ASSERT(m_mainThreadLoader);
141 m_mainThreadLoader->start(ResourceRequest(requestData.get())); 141 m_mainThreadLoader->start(ResourceRequest(requestData.get()));
142 } 142 }
143 143
144 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)
145 { 145 {
146 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadCreateLoader, AllowCrossThreadAccess(this), options, resourceLoaderOp tions)); 146 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadCreateLoader, crossThreadUnretained(this), options, resourceLoaderOpt ions));
147 } 147 }
148 148
149 void WorkerThreadableLoader::MainThreadBridgeBase::startInMainThread(const Resou rceRequest& request, const WorkerGlobalScope& workerGlobalScope) 149 void WorkerThreadableLoader::MainThreadBridgeBase::startInMainThread(const Resou rceRequest& request, const WorkerGlobalScope& workerGlobalScope)
150 { 150 {
151 loaderProxy()->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadStart, AllowCrossThreadAccess(this), request)); 151 loaderProxy()->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadStart, crossThreadUnretained(this), request));
152 } 152 }
153 153
154 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadDestroy(ExecutionCo ntext* context) 154 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadDestroy(ExecutionCo ntext* context)
155 { 155 {
156 ASSERT(isMainThread()); 156 ASSERT(isMainThread());
157 ASSERT_UNUSED(context, context->isDocument()); 157 ASSERT_UNUSED(context, context->isDocument());
158 delete this; 158 delete this;
159 } 159 }
160 160
161 void WorkerThreadableLoader::MainThreadBridgeBase::destroy() 161 void WorkerThreadableLoader::MainThreadBridgeBase::destroy()
162 { 162 {
163 // Ensure that no more client callbacks are done in the worker context's thr ead. 163 // Ensure that no more client callbacks are done in the worker context's thr ead.
164 m_workerClientWrapper->clearClient(); 164 m_workerClientWrapper->clearClient();
165 165
166 // "delete this" and m_mainThreadLoader::deref() on the worker object's thre ad. 166 // "delete this" and m_mainThreadLoader::deref() on the worker object's thre ad.
167 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadDestroy, AllowCrossThreadAccess(this))); 167 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadDestroy, crossThreadUnretained(this)));
168 } 168 }
169 169
170 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadOverrideTimeout(uns igned long timeoutMilliseconds, ExecutionContext* context) 170 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadOverrideTimeout(uns igned long timeoutMilliseconds, ExecutionContext* context)
171 { 171 {
172 ASSERT(isMainThread()); 172 ASSERT(isMainThread());
173 ASSERT_UNUSED(context, context->isDocument()); 173 ASSERT_UNUSED(context, context->isDocument());
174 174
175 if (!m_mainThreadLoader) 175 if (!m_mainThreadLoader)
176 return; 176 return;
177 m_mainThreadLoader->overrideTimeout(timeoutMilliseconds); 177 m_mainThreadLoader->overrideTimeout(timeoutMilliseconds);
178 } 178 }
179 179
180 void WorkerThreadableLoader::MainThreadBridgeBase::overrideTimeout(unsigned long timeoutMilliseconds) 180 void WorkerThreadableLoader::MainThreadBridgeBase::overrideTimeout(unsigned long timeoutMilliseconds)
181 { 181 {
182 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadOverrideTimeout, AllowCrossThreadAccess(this), timeoutMilliseconds)); 182 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadOverrideTimeout, crossThreadUnretained(this), timeoutMilliseconds));
183 } 183 }
184 184
185 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadCancel(ExecutionCon text* context) 185 void WorkerThreadableLoader::MainThreadBridgeBase::mainThreadCancel(ExecutionCon text* context)
186 { 186 {
187 ASSERT(isMainThread()); 187 ASSERT(isMainThread());
188 ASSERT_UNUSED(context, context->isDocument()); 188 ASSERT_UNUSED(context, context->isDocument());
189 189
190 if (!m_mainThreadLoader) 190 if (!m_mainThreadLoader)
191 return; 191 return;
192 m_mainThreadLoader->cancel(); 192 m_mainThreadLoader->cancel();
193 m_mainThreadLoader = nullptr; 193 m_mainThreadLoader = nullptr;
194 } 194 }
195 195
196 void WorkerThreadableLoader::MainThreadBridgeBase::cancel() 196 void WorkerThreadableLoader::MainThreadBridgeBase::cancel()
197 { 197 {
198 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadCancel, AllowCrossThreadAccess(this))); 198 m_loaderProxy->postTaskToLoader(createCrossThreadTask(&MainThreadBridgeBase: :mainThreadCancel, crossThreadUnretained(this)));
199 RefPtr<ThreadableLoaderClientWrapper> clientWrapper = m_workerClientWrapper; 199 RefPtr<ThreadableLoaderClientWrapper> clientWrapper = m_workerClientWrapper;
200 if (!clientWrapper->done()) { 200 if (!clientWrapper->done()) {
201 // If the client hasn't reached a termination state, then transition it by sending a cancellation error. 201 // If the client hasn't reached a termination state, then transition it by sending a cancellation error.
202 // Note: no more client callbacks will be done after this method -- the m_workerClientWrapper->clearClient() call ensures that. 202 // Note: no more client callbacks will be done after this method -- the m_workerClientWrapper->clearClient() call ensures that.
203 ResourceError error(String(), 0, String(), String()); 203 ResourceError error(String(), 0, String(), String());
204 error.setIsCancellation(true); 204 error.setIsCancellation(true);
205 clientWrapper->didFail(error); 205 clientWrapper->didFail(error);
206 } 206 }
207 // |this| might be already destructed here because didFail() might 207 // |this| might be already destructed here because didFail() might
208 // clear a reference to ThreadableLoader, which might destruct 208 // clear a reference to ThreadableLoader, which might destruct
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 362
363 MutexLocker lock(m_lock); 363 MutexLocker lock(m_lock);
364 RELEASE_ASSERT(!m_done); 364 RELEASE_ASSERT(!m_done);
365 365
366 m_clientTasks.append(std::move(task)); 366 m_clientTasks.append(std::move(task));
367 m_done = true; 367 m_done = true;
368 m_loaderDoneEvent->signal(); 368 m_loaderDoneEvent->signal();
369 } 369 }
370 370
371 } // namespace blink 371 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698