1/* 2 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free 16 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301 USA 18 */ 19#include "config.h" 20#if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS) 21#include "WorkerPlatformFileWriterClient.h" 22 23#include "AsyncFileWriterBlackBerry.h" 24#include "AsyncFileWriterClient.h" 25#include "CrossThreadTask.h" 26#include "FileError.h" 27#include "WorkerContext.h" 28#include "WorkerLoaderProxy.h" 29#include "WorkerThread.h" 30 31namespace WebCore { 32 33template<> struct CrossThreadCopierBase<false, false, WorkerPlatformFileWriterClient*> : public CrossThreadCopierPassThrough<WorkerPlatformFileWriterClient*> { 34}; 35 36void WorkerPlatformFileWriterClient::notifyWriteOnWorkerThread(ScriptExecutionContext*, WorkerPlatformFileWriterClient* platformClient, long long bytes, bool complete) 37{ 38 platformClient->PlatformFileWriterClient::notifyWrite(bytes, complete); 39} 40 41void WorkerPlatformFileWriterClient::notifyFailOnWorkerThread(ScriptExecutionContext*, WorkerPlatformFileWriterClient* platformClient, BlackBerry::Platform::WebFileError error) 42{ 43 platformClient->PlatformFileWriterClient::notifyFail(error); 44} 45 46void WorkerPlatformFileWriterClient::notifyTruncateOnWorkerThread(ScriptExecutionContext*, WorkerPlatformFileWriterClient* platformClient) 47{ 48 platformClient->PlatformFileWriterClient::notifyTruncate(); 49} 50 51void WorkerPlatformFileWriterClient::notifyWrite(long long bytes, bool complete) 52{ 53 postTaskToWorkerThreadIfNeeded(createCallbackTask(¬ifyWriteOnWorkerThread, this, bytes, complete)); 54} 55 56void WorkerPlatformFileWriterClient::notifyTruncate() 57{ 58 postTaskToWorkerThreadIfNeeded(createCallbackTask(¬ifyTruncateOnWorkerThread, this)); 59} 60 61void WorkerPlatformFileWriterClient::notifyFail(BlackBerry::Platform::WebFileError error) 62{ 63 postTaskToWorkerThreadIfNeeded(createCallbackTask(¬ifyFailOnWorkerThread, this, error)); 64} 65 66void WorkerPlatformFileWriterClient::postTaskToWorkerThreadIfNeeded(PassOwnPtr<ScriptExecutionContext::Task> task) 67{ 68 WTF::MutexLocker locker(m_mutex); 69 if (!m_context) 70 return; 71 72 m_context->thread()->workerLoaderProxy().postTaskForModeToWorkerContext(task, m_mode); 73} 74 75} 76 77#endif 78