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

Side by Side Diff: WebKit/chromium/src/WorkerFileSystemCallbacksBridge.cpp

Issue 11192017: ********** WebCore blob hacking (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk/Source/
Patch Set: Created 7 years, 11 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) 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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "WorkerFileSystemCallbacksBridge.h" 32 #include "WorkerFileSystemCallbacksBridge.h"
33 33
34 #if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS) 34 #if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS)
35 35
36 #include "BlobData.h"
36 #include "CrossThreadTask.h" 37 #include "CrossThreadTask.h"
37 #include "KURL.h" 38 #include "KURL.h"
38 #include "WebCommonWorkerClient.h" 39 #include "WebCommonWorkerClient.h"
39 #include "WebFileSystemCallbacks.h" 40 #include "WebFileSystemCallbacksImpl.h"
40 #include "WebFileSystemEntry.h" 41 #include "WebFileSystemEntry.h"
41 #include "WebWorkerBase.h" 42 #include "WebWorkerBase.h"
42 #include "WorkerContext.h" 43 #include "WorkerContext.h"
43 #include "WorkerLoaderProxy.h" 44 #include "WorkerLoaderProxy.h"
44 #include "WorkerScriptController.h" 45 #include "WorkerScriptController.h"
45 #include "WorkerThread.h" 46 #include "WorkerThread.h"
46 #include <public/WebFileInfo.h> 47 #include <public/WebFileInfo.h>
47 #include <public/WebString.h> 48 #include <public/WebString.h>
48 #include <public/WebURL.h> 49 #include <public/WebURL.h>
49 #include <wtf/MainThread.h> 50 #include <wtf/MainThread.h>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 m_bridge->didSucceedOnMainThread(m_mode); 118 m_bridge->didSucceedOnMainThread(m_mode);
118 delete this; 119 delete this;
119 } 120 }
120 121
121 virtual void didReadMetadata(const WebFileInfo& info) 122 virtual void didReadMetadata(const WebFileInfo& info)
122 { 123 {
123 m_bridge->didReadMetadataOnMainThread(info, m_mode); 124 m_bridge->didReadMetadataOnMainThread(info, m_mode);
124 delete this; 125 delete this;
125 } 126 }
126 127
128 virtual void didCreateSnapshotFile(const WebFileInfo& info)
129 {
130 // It's important to create a BlobDataHandle that refers to the platform file path prior
131 // to return from this method so the underlying file will not be deleted .
132 OwnPtr<BlobData> blobData = BlobData::create();
133 blobData->appendFile(info.platformPath);
134 RefPtr<BlobDataHandle> snapshotBlob = BlobDataHandle::create(blobData.re lease(), info.length);
135 m_bridge->didCreateSnapshotFileOnMainThread(info, m_mode, snapshotBlob);
136 delete this;
137 }
138
127 virtual void didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore) 139 virtual void didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
128 { 140 {
129 m_bridge->didReadDirectoryOnMainThread(entries, hasMore, m_mode); 141 m_bridge->didReadDirectoryOnMainThread(entries, hasMore, m_mode);
130 delete this; 142 delete this;
131 } 143 }
132 144
133 private: 145 private:
134 MainThreadFileSystemCallbacks(PassRefPtr<WorkerFileSystemCallbacksBridge> br idge, const String& mode) 146 MainThreadFileSystemCallbacks(PassRefPtr<WorkerFileSystemCallbacksBridge> br idge, const String& mode)
135 : m_bridge(bridge) 147 : m_bridge(bridge)
136 , m_mode(mode) 148 , m_mode(mode)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 294
283 void WorkerFileSystemCallbacksBridge::postReadDirectoryToMainThread(WebFileSyste m* fileSystem, const KURL& path, const String& mode) 295 void WorkerFileSystemCallbacksBridge::postReadDirectoryToMainThread(WebFileSyste m* fileSystem, const KURL& path, const String& mode)
284 { 296 {
285 ASSERT(fileSystem); 297 ASSERT(fileSystem);
286 dispatchTaskToMainThread( 298 dispatchTaskToMainThread(
287 createCallbackTask(&readDirectoryOnMainThread, 299 createCallbackTask(&readDirectoryOnMainThread,
288 AllowCrossThreadAccess(fileSystem), path, 300 AllowCrossThreadAccess(fileSystem), path,
289 this, mode)); 301 this, mode));
290 } 302 }
291 303
292 void WorkerFileSystemCallbacksBridge::postCreateSnapshotFileToMainThread(WebFile System* fileSystem, const KURL& internalBlobURL, const KURL& path, const String& mode) 304 void WorkerFileSystemCallbacksBridge::postCreateSnapshotFileToMainThread(WebFile System* fileSystem, const KURL& path, const String& mode)
293 { 305 {
294 ASSERT(fileSystem); 306 ASSERT(fileSystem);
295 dispatchTaskToMainThread( 307 dispatchTaskToMainThread(
296 createCallbackTask(&createSnapshotFileOnMainThread, 308 createCallbackTask(&createSnapshotFileOnMainThread,
297 AllowCrossThreadAccess(fileSystem), 309 AllowCrossThreadAccess(fileSystem),
298 internalBlobURL, path, this, mode)); 310 path, this, mode));
299 } 311 }
300 312
301 void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecution Context*, WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long lo ng size, bool create, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode) 313 void WorkerFileSystemCallbacksBridge::openFileSystemOnMainThread(ScriptExecution Context*, WebCommonWorkerClient* commonClient, WebFileSystem::Type type, long lo ng size, bool create, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const String& mode)
302 { 314 {
303 if (!commonClient) 315 if (!commonClient)
304 bridge->didFailOnMainThread(WebFileErrorAbort, mode); 316 bridge->didFailOnMainThread(WebFileErrorAbort, mode);
305 else { 317 else {
306 commonClient->openFileSystem(type, size, create, MainThreadFileSystemCal lbacks::createLeakedPtr(bridge, mode)); 318 commonClient->openFileSystem(type, size, create, MainThreadFileSystemCal lbacks::createLeakedPtr(bridge, mode));
307 } 319 }
308 } 320 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 void WorkerFileSystemCallbacksBridge::directoryExistsOnMainThread(WebCore::Scrip tExecutionContext*, WebFileSystem* fileSystem, const KURL& path, PassRefPtr<Work erFileSystemCallbacksBridge> bridge, const String& mode) 362 void WorkerFileSystemCallbacksBridge::directoryExistsOnMainThread(WebCore::Scrip tExecutionContext*, WebFileSystem* fileSystem, const KURL& path, PassRefPtr<Work erFileSystemCallbacksBridge> bridge, const String& mode)
351 { 363 {
352 fileSystem->directoryExists(path, MainThreadFileSystemCallbacks::createLeake dPtr(bridge, mode)); 364 fileSystem->directoryExists(path, MainThreadFileSystemCallbacks::createLeake dPtr(bridge, mode));
353 } 365 }
354 366
355 void WorkerFileSystemCallbacksBridge::readDirectoryOnMainThread(WebCore::ScriptE xecutionContext*, WebFileSystem* fileSystem, const KURL& path, PassRefPtr<Worker FileSystemCallbacksBridge> bridge, const String& mode) 367 void WorkerFileSystemCallbacksBridge::readDirectoryOnMainThread(WebCore::ScriptE xecutionContext*, WebFileSystem* fileSystem, const KURL& path, PassRefPtr<Worker FileSystemCallbacksBridge> bridge, const String& mode)
356 { 368 {
357 fileSystem->readDirectory(path, MainThreadFileSystemCallbacks::createLeakedP tr(bridge, mode)); 369 fileSystem->readDirectory(path, MainThreadFileSystemCallbacks::createLeakedP tr(bridge, mode));
358 } 370 }
359 371
360 void WorkerFileSystemCallbacksBridge::createSnapshotFileOnMainThread(WebCore::Sc riptExecutionContext*, WebFileSystem* fileSystem, const KURL& internalBlobURL, c onst KURL& path, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const Strin g& mode) 372 void WorkerFileSystemCallbacksBridge::createSnapshotFileOnMainThread(WebCore::Sc riptExecutionContext*, WebFileSystem* fileSystem, const KURL& path, PassRefPtr<W orkerFileSystemCallbacksBridge> bridge, const String& mode)
361 { 373 {
362 fileSystem->createSnapshotFileAndReadMetadata(internalBlobURL, path, MainThr eadFileSystemCallbacks::createLeakedPtr(bridge, mode)); 374 fileSystem->createSnapshotFileAndReadMetadata(path, MainThreadFileSystemCall backs::createLeakedPtr(bridge, mode));
363 } 375 }
364 376
365 void WorkerFileSystemCallbacksBridge::didFailOnMainThread(WebFileError error, co nst String& mode) 377 void WorkerFileSystemCallbacksBridge::didFailOnMainThread(WebFileError error, co nst String& mode)
366 { 378 {
367 mayPostTaskToWorker(createCallbackTask(&didFailOnWorkerThread, this, error), mode); 379 mayPostTaskToWorker(createCallbackTask(&didFailOnWorkerThread, this, error), mode);
368 } 380 }
369 381
370 void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnMainThread(const String & name, const KURL& rootURL, const String& mode) 382 void WorkerFileSystemCallbacksBridge::didOpenFileSystemOnMainThread(const String & name, const KURL& rootURL, const String& mode)
371 { 383 {
372 mayPostTaskToWorker(createCallbackTask(&didOpenFileSystemOnWorkerThread, 384 mayPostTaskToWorker(createCallbackTask(&didOpenFileSystemOnWorkerThread,
373 this, name, rootURL), mode); 385 this, name, rootURL), mode);
374 } 386 }
375 387
376 void WorkerFileSystemCallbacksBridge::didSucceedOnMainThread(const String& mode) 388 void WorkerFileSystemCallbacksBridge::didSucceedOnMainThread(const String& mode)
377 { 389 {
378 mayPostTaskToWorker(createCallbackTask(&didSucceedOnWorkerThread, this), mod e); 390 mayPostTaskToWorker(createCallbackTask(&didSucceedOnWorkerThread, this), mod e);
379 } 391 }
380 392
381 void WorkerFileSystemCallbacksBridge::didReadMetadataOnMainThread(const WebFileI nfo& info, const String& mode) 393 void WorkerFileSystemCallbacksBridge::didReadMetadataOnMainThread(const WebFileI nfo& info, const String& mode)
382 { 394 {
383 mayPostTaskToWorker(createCallbackTask(&didReadMetadataOnWorkerThread, this, info), mode); 395 mayPostTaskToWorker(createCallbackTask(&didReadMetadataOnWorkerThread, this, info), mode);
384 } 396 }
385 397
398 void WorkerFileSystemCallbacksBridge::didCreateSnapshotFileOnMainThread(const We bFileInfo& info, const String& mode, PassRefPtr<BlobDataHandle> snapshotBlob)
399 {
400 mayPostTaskToWorker(createCallbackTask(&didCreateSnapshotFileOnWorkerThread, this, info, snapshotBlob), mode);
401 }
402
386 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread(const WebVect or<WebFileSystemEntry>& entries, bool hasMore, const String& mode) 403 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnMainThread(const WebVect or<WebFileSystemEntry>& entries, bool hasMore, const String& mode)
387 { 404 {
388 mayPostTaskToWorker( 405 mayPostTaskToWorker(
389 createCallbackTask(&didReadDirectoryOnWorkerThread, 406 createCallbackTask(&didReadDirectoryOnWorkerThread,
390 this, entries, hasMore), mode); 407 this, entries, hasMore), mode);
391 } 408 }
392 409
393 WorkerFileSystemCallbacksBridge::WorkerFileSystemCallbacksBridge(WebCore::Worker LoaderProxy* workerLoaderProxy, ScriptExecutionContext* scriptExecutionContext, WebFileSystemCallbacks* callbacks) 410 WorkerFileSystemCallbacksBridge::WorkerFileSystemCallbacksBridge(WebCore::Worker LoaderProxy* workerLoaderProxy, ScriptExecutionContext* scriptExecutionContext, WebFileSystemCallbacksImpl* callbacks)
394 : m_workerLoaderProxy(workerLoaderProxy) 411 : m_workerLoaderProxy(workerLoaderProxy)
395 , m_workerContext(scriptExecutionContext) 412 , m_workerContext(scriptExecutionContext)
396 , m_workerContextObserver(WorkerFileSystemContextObserver::create(static_cas t<WorkerContext*>(m_workerContext), this).leakPtr()) 413 , m_workerContextObserver(WorkerFileSystemContextObserver::create(static_cas t<WorkerContext*>(m_workerContext), this).leakPtr())
397 , m_callbacksOnWorkerThread(callbacks) 414 , m_callbacksOnWorkerThread(callbacks)
398 { 415 {
399 ASSERT(m_workerContext->isContextThread()); 416 ASSERT(m_workerContext->isContextThread());
400 } 417 }
401 418
402 WorkerFileSystemCallbacksBridge::~WorkerFileSystemCallbacksBridge() 419 WorkerFileSystemCallbacksBridge::~WorkerFileSystemCallbacksBridge()
403 { 420 {
(...skipping 13 matching lines...) Expand all
417 void WorkerFileSystemCallbacksBridge::didSucceedOnWorkerThread(ScriptExecutionCo ntext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge) 434 void WorkerFileSystemCallbacksBridge::didSucceedOnWorkerThread(ScriptExecutionCo ntext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge)
418 { 435 {
419 bridge->m_callbacksOnWorkerThread->didSucceed(); 436 bridge->m_callbacksOnWorkerThread->didSucceed();
420 } 437 }
421 438
422 void WorkerFileSystemCallbacksBridge::didReadMetadataOnWorkerThread(ScriptExecut ionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const WebFileIn fo& info) 439 void WorkerFileSystemCallbacksBridge::didReadMetadataOnWorkerThread(ScriptExecut ionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const WebFileIn fo& info)
423 { 440 {
424 bridge->m_callbacksOnWorkerThread->didReadMetadata(info); 441 bridge->m_callbacksOnWorkerThread->didReadMetadata(info);
425 } 442 }
426 443
444 void WorkerFileSystemCallbacksBridge::didCreateSnapshotFileOnWorkerThread(Script ExecutionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const Web FileInfo& info, PassRefPtr<BlobDataHandle> snapshotBlob)
445 {
446 bridge->m_callbacksOnWorkerThread->didCreateSnapshotFile(info, snapshotBlob) ;
447 }
448
427 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread(ScriptExecu tionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const WebVecto r<WebFileSystemEntry>& entries, bool hasMore) 449 void WorkerFileSystemCallbacksBridge::didReadDirectoryOnWorkerThread(ScriptExecu tionContext*, PassRefPtr<WorkerFileSystemCallbacksBridge> bridge, const WebVecto r<WebFileSystemEntry>& entries, bool hasMore)
428 { 450 {
429 bridge->m_callbacksOnWorkerThread->didReadDirectory(entries, hasMore); 451 bridge->m_callbacksOnWorkerThread->didReadDirectory(entries, hasMore);
430 } 452 }
431 453
432 454
433 void WorkerFileSystemCallbacksBridge::runTaskOnMainThread(WebCore::ScriptExecuti onContext* scriptExecutionContext, PassRefPtr<WorkerFileSystemCallbacksBridge> b ridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun) 455 void WorkerFileSystemCallbacksBridge::runTaskOnMainThread(WebCore::ScriptExecuti onContext* scriptExecutionContext, PassRefPtr<WorkerFileSystemCallbacksBridge> b ridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun)
434 { 456 {
435 ASSERT(isMainThread()); 457 ASSERT(isMainThread());
436 taskToRun->performTask(scriptExecutionContext); 458 taskToRun->performTask(scriptExecutionContext);
(...skipping 25 matching lines...) Expand all
462 ASSERT(isMainThread()); 484 ASSERT(isMainThread());
463 485
464 MutexLocker locker(m_loaderProxyMutex); 486 MutexLocker locker(m_loaderProxyMutex);
465 if (m_workerLoaderProxy) 487 if (m_workerLoaderProxy)
466 m_workerLoaderProxy->postTaskForModeToWorkerContext(createCallbackTask(& runTaskOnWorkerThread, this, task), mode); 488 m_workerLoaderProxy->postTaskForModeToWorkerContext(createCallbackTask(& runTaskOnWorkerThread, this, task), mode);
467 } 489 }
468 490
469 } // namespace WebCore 491 } // namespace WebCore
470 492
471 #endif // ENABLE(FILE_SYSTEM) 493 #endif // ENABLE(FILE_SYSTEM)
OLDNEW
« no previous file with comments | « WebKit/chromium/src/WorkerFileSystemCallbacksBridge.h ('k') | WebKit/chromium/src/WorkerFileWriterCallbacksBridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698