Changeset 68669 in webkit
- Timestamp:
- Sep 29, 2010 11:12:36 AM (14 years ago)
- Location:
- trunk/WebKit/chromium
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit/chromium/ChangeLog
r68666 r68669 1 2010-09-29 Kinuko Yasuda <kinuko@chromium.org> 2 3 Reviewed by David Levin. 4 5 Bridge all FileSystem operations on Workers to the MainThread 6 https://bugs.webkit.org/show_bug.cgi?id=46524 7 8 * src/LocalFileSystemChromium.cpp: 9 (WebCore::LocalFileSystem::requestFileSystem): Changed the worker case 10 code to create WebFileSystemCallbacksImpl with the current 11 ScriptExecutionContext (WorkerContext). 12 * src/WebFileSystemCallbacksImpl.cpp: 13 (WebKit::WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl): Added 14 a new constructor that takes ScriptExecutionContext (WorkerContext) 15 for workers. 16 (WebKit::WebFileSystemCallbacksImpl::didOpenFileSystem): Added the 17 code for workers that creates WorkerAsyncFileSystemChromium. 18 * src/WebFileSystemCallbacksImpl.h: 19 * src/WorkerAsyncFileSystemChromium.cpp: Added. 20 * src/WorkerAsyncFileSystemChromium.h: Added. 21 * src/WorkerFileSystemCallbacksBridge.cpp: Added methods for regular 22 file system operations to proxy them to the main thread. 23 (WebKit::WorkerFileSystemCallbacksBridge::createForOpenFileSystem): 24 (WebKit::WorkerFileSystemCallbacksBridge::createForMove): 25 (WebKit::WorkerFileSystemCallbacksBridge::createForCopy): 26 (WebKit::WorkerFileSystemCallbacksBridge::createForRemove): 27 (WebKit::WorkerFileSystemCallbacksBridge::createForReadMetadata): 28 (WebKit::WorkerFileSystemCallbacksBridge::createForCreateFile): 29 (WebKit::WorkerFileSystemCallbacksBridge::createForCreateDirectory): 30 (WebKit::WorkerFileSystemCallbacksBridge::createForFileExists): 31 (WebKit::WorkerFileSystemCallbacksBridge::createForDirectoryExists): 32 (WebKit::WorkerFileSystemCallbacksBridge::createForReadDirectory): 33 (WebKit::MainThreadFileSystemCallbacks::didSucceed): 34 (WebKit::MainThreadFileSystemCallbacks::didReadMetadata): 35 (WebKit::MainThreadFileSystemCallbacks::didReadDirectory): 36 (WebKit::WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread): 37 (WebKit::WorkerFileSystemCallbacksBridge::moveOnMainThread): 38 (WebKit::WorkerFileSystemCallbacksBridge::copyOnMainThread): 39 (WebKit::WorkerFileSystemCallbacksBridge::removeOnMainThread): 40 (WebKit::WorkerFileSystemCallbacksBridge::readMetadataOnMainThread): 41 (WebKit::WorkerFileSystemCallbacksBridge::createFileOnMainThread): 42 (WebKit::WorkerFileSystemCallbacksBridge::createDirectoryOnMainThread): 43 (WebKit::WorkerFileSystemCallbacksBridge::fileExistsOnMainThread): 44 (WebKit::WorkerFileSystemCallbacksBridge::directoryExistsOnMainThread): 45 (WebKit::WorkerFileSystemCallbacksBridge::readDirectoryOnMainThread): 46 (WebKit::WorkerFileSystemCallbacksBridge::didSucceedOnMainThread): 47 (WebKit::WorkerFileSystemCallbacksBridge::didReadMetadataOnMainThread): 48 (WebKit::WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread): 49 (WebKit::WorkerFileSystemCallbacksBridge::didSucceedOnWorkerThread): 50 (WebKit::WorkerFileSystemCallbacksBridge::didReadMetadataOnWorkerThread): 51 (WebKit::WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread): 52 (WebKit::WorkerFileSystemCallbacksBridge::derefIfWorkerIsStopped): 53 * src/WorkerFileSystemCallbacksBridge.h: 54 1 55 2010-09-29 Matt Perry <mpcomplete@chromium.org> 2 56 -
trunk/WebKit/chromium/src/AsyncFileSystemChromium.cpp
r68222 r68669 62 62 } 63 63 64 void AsyncFileSystemChromium::move(const String& s rcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)64 void AsyncFileSystemChromium::move(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) 65 65 { 66 m_webFileSystem->move(s rcPath, destPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));66 m_webFileSystem->move(sourcePath, destinationPath, new WebKit::WebFileSystemCallbacksImpl(callbacks)); 67 67 } 68 68 69 void AsyncFileSystemChromium::copy(const String& s rcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)69 void AsyncFileSystemChromium::copy(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) 70 70 { 71 m_webFileSystem->copy(s rcPath, destPath, new WebKit::WebFileSystemCallbacksImpl(callbacks));71 m_webFileSystem->copy(sourcePath, destinationPath, new WebKit::WebFileSystemCallbacksImpl(callbacks)); 72 72 } 73 73 -
trunk/WebKit/chromium/src/AsyncFileSystemChromium.h
r68180 r68669 35 35 36 36 #include "AsyncFileSystem.h" 37 #include <wtf/Pass RefPtr.h>37 #include <wtf/PassOwnPtr.h> 38 38 39 39 namespace WebKit { … … 47 47 class AsyncFileSystemChromium : public AsyncFileSystem { 48 48 public: 49 AsyncFileSystemChromium(const String& rootPath); 49 static PassOwnPtr<AsyncFileSystem> create(const String& rootPath) 50 { 51 return adoptPtr(new AsyncFileSystemChromium(rootPath)); 52 } 53 50 54 virtual ~AsyncFileSystemChromium(); 51 55 52 virtual void move(const String& s rcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks>);53 virtual void copy(const String& s rcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks>);56 virtual void move(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks>); 57 virtual void copy(const String& sourcePath, const String& destinationPath, PassOwnPtr<AsyncFileSystemCallbacks>); 54 58 virtual void remove(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>); 55 59 virtual void readMetadata(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>); … … 62 66 63 67 private: 68 explicit AsyncFileSystemChromium(const String& rootPath); 64 69 WebKit::WebFileSystem* m_webFileSystem; 65 70 }; -
trunk/WebKit/chromium/src/LocalFileSystemChromium.cpp
r68411 r68669 69 69 WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy(); 70 70 WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerLoaderProxy); 71 webWorker->openFileSystem(static_cast<WebFileSystem::Type>(type), size, new WebFileSystemCallbacksImpl(callbacks ));71 webWorker->openFileSystem(static_cast<WebFileSystem::Type>(type), size, new WebFileSystemCallbacksImpl(callbacks, context)); 72 72 } 73 73 } -
trunk/WebKit/chromium/src/WebFileSystemCallbacksImpl.cpp
r66280 r68669 35 35 #include "AsyncFileSystemCallbacks.h" 36 36 #include "AsyncFileSystemChromium.h" 37 #include " ExceptionCode.h"37 #include "ScriptExecutionContext.h" 38 38 #include "WebFileSystemEntry.h" 39 39 #include "WebFileInfo.h" 40 40 #include "WebString.h" 41 #include "WorkerAsyncFileSystemChromium.h" 41 42 #include <wtf/Vector.h> 42 43 … … 45 46 namespace WebKit { 46 47 47 WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSystemCallbacks> callbacks )48 WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSystemCallbacks> callbacks, WebCore::ScriptExecutionContext* context) 48 49 : m_callbacks(callbacks) 50 , m_context(context) 49 51 { 52 ASSERT(m_callbacks); 50 53 } 51 54 … … 56 59 void WebFileSystemCallbacksImpl::didSucceed() 57 60 { 58 ASSERT(m_callbacks);59 61 m_callbacks->didSucceed(); 60 62 delete this; … … 63 65 void WebFileSystemCallbacksImpl::didReadMetadata(const WebFileInfo& info) 64 66 { 65 ASSERT(m_callbacks);66 67 m_callbacks->didReadMetadata(info.modificationTime); 67 68 delete this; … … 70 71 void WebFileSystemCallbacksImpl::didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore) 71 72 { 72 ASSERT(m_callbacks);73 73 for (size_t i = 0; i < entries.size(); ++i) 74 74 m_callbacks->didReadDirectoryEntry(entries[i].name, entries[i].isDirectory); … … 80 80 void WebFileSystemCallbacksImpl::didOpenFileSystem(const WebString& name, const WebString& path) 81 81 { 82 m_callbacks->didOpenFileSystem(name, new AsyncFileSystemChromium(path)); 82 if (m_context && m_context->isWorkerContext()) 83 m_callbacks->didOpenFileSystem(name, WorkerAsyncFileSystemChromium::create(m_context, path)); 84 else 85 m_callbacks->didOpenFileSystem(name, AsyncFileSystemChromium::create(path)); 83 86 delete this; 84 87 } … … 86 89 void WebFileSystemCallbacksImpl::didFail(WebFileError error) 87 90 { 88 ASSERT(m_callbacks);89 91 m_callbacks->didFail(error); 90 92 delete this; -
trunk/WebKit/chromium/src/WebFileSystemCallbacksImpl.h
r67919 r68669 39 39 namespace WebCore { 40 40 class AsyncFileSystemCallbacks; 41 class ScriptExecutionContext; 41 42 } 42 43 … … 49 50 class WebFileSystemCallbacksImpl : public WebFileSystemCallbacks { 50 51 public: 51 WebFileSystemCallbacksImpl(PassOwnPtr<WebCore::AsyncFileSystemCallbacks> );52 WebFileSystemCallbacksImpl(PassOwnPtr<WebCore::AsyncFileSystemCallbacks>, WebCore::ScriptExecutionContext* = 0); 52 53 virtual ~WebFileSystemCallbacksImpl(); 53 54 … … 60 61 private: 61 62 OwnPtr<WebCore::AsyncFileSystemCallbacks> m_callbacks; 63 64 // Used for worker's openFileSystem callbacks. 65 WebCore::ScriptExecutionContext* m_context; 62 66 }; 63 67 -
trunk/WebKit/chromium/src/WebWorkerBase.cpp
r68226 r68669 241 241 { 242 242 WorkerScriptController* controller = WorkerScriptController::controllerForContext(); 243 WorkerContext* workerContext = controller->workerContext(); 244 245 RefPtr<WorkerFileSystemCallbacksBridge> bridge = WorkerFileSystemCallbacksBridge::create(this, workerContext, callbacks); 243 RefPtr<WorkerFileSystemCallbacksBridge> bridge = WorkerFileSystemCallbacksBridge::create(this, controller->workerContext(), callbacks); 246 244 bridge->postOpenFileSystemToMainThread(commonClient(), type, size, openFileSystemMode); 247 245 } -
trunk/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp
r68222 r68669 36 36 #include "CrossThreadTask.h" 37 37 #include "WebCommonWorkerClient.h" 38 #include "WebFileInfo.h" 38 39 #include "WebFileSystemCallbacks.h" 40 #include "WebFileSystemEntry.h" 39 41 #include "WebString.h" 40 42 #include "WebWorkerBase.h" … … 45 47 #include <wtf/Threading.h> 46 48 49 namespace WebCore { 50 51 template<> struct CrossThreadCopierBase<false, false, WebKit::WebFileInfo> { 52 typedef WebKit::WebFileInfo Type; 53 static Type copy(const WebKit::WebFileInfo& info) 54 { 55 // Perform per-field copy to make sure we don't do any (unexpected) non-thread safe copy here. 56 struct WebKit::WebFileInfo newInfo; 57 newInfo.modificationTime = info.modificationTime; 58 newInfo.length = info.length; 59 newInfo.type = info.type; 60 return newInfo; 61 } 62 }; 63 64 template<> struct CrossThreadCopierBase<false, false, WebKit::WebVector<WebKit::WebFileSystemEntry> > { 65 typedef WebKit::WebVector<WebKit::WebFileSystemEntry> Type; 66 static Type copy(const WebKit::WebVector<WebKit::WebFileSystemEntry>& entries) 67 { 68 WebKit::WebVector<WebKit::WebFileSystemEntry> newEntries(entries.size()); 69 for (size_t i = 0; i < entries.size(); ++i) { 70 String name = entries[i].name; 71 newEntries[i].isDirectory = entries[i].isDirectory; 72 newEntries[i].name = name.crossThreadString(); 73 } 74 return newEntries; 75 } 76 }; 77 78 } 79 47 80 using namespace WebCore; 48 81 … … 52 85 class MainThreadFileSystemCallbacks : public WebFileSystemCallbacks { 53 86 public: 54 static PassOwnPtr<MainThreadFileSystemCallbacks> create(PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode) 55 { 56 return adoptPtr(new MainThreadFileSystemCallbacks(bridge, mode)); 87 // Callbacks are self-destructed and we always return leaked pointer here. 88 static MainThreadFileSystemCallbacks* createLeakedPtr(PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode) 89 { 90 OwnPtr<MainThreadFileSystemCallbacks> callbacks = adoptPtr(new MainThreadFileSystemCallbacks(bridge, mode)); 91 return callbacks.leakPtr(); 57 92 } 58 93 … … 75 110 virtual void didSucceed() 76 111 { 77 WEBKIT_ASSERT_NOT_REACHED(); 112 m_bridge->didSucceedOnMainThread(m_mode); 113 delete this; 78 114 } 79 115 80 116 virtual void didReadMetadata(const WebFileInfo& info) 81 117 { 82 WEBKIT_ASSERT_NOT_REACHED(); 118 m_bridge->didReadMetadataOnMainThread(info, m_mode); 119 delete this; 83 120 } 84 121 85 122 virtual void didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore) 86 123 { 87 WEBKIT_ASSERT_NOT_REACHED(); 124 m_bridge->didReadDirectoryOnMainThread(entries, hasMore, m_mode); 125 delete this; 88 126 } 89 127 … … 115 153 void WorkerFileSystemCallbacksBridge::postOpenFileSystemToMainThread(WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, const String& mode) 116 154 { 117 m_selfRef = this; 118 ASSERT(m_workerContext->isContextThread()); 119 ASSERT(m_worker); 120 m_worker->dispatchTaskToMainThread(createCallbackTask(&openFileSystemOnMainThread, commonClient, type, size, this, mode)); 155 dispatchTaskToMainThread(createCallbackTask(&openFileSystemOnMainThread, commonClient, type, size, this, mode)); 156 } 157 158 void WorkerFileSystemCallbacksBridge::postMoveToMainThread(WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, const String& mode) 159 { 160 dispatchTaskToMainThread(createCallbackTask(&moveOnMainThread, fileSystem, sourcePath, destinationPath, this, mode)); 161 } 162 163 void WorkerFileSystemCallbacksBridge::postCopyToMainThread(WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, const String& mode) 164 { 165 dispatchTaskToMainThread(createCallbackTask(©OnMainThread, fileSystem, sourcePath, destinationPath, this, mode)); 166 } 167 168 void WorkerFileSystemCallbacksBridge::postRemoveToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode) 169 { 170 ASSERT(fileSystem); 171 dispatchTaskToMainThread(createCallbackTask(&removeOnMainThread, fileSystem, path, this, mode)); 172 } 173 174 void WorkerFileSystemCallbacksBridge::postReadMetadataToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode) 175 { 176 ASSERT(fileSystem); 177 dispatchTaskToMainThread(createCallbackTask(&readMetadataOnMainThread, fileSystem, path, this, mode)); 178 } 179 180 void WorkerFileSystemCallbacksBridge::postCreateFileToMainThread(WebFileSystem* fileSystem, const String& path, bool exclusive, const String& mode) 181 { 182 dispatchTaskToMainThread(createCallbackTask(&createFileOnMainThread, fileSystem, path, exclusive, this, mode)); 183 } 184 185 void WorkerFileSystemCallbacksBridge::postCreateDirectoryToMainThread(WebFileSystem* fileSystem, const String& path, bool exclusive, const String& mode) 186 { 187 ASSERT(fileSystem); 188 dispatchTaskToMainThread(createCallbackTask(&createDirectoryOnMainThread, fileSystem, path, exclusive, this, mode)); 189 } 190 191 void WorkerFileSystemCallbacksBridge::postFileExistsToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode) 192 { 193 ASSERT(fileSystem); 194 dispatchTaskToMainThread(createCallbackTask(&fileExistsOnMainThread, fileSystem, path, this, mode)); 195 } 196 197 void WorkerFileSystemCallbacksBridge::postDirectoryExistsToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode) 198 { 199 ASSERT(fileSystem); 200 dispatchTaskToMainThread(createCallbackTask(&directoryExistsOnMainThread, fileSystem, path, this, mode)); 201 } 202 203 void WorkerFileSystemCallbacksBridge::postReadDirectoryToMainThread(WebFileSystem* fileSystem, const String& path, const String& mode) 204 { 205 ASSERT(fileSystem); 206 dispatchTaskToMainThread(createCallbackTask(&readDirectoryOnMainThread, fileSystem, path, this, mode)); 121 207 } 122 208 123 209 void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecutionContext*, WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long long size, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 124 210 { 125 ASSERT(isMainThread());126 211 if (!commonClient) 127 212 bridge->didFailOnMainThread(WebFileErrorAbort, mode); 128 213 else { 129 // MainThreadFileSystemCallbacks is self-destructed, so we leak ptr here. 130 commonClient->openFileSystem(type, size, MainThreadFileSystemCallbacks::create(bridge, mode).leakPtr()); 131 } 214 commonClient->openFileSystem(type, size, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 215 } 216 } 217 218 void WorkerFileSystemCallbacksBridge::moveOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 219 { 220 fileSystem->move(sourcePath, destinationPath, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 221 } 222 223 void WorkerFileSystemCallbacksBridge::copyOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& sourcePath, const String& destinationPath, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 224 { 225 fileSystem->copy(sourcePath, destinationPath, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 226 } 227 228 void WorkerFileSystemCallbacksBridge::removeOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 229 { 230 fileSystem->remove(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 231 } 232 233 void WorkerFileSystemCallbacksBridge::readMetadataOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 234 { 235 fileSystem->readMetadata(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 236 } 237 238 void WorkerFileSystemCallbacksBridge::createFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 239 { 240 fileSystem->createFile(path, exclusive, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 241 } 242 243 void WorkerFileSystemCallbacksBridge::createDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 244 { 245 fileSystem->createDirectory(path, exclusive, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 246 } 247 248 void WorkerFileSystemCallbacksBridge::fileExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 249 { 250 fileSystem->fileExists(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 251 } 252 253 void WorkerFileSystemCallbacksBridge::directoryExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 254 { 255 fileSystem->directoryExists(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 256 } 257 258 void WorkerFileSystemCallbacksBridge::readDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem* fileSystem, const String& path, WorkerFileSystemCallbacksBridge* bridge, const String& mode) 259 { 260 fileSystem->readDirectory(path, MainThreadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 132 261 } 133 262 134 263 void WorkerFileSystemCallbacksBridge::didFailOnMainThread(WebFileError error, const String& mode) 135 264 { 136 ASSERT(isMainThread()); 137 mayPostTaskToWorker(createCallbackTask(&didFailOnWorkerThread, m_selfRef, error), mode); 265 mayPostTaskToWorker(createCallbackTask(&didFailOnWorkerThread, this, error), mode); 138 266 } 139 267 140 268 void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnMainThread(const String& name, const String& rootPath, const String& mode) 141 269 { 142 ASSERT(isMainThread()); 143 mayPostTaskToWorker(createCallbackTask(&didOpenFileSystemOnWorkerThread, m_selfRef, name, rootPath), mode); 270 mayPostTaskToWorker(createCallbackTask(&didOpenFileSystemOnWorkerThread, this, name, rootPath), mode); 271 } 272 273 void WorkerFileSystemCallbacksBridge::didSucceedOnMainThread(const String& mode) 274 { 275 mayPostTaskToWorker(createCallbackTask(&didSucceedOnWorkerThread, this), mode); 276 } 277 278 void WorkerFileSystemCallbacksBridge::didReadMetadataOnMainThread(const WebFileInfo& info, const String& mode) 279 { 280 mayPostTaskToWorker(createCallbackTask(&didReadMetadataOnWorkerThread, this, info), mode); 281 } 282 283 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread(const WebVector<WebFileSystemEntry>& entries, bool hasMore, const String& mode) 284 { 285 mayPostTaskToWorker(createCallbackTask(&didReadDirectoryOnWorkerThread, this, entries, hasMore), mode); 144 286 } 145 287 … … 158 300 } 159 301 160 void WorkerFileSystemCallbacksBridge::didFailOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, WebFileError error) 161 { 162 if (bridge->m_callbacksOnWorkerThread) { 163 ASSERT(bridge->m_workerContext->isContextThread()); 164 bridge->m_callbacksOnWorkerThread->didFail(error); 165 bridge->m_callbacksOnWorkerThread = 0; 166 } 167 } 168 169 void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnWorkerThread(ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& name, const String& rootPath) 170 { 171 if (bridge->m_callbacksOnWorkerThread) { 172 ASSERT(bridge->m_workerContext->isContextThread()); 173 bridge->m_callbacksOnWorkerThread->didOpenFileSystem(name, rootPath); 174 bridge->m_callbacksOnWorkerThread = 0; 175 } 302 void WorkerFileSystemCallbacksBridge::didFailOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, WebFileError error) 303 { 304 bridge->m_callbacksOnWorkerThread->didFail(error); 305 } 306 307 void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, const String& name, const String& rootPath) 308 { 309 bridge->m_callbacksOnWorkerThread->didOpenFileSystem(name, rootPath); 310 } 311 312 void WorkerFileSystemCallbacksBridge::didSucceedOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge) 313 { 314 bridge->m_callbacksOnWorkerThread->didSucceed(); 315 } 316 317 void WorkerFileSystemCallbacksBridge::didReadMetadataOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, const WebFileInfo& info) 318 { 319 bridge->m_callbacksOnWorkerThread->didReadMetadata(info); 320 } 321 322 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread(ScriptExecutionContext*, WorkerFileSystemCallbacksBridge* bridge, const WebVector<WebFileSystemEntry>& entries, bool hasMore) 323 { 324 bridge->m_callbacksOnWorkerThread->didReadDirectory(entries, hasMore); 325 } 326 327 bool WorkerFileSystemCallbacksBridge::derefIfWorkerIsStopped() 328 { 329 WebWorkerBase* worker = 0; 330 { 331 MutexLocker locker(m_mutex); 332 worker = m_worker; 333 } 334 335 if (!worker) { 336 m_selfRef.clear(); 337 return true; 338 } 339 return false; 340 } 341 342 void WorkerFileSystemCallbacksBridge::runTaskOnMainThread(WebCore::ScriptExecutionContext* scriptExecutionContext, WorkerFileSystemCallbacksBridge* bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun) 343 { 344 ASSERT(isMainThread()); 345 if (bridge->derefIfWorkerIsStopped()) 346 return; 347 taskToRun->performTask(scriptExecutionContext); 348 } 349 350 void WorkerFileSystemCallbacksBridge::runTaskOnWorkerThread(WebCore::ScriptExecutionContext* scriptExecutionContext, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun) 351 { 352 if (!bridge->m_callbacksOnWorkerThread) 353 return; 354 ASSERT(bridge->m_workerContext->isContextThread()); 355 taskToRun->performTask(scriptExecutionContext); 356 bridge->m_callbacksOnWorkerThread = 0; 357 } 358 359 void WorkerFileSystemCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task> task) 360 { 361 ASSERT(!m_selfRef); 362 ASSERT(m_worker); 363 ASSERT(m_workerContext->isContextThread()); 364 m_selfRef = this; 365 m_worker->dispatchTaskToMainThread(createCallbackTask(&runTaskOnMainThread, this, task)); 176 366 } 177 367 178 368 void WorkerFileSystemCallbacksBridge::mayPostTaskToWorker(PassOwnPtr<ScriptExecutionContext::Task> task, const String& mode) 179 369 { 370 ASSERT(isMainThread()); 180 371 { // Let go of the mutex before possibly deleting this due to m_selfRef.clear(). 181 372 MutexLocker locker(m_mutex); 182 373 if (m_worker) 183 m_worker->postTaskForModeToWorkerContext( task, mode);374 m_worker->postTaskForModeToWorkerContext(createCallbackTask(&runTaskOnWorkerThread, m_selfRef, task), mode); 184 375 } 185 376 m_selfRef.clear(); -
trunk/WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h
r68333 r68669 69 69 class WorkerFileSystemCallbacksBridge : public ThreadSafeShared<WorkerFileSystemCallbacksBridge>, public WebCore::WorkerContext::Observer { 70 70 public: 71 static PassRefPtr<WorkerFileSystemCallbacksBridge> create(WebWorkerBase* worker, WebCore::ScriptExecutionContext* workerContext, WebFileSystemCallbacks* callbacks)72 {73 return WTF::adoptRef(new WorkerFileSystemCallbacksBridge(worker, workerContext, callbacks));74 }75 71 ~WorkerFileSystemCallbacksBridge(); 76 72 … … 83 79 void stop(); 84 80 85 // Posts an initial request task to the main thread. It is supposed to be called immediately after the bridge is constructed. (It doesn't check if the context has been stopped or not.) 81 static PassRefPtr<WorkerFileSystemCallbacksBridge> create(WebWorkerBase* worker, WebCore::ScriptExecutionContext* workerContext, WebFileSystemCallbacks* callbacks) 82 { 83 return adoptRef(new WorkerFileSystemCallbacksBridge(worker, workerContext, callbacks)); 84 } 85 86 // Methods that create an instance and post an initial request task to the main thread. They must be called on the worker thread. 86 87 void postOpenFileSystemToMainThread(WebCommonWorkerClient*, WebFileSystem::Type, long long size, const String& mode); 88 void postMoveToMainThread(WebFileSystem*, const String& srcPath, const String& destPath, const String& mode); 89 void postCopyToMainThread(WebFileSystem*, const String& srcPath, const String& destPath, const String& mode); 90 void postRemoveToMainThread(WebFileSystem*, const String& path, const String& mode); 91 void postReadMetadataToMainThread(WebFileSystem*, const String& path, const String& mode); 92 void postCreateFileToMainThread(WebFileSystem*, const String& path, bool exclusive, const String& mode); 93 void postCreateDirectoryToMainThread(WebFileSystem*, const String& path, bool exclusive, const String& mode); 94 void postFileExistsToMainThread(WebFileSystem*, const String& path, const String& mode); 95 void postDirectoryExistsToMainThread(WebFileSystem*, const String& path, const String& mode); 96 void postReadDirectoryToMainThread(WebFileSystem*, const String& path, const String& mode); 87 97 88 98 // Callback methods that are called on the main thread. 89 99 void didFailOnMainThread(WebFileError, const String& mode); 90 100 void didOpenFileSystemOnMainThread(const String& name, const String& rootPath, const String& mode); 101 void didSucceedOnMainThread(const String& mode); 102 void didReadMetadataOnMainThread(const WebFileInfo&, const String& mode); 103 void didReadDirectoryOnMainThread(const WebVector<WebFileSystemEntry>&, bool hasMore, const String& mode); 91 104 92 105 private: 93 106 WorkerFileSystemCallbacksBridge(WebWorkerBase*, WebCore::ScriptExecutionContext*, WebFileSystemCallbacks*); 94 107 95 // Method that isto be called on the main thread.108 // Methods that are to be called on the main thread. 96 109 static void openFileSystemOnMainThread(WebCore::ScriptExecutionContext*, WebCommonWorkerClient*, WebFileSystem::Type, long long size, WorkerFileSystemCallbacksBridge*, const String& mode); 110 static void moveOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& srcPath, const String& destPath, WorkerFileSystemCallbacksBridge*, const String& mode); 111 static void copyOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& srcPath, const String& destPath, WorkerFileSystemCallbacksBridge*, const String& mode); 112 static void removeOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode); 113 static void readMetadataOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode); 114 static void createFileOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge*, const String& mode); 115 static void createDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, bool exclusive, WorkerFileSystemCallbacksBridge*, const String& mode); 116 static void fileExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode); 117 static void directoryExistsOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode); 118 static void readDirectoryOnMainThread(WebCore::ScriptExecutionContext*, WebFileSystem*, const String& path, WorkerFileSystemCallbacksBridge*, const String& mode); 97 119 98 120 friend class MainThreadFileSystemCallbacks; … … 100 122 // Methods that dispatch WebFileSystemCallbacks on the worker threads. 101 123 // They release a selfRef of the WorkerFileSystemCallbacksBridge. 102 static void didFailOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, WebFileError); 103 static void didOpenFileSystemOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, const String& name, const String& rootPath); 124 static void didFailOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, WebFileError); 125 static void didOpenFileSystemOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, const String& name, const String& rootPath); 126 static void didSucceedOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*); 127 static void didReadMetadataOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, const WebFileInfo&); 128 static void didReadDirectoryOnWorkerThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, const WebVector<WebFileSystemEntry>&, bool hasMore); 104 129 130 // For early-exist; this deref's selfRef and returns true if the worker is already null. 131 bool derefIfWorkerIsStopped(); 132 133 static void runTaskOnMainThread(WebCore::ScriptExecutionContext*, WorkerFileSystemCallbacksBridge*, PassOwnPtr<WebCore::ScriptExecutionContext::Task>); 134 static void runTaskOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge>, PassOwnPtr<WebCore::ScriptExecutionContext::Task>); 135 136 void dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Task>); 105 137 void mayPostTaskToWorker(PassOwnPtr<WebCore::ScriptExecutionContext::Task>, const String& mode); 106 138
Note: See TracChangeset
for help on using the changeset viewer.