OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2010, 2012 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 Loading... |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "WorkerFileSystemCallbacksBridge.h" | 32 #include "WorkerFileSystemCallbacksBridge.h" |
33 | 33 |
34 #include "WebCommonWorkerClient.h" | 34 #include "WebCommonWorkerClient.h" |
35 #include "WebFileSystemCallbacksImpl.h" | 35 #include "WebFileSystemCallbacksImpl.h" |
36 #include "WebWorkerBase.h" | 36 #include "WebWorkerBase.h" |
37 #include "bindings/v8/WorkerScriptController.h" | 37 #include "bindings/v8/WorkerScriptController.h" |
38 #include "core/dom/CrossThreadTask.h" | 38 #include "core/dom/CrossThreadTask.h" |
39 #include "core/platform/network/BlobData.h" | 39 #include "core/platform/network/BlobData.h" |
40 #include "core/workers/WorkerContext.h" | 40 #include "core/workers/WorkerGlobalScope.h" |
41 #include "core/workers/WorkerLoaderProxy.h" | 41 #include "core/workers/WorkerLoaderProxy.h" |
42 #include "core/workers/WorkerThread.h" | 42 #include "core/workers/WorkerThread.h" |
43 #include "public/platform/WebFileInfo.h" | 43 #include "public/platform/WebFileInfo.h" |
44 #include "public/platform/WebFileSystemEntry.h" | 44 #include "public/platform/WebFileSystemEntry.h" |
45 #include "public/platform/WebString.h" | 45 #include "public/platform/WebString.h" |
46 #include "public/platform/WebURL.h" | 46 #include "public/platform/WebURL.h" |
47 #include "weborigin/KURL.h" | 47 #include "weborigin/KURL.h" |
48 #include "wtf/MainThread.h" | 48 #include "wtf/MainThread.h" |
49 #include "wtf/Threading.h" | 49 #include "wtf/Threading.h" |
50 #include "wtf/UnusedParam.h" | 50 #include "wtf/UnusedParam.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 { | 147 { |
148 ASSERT(m_bridge); | 148 ASSERT(m_bridge); |
149 } | 149 } |
150 | 150 |
151 RefPtr<WorkerFileSystemCallbacksBridge> m_bridge; | 151 RefPtr<WorkerFileSystemCallbacksBridge> m_bridge; |
152 const String m_mode; | 152 const String m_mode; |
153 }; | 153 }; |
154 | 154 |
155 // Observes the worker context. By keeping this separate, it is easier to verify | 155 // Observes the worker context. By keeping this separate, it is easier to verify |
156 // that it only gets deleted on the worker context thread which is verified by ~
Observer. | 156 // that it only gets deleted on the worker context thread which is verified by ~
Observer. |
157 class WorkerFileSystemContextObserver : public WebCore::WorkerContext::Observer
{ | 157 class WorkerFileSystemContextObserver : public WebCore::WorkerGlobalScope::Obser
ver { |
158 public: | 158 public: |
159 static PassOwnPtr<WorkerFileSystemContextObserver> create(WorkerContext* con
text, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge) | 159 static PassOwnPtr<WorkerFileSystemContextObserver> create(WorkerGlobalScope*
context, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge) |
160 { | 160 { |
161 return adoptPtr(new WorkerFileSystemContextObserver(context, bridge)); | 161 return adoptPtr(new WorkerFileSystemContextObserver(context, bridge)); |
162 } | 162 } |
163 | 163 |
164 // WorkerContext::Observer method. | 164 // WorkerGlobalScope::Observer method. |
165 virtual void notifyStop() | 165 virtual void notifyStop() |
166 { | 166 { |
167 m_bridge->stop(); | 167 m_bridge->stop(); |
168 } | 168 } |
169 | 169 |
170 private: | 170 private: |
171 WorkerFileSystemContextObserver(WorkerContext* context, PassRefPtr<WorkerFil
eSystemCallbacksBridge> bridge) | 171 WorkerFileSystemContextObserver(WorkerGlobalScope* context, PassRefPtr<Worke
rFileSystemCallbacksBridge> bridge) |
172 : WebCore::WorkerContext::Observer(context) | 172 : WebCore::WorkerGlobalScope::Observer(context) |
173 , m_bridge(bridge) | 173 , m_bridge(bridge) |
174 { | 174 { |
175 } | 175 } |
176 | 176 |
177 RefPtr<WorkerFileSystemCallbacksBridge> m_bridge; | 177 RefPtr<WorkerFileSystemCallbacksBridge> m_bridge; |
178 }; | 178 }; |
179 | 179 |
180 void WorkerFileSystemCallbacksBridge::stop() | 180 void WorkerFileSystemCallbacksBridge::stop() |
181 { | 181 { |
182 ASSERT(m_workerContext->isContextThread()); | 182 ASSERT(m_workerGlobalScope->isContextThread()); |
183 { | 183 { |
184 MutexLocker locker(m_loaderProxyMutex); | 184 MutexLocker locker(m_loaderProxyMutex); |
185 m_workerLoaderProxy = 0; | 185 m_workerLoaderProxy = 0; |
186 } | 186 } |
187 | 187 |
188 if (m_callbacksOnWorkerThread) | 188 if (m_callbacksOnWorkerThread) |
189 m_callbacksOnWorkerThread->didFail(WebFileErrorAbort); | 189 m_callbacksOnWorkerThread->didFail(WebFileErrorAbort); |
190 | 190 |
191 cleanUpAfterCallback(); | 191 cleanUpAfterCallback(); |
192 } | 192 } |
193 | 193 |
194 void WorkerFileSystemCallbacksBridge::cleanUpAfterCallback() | 194 void WorkerFileSystemCallbacksBridge::cleanUpAfterCallback() |
195 { | 195 { |
196 ASSERT(m_workerContext->isContextThread()); | 196 ASSERT(m_workerGlobalScope->isContextThread()); |
197 | 197 |
198 m_callbacksOnWorkerThread = 0; | 198 m_callbacksOnWorkerThread = 0; |
199 if (m_workerContextObserver) { | 199 if (m_workerGlobalScopeObserver) { |
200 WorkerFileSystemContextObserver* observer = m_workerContextObserver; | 200 WorkerFileSystemContextObserver* observer = m_workerGlobalScopeObserver; |
201 m_workerContextObserver = 0; | 201 m_workerGlobalScopeObserver = 0; |
202 // The next line may delete this. | 202 // The next line may delete this. |
203 delete observer; | 203 delete observer; |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 void WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread(WebCommonWo
rkerClient* commonClient, WebFileSystemType type, long long size, bool create, c
onst String& mode) | 207 void WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread(WebCommonWo
rkerClient* commonClient, WebFileSystemType type, long long size, bool create, c
onst String& mode) |
208 { | 208 { |
209 dispatchTaskToMainThread( | 209 dispatchTaskToMainThread( |
210 createCallbackTask(&openFileSystemOnMainThread, | 210 createCallbackTask(&openFileSystemOnMainThread, |
211 AllowCrossThreadAccess(commonClient), type, size, cre
ate, | 211 AllowCrossThreadAccess(commonClient), type, size, cre
ate, |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 400 |
401 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread(const WebVect
or<WebFileSystemEntry>& entries, bool hasMore, const String& mode) | 401 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread(const WebVect
or<WebFileSystemEntry>& entries, bool hasMore, const String& mode) |
402 { | 402 { |
403 mayPostTaskToWorker( | 403 mayPostTaskToWorker( |
404 createCallbackTask(&didReadDirectoryOnWorkerThread, | 404 createCallbackTask(&didReadDirectoryOnWorkerThread, |
405 this, entries, hasMore), mode); | 405 this, entries, hasMore), mode); |
406 } | 406 } |
407 | 407 |
408 WorkerFileSystemCallbacksBridge::WorkerFileSystemCallbacksBridge(WebCore::Worker
LoaderProxy* workerLoaderProxy, ScriptExecutionContext* scriptExecutionContext,
WebFileSystemCallbacksImpl* callbacks) | 408 WorkerFileSystemCallbacksBridge::WorkerFileSystemCallbacksBridge(WebCore::Worker
LoaderProxy* workerLoaderProxy, ScriptExecutionContext* scriptExecutionContext,
WebFileSystemCallbacksImpl* callbacks) |
409 : m_workerLoaderProxy(workerLoaderProxy) | 409 : m_workerLoaderProxy(workerLoaderProxy) |
410 , m_workerContext(scriptExecutionContext) | 410 , m_workerGlobalScope(scriptExecutionContext) |
411 , m_workerContextObserver(WorkerFileSystemContextObserver::create(static_cas
t<WorkerContext*>(m_workerContext), this).leakPtr()) | 411 , m_workerGlobalScopeObserver(WorkerFileSystemContextObserver::create(static
_cast<WorkerGlobalScope*>(m_workerGlobalScope), this).leakPtr()) |
412 , m_callbacksOnWorkerThread(callbacks) | 412 , m_callbacksOnWorkerThread(callbacks) |
413 { | 413 { |
414 ASSERT(m_workerContext->isContextThread()); | 414 ASSERT(m_workerGlobalScope->isContextThread()); |
415 } | 415 } |
416 | 416 |
417 WorkerFileSystemCallbacksBridge::~WorkerFileSystemCallbacksBridge() | 417 WorkerFileSystemCallbacksBridge::~WorkerFileSystemCallbacksBridge() |
418 { | 418 { |
419 ASSERT(!m_callbacksOnWorkerThread); | 419 ASSERT(!m_callbacksOnWorkerThread); |
420 } | 420 } |
421 | 421 |
422 void WorkerFileSystemCallbacksBridge::didFailOnWorkerThread(ScriptExecutionConte
xt*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, WebFileError error) | 422 void WorkerFileSystemCallbacksBridge::didFailOnWorkerThread(ScriptExecutionConte
xt*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, WebFileError error) |
423 { | 423 { |
424 bridge->m_callbacksOnWorkerThread->didFail(error); | 424 bridge->m_callbacksOnWorkerThread->didFail(error); |
(...skipping 28 matching lines...) Expand all Loading... |
453 void WorkerFileSystemCallbacksBridge::runTaskOnMainThread(WebCore::ScriptExecuti
onContext* scriptExecutionContext, PassRefPtr<WorkerFileSystemCallbacksBridge> b
ridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun) | 453 void WorkerFileSystemCallbacksBridge::runTaskOnMainThread(WebCore::ScriptExecuti
onContext* scriptExecutionContext, PassRefPtr<WorkerFileSystemCallbacksBridge> b
ridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun) |
454 { | 454 { |
455 ASSERT(isMainThread()); | 455 ASSERT(isMainThread()); |
456 taskToRun->performTask(scriptExecutionContext); | 456 taskToRun->performTask(scriptExecutionContext); |
457 } | 457 } |
458 | 458 |
459 void WorkerFileSystemCallbacksBridge::runTaskOnWorkerThread(WebCore::ScriptExecu
tionContext* scriptExecutionContext, PassRefPtr<WorkerFileSystemCallbacksBridge>
bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun) | 459 void WorkerFileSystemCallbacksBridge::runTaskOnWorkerThread(WebCore::ScriptExecu
tionContext* scriptExecutionContext, PassRefPtr<WorkerFileSystemCallbacksBridge>
bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun) |
460 { | 460 { |
461 if (!bridge->m_callbacksOnWorkerThread) | 461 if (!bridge->m_callbacksOnWorkerThread) |
462 return; | 462 return; |
463 ASSERT(bridge->m_workerContext->isContextThread()); | 463 ASSERT(bridge->m_workerGlobalScope->isContextThread()); |
464 taskToRun->performTask(scriptExecutionContext); | 464 taskToRun->performTask(scriptExecutionContext); |
465 | 465 |
466 // taskToRun does the callback. | 466 // taskToRun does the callback. |
467 bridge->cleanUpAfterCallback(); | 467 bridge->cleanUpAfterCallback(); |
468 | 468 |
469 // WorkerFileSystemCallbacksBridge may be deleted here when bridge goes out
of scope. | 469 // WorkerFileSystemCallbacksBridge may be deleted here when bridge goes out
of scope. |
470 } | 470 } |
471 | 471 |
472 void WorkerFileSystemCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<WebCor
e::ScriptExecutionContext::Task> task) | 472 void WorkerFileSystemCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<WebCor
e::ScriptExecutionContext::Task> task) |
473 { | 473 { |
474 ASSERT(m_workerLoaderProxy); | 474 ASSERT(m_workerLoaderProxy); |
475 ASSERT(m_workerContext->isContextThread()); | 475 ASSERT(m_workerGlobalScope->isContextThread()); |
476 WebWorkerBase::dispatchTaskToMainThread(createCallbackTask(&runTaskOnMainThr
ead, RefPtr<WorkerFileSystemCallbacksBridge>(this).release(), task)); | 476 WebWorkerBase::dispatchTaskToMainThread(createCallbackTask(&runTaskOnMainThr
ead, RefPtr<WorkerFileSystemCallbacksBridge>(this).release(), task)); |
477 } | 477 } |
478 | 478 |
479 void WorkerFileSystemCallbacksBridge::mayPostTaskToWorker(PassOwnPtr<ScriptExecu
tionContext::Task> task, const String& mode) | 479 void WorkerFileSystemCallbacksBridge::mayPostTaskToWorker(PassOwnPtr<ScriptExecu
tionContext::Task> task, const String& mode) |
480 { | 480 { |
481 // Relies on its caller (MainThreadFileSystemCallbacks:did*) to keep WorkerF
ileSystemCallbacksBridge alive. | 481 // Relies on its caller (MainThreadFileSystemCallbacks:did*) to keep WorkerF
ileSystemCallbacksBridge alive. |
482 ASSERT(isMainThread()); | 482 ASSERT(isMainThread()); |
483 | 483 |
484 MutexLocker locker(m_loaderProxyMutex); | 484 MutexLocker locker(m_loaderProxyMutex); |
485 if (m_workerLoaderProxy) | 485 if (m_workerLoaderProxy) |
486 m_workerLoaderProxy->postTaskForModeToWorkerContext(createCallbackTask(&
runTaskOnWorkerThread, this, task), mode); | 486 m_workerLoaderProxy->postTaskForModeToWorkerGlobalScope(createCallbackTa
sk(&runTaskOnWorkerThread, this, task), mode); |
487 } | 487 } |
488 | 488 |
489 } // namespace WebCore | 489 } // namespace WebCore |
OLD | NEW |