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

Side by Side Diff: Source/WebKit/chromium/src/WorkerFileWriterCallbacksBridge.cpp

Issue 17648006: Rename WorkerContext to WorkerGlobalScope (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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 16 matching lines...) Expand all
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 "WorkerFileWriterCallbacksBridge.h" 32 #include "WorkerFileWriterCallbacksBridge.h"
33 33
34 #include "WebFileWriter.h" 34 #include "WebFileWriter.h"
35 #include "WebWorkerBase.h" 35 #include "WebWorkerBase.h"
36 #include "core/dom/CrossThreadTask.h" 36 #include "core/dom/CrossThreadTask.h"
37 #include "core/workers/WorkerContext.h" 37 #include "core/workers/WorkerGlobalScope.h"
38 #include "core/workers/WorkerLoaderProxy.h" 38 #include "core/workers/WorkerLoaderProxy.h"
39 #include "core/workers/WorkerThread.h" 39 #include "core/workers/WorkerThread.h"
40 #include "modules/filesystem/AsyncFileWriterClient.h" 40 #include "modules/filesystem/AsyncFileWriterClient.h"
41 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
42 #include "public/platform/WebCString.h" 42 #include "public/platform/WebCString.h"
43 #include "public/platform/WebFileSystem.h" 43 #include "public/platform/WebFileSystem.h"
44 #include <wtf/MainThread.h> 44 #include <wtf/MainThread.h>
45 #include <wtf/Threading.h> 45 #include <wtf/Threading.h>
46 46
47 using namespace WebCore; 47 using namespace WebCore;
48 48
49 namespace WebKit { 49 namespace WebKit {
50 50
51 void WorkerFileWriterCallbacksBridge::notifyStop() 51 void WorkerFileWriterCallbacksBridge::notifyStop()
52 { 52 {
53 ASSERT(m_workerContext->isContextThread()); 53 ASSERT(m_workerGlobalScope->isContextThread());
54 m_clientOnWorkerThread = 0; 54 m_clientOnWorkerThread = 0;
55 { 55 {
56 MutexLocker locker(m_loaderProxyMutex); 56 MutexLocker locker(m_loaderProxyMutex);
57 m_proxy = 0; 57 m_proxy = 0;
58 } 58 }
59 } 59 }
60 60
61 void WorkerFileWriterCallbacksBridge::postWriteToMainThread(long long position, const KURL& data) 61 void WorkerFileWriterCallbacksBridge::postWriteToMainThread(long long position, const KURL& data)
62 { 62 {
63 ASSERT(!m_operationInProgress); 63 ASSERT(!m_operationInProgress);
(...skipping 11 matching lines...) Expand all
75 } 75 }
76 76
77 void WorkerFileWriterCallbacksBridge::postAbortToMainThread() 77 void WorkerFileWriterCallbacksBridge::postAbortToMainThread()
78 { 78 {
79 ASSERT(m_operationInProgress); 79 ASSERT(m_operationInProgress);
80 dispatchTaskToMainThread(createCallbackTask(&abortOnMainThread, this)); 80 dispatchTaskToMainThread(createCallbackTask(&abortOnMainThread, this));
81 } 81 }
82 82
83 void WorkerFileWriterCallbacksBridge::postShutdownToMainThread(PassRefPtr<Worker FileWriterCallbacksBridge> bridge) 83 void WorkerFileWriterCallbacksBridge::postShutdownToMainThread(PassRefPtr<Worker FileWriterCallbacksBridge> bridge)
84 { 84 {
85 ASSERT(m_workerContext->isContextThread()); 85 ASSERT(m_workerGlobalScope->isContextThread());
86 m_clientOnWorkerThread = 0; 86 m_clientOnWorkerThread = 0;
87 dispatchTaskToMainThread(createCallbackTask(&shutdownOnMainThread, bridge)); 87 dispatchTaskToMainThread(createCallbackTask(&shutdownOnMainThread, bridge));
88 } 88 }
89 89
90 void WorkerFileWriterCallbacksBridge::writeOnMainThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long position, const K URL& data) 90 void WorkerFileWriterCallbacksBridge::writeOnMainThread(ScriptExecutionContext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long position, const K URL& data)
91 { 91 {
92 bridge->m_writer->write(position, WebURL(data)); 92 bridge->m_writer->write(position, WebURL(data));
93 } 93 }
94 94
95 void WorkerFileWriterCallbacksBridge::truncateOnMainThread(ScriptExecutionContex t*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long length) 95 void WorkerFileWriterCallbacksBridge::truncateOnMainThread(ScriptExecutionContex t*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long length)
(...skipping 29 matching lines...) Expand all
125 } 125 }
126 126
127 void WorkerFileWriterCallbacksBridge::didTruncate() 127 void WorkerFileWriterCallbacksBridge::didTruncate()
128 { 128 {
129 dispatchTaskToWorkerThread(createCallbackTask(&didTruncateOnWorkerThread, th is)); 129 dispatchTaskToWorkerThread(createCallbackTask(&didTruncateOnWorkerThread, th is));
130 } 130 }
131 131
132 static const char fileWriterOperationsMode[] = "fileWriterOperationsMode"; 132 static const char fileWriterOperationsMode[] = "fileWriterOperationsMode";
133 133
134 WorkerFileWriterCallbacksBridge::WorkerFileWriterCallbacksBridge(const KURL& pat h, WorkerLoaderProxy* proxy, ScriptExecutionContext* scriptExecutionContext, Asy ncFileWriterClient* client) 134 WorkerFileWriterCallbacksBridge::WorkerFileWriterCallbacksBridge(const KURL& pat h, WorkerLoaderProxy* proxy, ScriptExecutionContext* scriptExecutionContext, Asy ncFileWriterClient* client)
135 : WorkerContext::Observer(static_cast<WorkerContext*>(scriptExecutionContext )) 135 : WorkerGlobalScope::Observer(static_cast<WorkerGlobalScope*>(scriptExecutio nContext))
136 , m_proxy(proxy) 136 , m_proxy(proxy)
137 , m_workerContext(scriptExecutionContext) 137 , m_workerGlobalScope(scriptExecutionContext)
138 , m_clientOnWorkerThread(client) 138 , m_clientOnWorkerThread(client)
139 , m_writerDeleted(false) 139 , m_writerDeleted(false)
140 , m_operationInProgress(false) 140 , m_operationInProgress(false)
141 { 141 {
142 ASSERT(m_workerContext->isContextThread()); 142 ASSERT(m_workerGlobalScope->isContextThread());
143 m_mode = fileWriterOperationsMode; 143 m_mode = fileWriterOperationsMode;
144 m_mode.append(String::number(static_cast<WorkerContext*>(scriptExecutionCont ext)->thread()->runLoop().createUniqueId())); 144 m_mode.append(String::number(static_cast<WorkerGlobalScope*>(scriptExecution Context)->thread()->runLoop().createUniqueId()));
145 postInitToMainThread(path); 145 postInitToMainThread(path);
146 } 146 }
147 147
148 void WorkerFileWriterCallbacksBridge::postInitToMainThread(const KURL& path) 148 void WorkerFileWriterCallbacksBridge::postInitToMainThread(const KURL& path)
149 { 149 {
150 dispatchTaskToMainThread( 150 dispatchTaskToMainThread(
151 createCallbackTask(&initOnMainThread, this, path)); 151 createCallbackTask(&initOnMainThread, this, path));
152 } 152 }
153 153
154 WorkerFileWriterCallbacksBridge::~WorkerFileWriterCallbacksBridge() 154 WorkerFileWriterCallbacksBridge::~WorkerFileWriterCallbacksBridge()
155 { 155 {
156 ASSERT(!m_clientOnWorkerThread); 156 ASSERT(!m_clientOnWorkerThread);
157 ASSERT(!m_writer); 157 ASSERT(!m_writer);
158 } 158 }
159 159
160 // 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 // 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.
161 void WorkerFileWriterCallbacksBridge::didWriteOnWorkerThread(ScriptExecutionCont ext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long length, bool complete) 161 void WorkerFileWriterCallbacksBridge::didWriteOnWorkerThread(ScriptExecutionCont ext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, long long length, bool complete)
162 { 162 {
163 ASSERT(bridge->m_workerContext->isContextThread()); 163 ASSERT(bridge->m_workerGlobalScope->isContextThread());
164 ASSERT(bridge->m_operationInProgress); 164 ASSERT(bridge->m_operationInProgress);
165 if (complete) 165 if (complete)
166 bridge->m_operationInProgress = false; 166 bridge->m_operationInProgress = false;
167 bridge->m_clientOnWorkerThread->didWrite(length, complete); 167 bridge->m_clientOnWorkerThread->didWrite(length, complete);
168 } 168 }
169 169
170 void WorkerFileWriterCallbacksBridge::didFailOnWorkerThread(ScriptExecutionConte xt*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, WebFileError error) 170 void WorkerFileWriterCallbacksBridge::didFailOnWorkerThread(ScriptExecutionConte xt*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, WebFileError error)
171 { 171 {
172 ASSERT(bridge->m_workerContext->isContextThread()); 172 ASSERT(bridge->m_workerGlobalScope->isContextThread());
173 ASSERT(bridge->m_operationInProgress); 173 ASSERT(bridge->m_operationInProgress);
174 bridge->m_operationInProgress = false; 174 bridge->m_operationInProgress = false;
175 bridge->m_clientOnWorkerThread->didFail(static_cast<FileError::ErrorCode>(er ror)); 175 bridge->m_clientOnWorkerThread->didFail(static_cast<FileError::ErrorCode>(er ror));
176 } 176 }
177 177
178 void WorkerFileWriterCallbacksBridge::didTruncateOnWorkerThread(ScriptExecutionC ontext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge) 178 void WorkerFileWriterCallbacksBridge::didTruncateOnWorkerThread(ScriptExecutionC ontext*, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge)
179 { 179 {
180 ASSERT(bridge->m_workerContext->isContextThread()); 180 ASSERT(bridge->m_workerGlobalScope->isContextThread());
181 ASSERT(bridge->m_operationInProgress); 181 ASSERT(bridge->m_operationInProgress);
182 bridge->m_operationInProgress = false; 182 bridge->m_operationInProgress = false;
183 bridge->m_clientOnWorkerThread->didTruncate(); 183 bridge->m_clientOnWorkerThread->didTruncate();
184 } 184 }
185 185
186 void WorkerFileWriterCallbacksBridge::runTaskOnMainThread(ScriptExecutionContext * scriptExecutionContext, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, Pa ssOwnPtr<ScriptExecutionContext::Task> taskToRun) 186 void WorkerFileWriterCallbacksBridge::runTaskOnMainThread(ScriptExecutionContext * scriptExecutionContext, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, Pa ssOwnPtr<ScriptExecutionContext::Task> taskToRun)
187 { 187 {
188 ASSERT(isMainThread()); 188 ASSERT(isMainThread());
189 if (!bridge->m_writerDeleted) 189 if (!bridge->m_writerDeleted)
190 taskToRun->performTask(scriptExecutionContext); 190 taskToRun->performTask(scriptExecutionContext);
191 } 191 }
192 192
193 void WorkerFileWriterCallbacksBridge::runTaskOnWorkerThread(ScriptExecutionConte xt* scriptExecutionContext, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, PassOwnPtr<ScriptExecutionContext::Task> taskToRun) 193 void WorkerFileWriterCallbacksBridge::runTaskOnWorkerThread(ScriptExecutionConte xt* scriptExecutionContext, PassRefPtr<WorkerFileWriterCallbacksBridge> bridge, PassOwnPtr<ScriptExecutionContext::Task> taskToRun)
194 { 194 {
195 ASSERT(bridge->m_workerContext->isContextThread()); 195 ASSERT(bridge->m_workerGlobalScope->isContextThread());
196 if (bridge->m_clientOnWorkerThread) 196 if (bridge->m_clientOnWorkerThread)
197 taskToRun->performTask(scriptExecutionContext); 197 taskToRun->performTask(scriptExecutionContext);
198 } 198 }
199 199
200 void WorkerFileWriterCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<Script ExecutionContext::Task> task) 200 void WorkerFileWriterCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<Script ExecutionContext::Task> task)
201 { 201 {
202 ASSERT(m_workerContext->isContextThread()); 202 ASSERT(m_workerGlobalScope->isContextThread());
203 WebWorkerBase::dispatchTaskToMainThread( 203 WebWorkerBase::dispatchTaskToMainThread(
204 createCallbackTask(&runTaskOnMainThread, this, task)); 204 createCallbackTask(&runTaskOnMainThread, this, task));
205 } 205 }
206 206
207 void WorkerFileWriterCallbacksBridge::dispatchTaskToWorkerThread(PassOwnPtr<Scri ptExecutionContext::Task> task) 207 void WorkerFileWriterCallbacksBridge::dispatchTaskToWorkerThread(PassOwnPtr<Scri ptExecutionContext::Task> task)
208 { 208 {
209 ASSERT(isMainThread()); 209 ASSERT(isMainThread());
210 210
211 MutexLocker locker(m_loaderProxyMutex); 211 MutexLocker locker(m_loaderProxyMutex);
212 if (m_proxy) 212 if (m_proxy)
213 m_proxy->postTaskForModeToWorkerContext( 213 m_proxy->postTaskForModeToWorkerGlobalScope(
214 createCallbackTask(&runTaskOnWorkerThread, this, task), m_mode); 214 createCallbackTask(&runTaskOnWorkerThread, this, task), m_mode);
215 } 215 }
216 216
217 bool WorkerFileWriterCallbacksBridge::waitForOperationToComplete() 217 bool WorkerFileWriterCallbacksBridge::waitForOperationToComplete()
218 { 218 {
219 while (m_operationInProgress) { 219 while (m_operationInProgress) {
220 WorkerContext* context = static_cast<WorkerContext*>(m_workerContext); 220 WorkerGlobalScope* context = static_cast<WorkerGlobalScope*>(m_workerGlo balScope);
221 if (context->thread()->runLoop().runInMode(context, m_mode) == MessageQu eueTerminated) 221 if (context->thread()->runLoop().runInMode(context, m_mode) == MessageQu eueTerminated)
222 return false; 222 return false;
223 } 223 }
224 return true; 224 return true;
225 } 225 }
226 226
227 } // namespace WebKit 227 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698