| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 { | 55 { |
| 56 ASSERT(m_workerContext->isContextThread()); | 56 ASSERT(m_workerContext->isContextThread()); |
| 57 m_clientOnWorkerThread = 0; | 57 m_clientOnWorkerThread = 0; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void WorkerFileWriterCallbacksBridge::postWriteToMainThread(long long position,
const KURL& data) | 60 void WorkerFileWriterCallbacksBridge::postWriteToMainThread(long long position,
const KURL& data) |
| 61 { | 61 { |
| 62 ASSERT(!m_operationInProgress); | 62 ASSERT(!m_operationInProgress); |
| 63 m_operationInProgress = true; | 63 m_operationInProgress = true; |
| 64 dispatchTaskToMainThread(createCallbackTask(&writeOnMainThread, | 64 dispatchTaskToMainThread(createCallbackTask(&writeOnMainThread, |
| 65 AllowCrossThreadAccess(this), po
sition, data)); | 65 this, position, data)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void WorkerFileWriterCallbacksBridge::postTruncateToMainThread(long long length) | 68 void WorkerFileWriterCallbacksBridge::postTruncateToMainThread(long long length) |
| 69 { | 69 { |
| 70 ASSERT(!m_operationInProgress); | 70 ASSERT(!m_operationInProgress); |
| 71 m_operationInProgress = true; | 71 m_operationInProgress = true; |
| 72 dispatchTaskToMainThread(createCallbackTask(&truncateOnMainThread, | 72 dispatchTaskToMainThread(createCallbackTask(&truncateOnMainThread, |
| 73 AllowCrossThreadAccess(this), le
ngth)); | 73 this, length)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void WorkerFileWriterCallbacksBridge::postAbortToMainThread() | 76 void WorkerFileWriterCallbacksBridge::postAbortToMainThread() |
| 77 { | 77 { |
| 78 ASSERT(m_operationInProgress); | 78 ASSERT(m_operationInProgress); |
| 79 dispatchTaskToMainThread(createCallbackTask(&abortOnMainThread, AllowCrossTh
readAccess(this))); | 79 dispatchTaskToMainThread(createCallbackTask(&abortOnMainThread, this)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void WorkerFileWriterCallbacksBridge::postShutdownToMainThread(PassRefPtr<Worker
FileWriterCallbacksBridge> bridge) | 82 void WorkerFileWriterCallbacksBridge::postShutdownToMainThread(PassRefPtr<Worker
FileWriterCallbacksBridge> bridge) |
| 83 { | 83 { |
| 84 ASSERT(m_workerContext->isContextThread()); | 84 ASSERT(m_workerContext->isContextThread()); |
| 85 m_clientOnWorkerThread = 0; | 85 m_clientOnWorkerThread = 0; |
| 86 dispatchTaskToMainThread(createCallbackTask(&shutdownOnMainThread, bridge)); | 86 dispatchTaskToMainThread(createCallbackTask(&shutdownOnMainThread, bridge)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void WorkerFileWriterCallbacksBridge::writeOnMainThread(ScriptExecutionContext*,
PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long position, const K
URL& data) | 89 void WorkerFileWriterCallbacksBridge::writeOnMainThread(ScriptExecutionContext*,
PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long position, const K
URL& data) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 108 } | 108 } |
| 109 | 109 |
| 110 void WorkerFileWriterCallbacksBridge::shutdownOnMainThread(ScriptExecutionContex
t*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge) | 110 void WorkerFileWriterCallbacksBridge::shutdownOnMainThread(ScriptExecutionContex
t*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge) |
| 111 { | 111 { |
| 112 bridge->m_writerDeleted = true; | 112 bridge->m_writerDeleted = true; |
| 113 bridge->m_writer.clear(); | 113 bridge->m_writer.clear(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void WorkerFileWriterCallbacksBridge::didWrite(long long bytes, bool complete) | 116 void WorkerFileWriterCallbacksBridge::didWrite(long long bytes, bool complete) |
| 117 { | 117 { |
| 118 dispatchTaskToWorkerThread(createCallbackTask(&didWriteOnWorkerThread, Allow
CrossThreadAccess(this), bytes, complete)); | 118 dispatchTaskToWorkerThread(createCallbackTask(&didWriteOnWorkerThread, this,
bytes, complete)); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void WorkerFileWriterCallbacksBridge::didFail(WebFileError error) | 121 void WorkerFileWriterCallbacksBridge::didFail(WebFileError error) |
| 122 { | 122 { |
| 123 dispatchTaskToWorkerThread(createCallbackTask(&didFailOnWorkerThread, AllowC
rossThreadAccess(this), error)); | 123 dispatchTaskToWorkerThread(createCallbackTask(&didFailOnWorkerThread, this,
error)); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void WorkerFileWriterCallbacksBridge::didTruncate() | 126 void WorkerFileWriterCallbacksBridge::didTruncate() |
| 127 { | 127 { |
| 128 dispatchTaskToWorkerThread(createCallbackTask(&didTruncateOnWorkerThread, Al
lowCrossThreadAccess(this))); | 128 dispatchTaskToWorkerThread(createCallbackTask(&didTruncateOnWorkerThread, th
is)); |
| 129 } | 129 } |
| 130 | 130 |
| 131 static const char fileWriterOperationsMode[] = "fileWriterOperationsMode"; | 131 static const char fileWriterOperationsMode[] = "fileWriterOperationsMode"; |
| 132 | 132 |
| 133 WorkerFileWriterCallbacksBridge::WorkerFileWriterCallbacksBridge(const KURL& pat
h, WorkerLoaderProxy* proxy, ScriptExecutionContext* scriptExecutionContext, Asy
ncFileWriterClient* client) | 133 WorkerFileWriterCallbacksBridge::WorkerFileWriterCallbacksBridge(const KURL& pat
h, WorkerLoaderProxy* proxy, ScriptExecutionContext* scriptExecutionContext, Asy
ncFileWriterClient* client) |
| 134 : WorkerContext::Observer(static_cast<WorkerContext*>(scriptExecutionContext
)) | 134 : WorkerContext::Observer(static_cast<WorkerContext*>(scriptExecutionContext
)) |
| 135 , m_proxy(proxy) | 135 , m_proxy(proxy) |
| 136 , m_workerContext(scriptExecutionContext) | 136 , m_workerContext(scriptExecutionContext) |
| 137 , m_clientOnWorkerThread(client) | 137 , m_clientOnWorkerThread(client) |
| 138 , m_writerDeleted(false) | 138 , m_writerDeleted(false) |
| 139 , m_operationInProgress(false) | 139 , m_operationInProgress(false) |
| 140 { | 140 { |
| 141 ASSERT(m_workerContext->isContextThread()); | 141 ASSERT(m_workerContext->isContextThread()); |
| 142 m_mode = fileWriterOperationsMode; | 142 m_mode = fileWriterOperationsMode; |
| 143 m_mode.append(String::number(static_cast<WorkerContext*>(scriptExecutionCont
ext)->thread()->runLoop().createUniqueId())); | 143 m_mode.append(String::number(static_cast<WorkerContext*>(scriptExecutionCont
ext)->thread()->runLoop().createUniqueId())); |
| 144 postInitToMainThread(path); | 144 postInitToMainThread(path); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void WorkerFileWriterCallbacksBridge::postInitToMainThread(const KURL& path) | 147 void WorkerFileWriterCallbacksBridge::postInitToMainThread(const KURL& path) |
| 148 { | 148 { |
| 149 dispatchTaskToMainThread( | 149 dispatchTaskToMainThread( |
| 150 createCallbackTask(&initOnMainThread, AllowCrossThreadAccess(this), path
)); | 150 createCallbackTask(&initOnMainThread, this, path)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 WorkerFileWriterCallbacksBridge::~WorkerFileWriterCallbacksBridge() | 153 WorkerFileWriterCallbacksBridge::~WorkerFileWriterCallbacksBridge() |
| 154 { | 154 { |
| 155 ASSERT(!m_clientOnWorkerThread); | 155 ASSERT(!m_clientOnWorkerThread); |
| 156 ASSERT(!m_writer); | 156 ASSERT(!m_writer); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // We know m_clientOnWorkerThread is still valid because it is only cleared on t
he context thread, and because we check in runTaskOnWorkerThread before calling
any of these methods. | 159 // We know m_clientOnWorkerThread is still valid because it is only cleared on t
he context thread, and because we check in runTaskOnWorkerThread before calling
any of these methods. |
| 160 void WorkerFileWriterCallbacksBridge::didWriteOnWorkerThread(ScriptExecutionCont
ext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long length, bool
complete) | 160 void WorkerFileWriterCallbacksBridge::didWriteOnWorkerThread(ScriptExecutionCont
ext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long length, bool
complete) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 { | 193 { |
| 194 ASSERT(bridge->m_workerContext->isContextThread()); | 194 ASSERT(bridge->m_workerContext->isContextThread()); |
| 195 if (bridge->m_clientOnWorkerThread) | 195 if (bridge->m_clientOnWorkerThread) |
| 196 taskToRun->performTask(scriptExecutionContext); | 196 taskToRun->performTask(scriptExecutionContext); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void WorkerFileWriterCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<Script
ExecutionContext::Task> task) | 199 void WorkerFileWriterCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<Script
ExecutionContext::Task> task) |
| 200 { | 200 { |
| 201 ASSERT(m_workerContext->isContextThread()); | 201 ASSERT(m_workerContext->isContextThread()); |
| 202 WebWorkerBase::dispatchTaskToMainThread( | 202 WebWorkerBase::dispatchTaskToMainThread( |
| 203 createCallbackTask(&runTaskOnMainThread, AllowCrossThreadAccess(this), t
ask)); | 203 createCallbackTask(&runTaskOnMainThread, this, task)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void WorkerFileWriterCallbacksBridge::dispatchTaskToWorkerThread(PassOwnPtr<Scri
ptExecutionContext::Task> task) | 206 void WorkerFileWriterCallbacksBridge::dispatchTaskToWorkerThread(PassOwnPtr<Scri
ptExecutionContext::Task> task) |
| 207 { | 207 { |
| 208 ASSERT(isMainThread()); | 208 ASSERT(isMainThread()); |
| 209 m_proxy->postTaskForModeToWorkerContext( | 209 m_proxy->postTaskForModeToWorkerContext( |
| 210 createCallbackTask(&runTaskOnWorkerThread, AllowCrossThreadAccess(this),
task), m_mode); | 210 createCallbackTask(&runTaskOnWorkerThread, this, task), m_mode); |
| 211 } | 211 } |
| 212 | 212 |
| 213 bool WorkerFileWriterCallbacksBridge::waitForOperationToComplete() | 213 bool WorkerFileWriterCallbacksBridge::waitForOperationToComplete() |
| 214 { | 214 { |
| 215 while (m_operationInProgress) { | 215 while (m_operationInProgress) { |
| 216 WorkerContext* context = static_cast<WorkerContext*>(m_workerContext); | 216 WorkerContext* context = static_cast<WorkerContext*>(m_workerContext); |
| 217 if (context->thread()->runLoop().runInMode(context, m_mode) == MessageQu
eueTerminated) | 217 if (context->thread()->runLoop().runInMode(context, m_mode) == MessageQu
eueTerminated) |
| 218 return false; | 218 return false; |
| 219 } | 219 } |
| 220 return true; | 220 return true; |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace WebKit | 223 } // namespace WebKit |
| 224 | 224 |
| 225 #endif // ENABLE(FILE_SYSTEM) | 225 #endif // ENABLE(FILE_SYSTEM) |
| OLD | NEW |