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

Side by Side Diff: Source/WebKit/chromium/src/WorkerStorageQuotaCallbacksBridge.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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "WorkerStorageQuotaCallbacksBridge.h" 32 #include "WorkerStorageQuotaCallbacksBridge.h"
33 33
34 #include "WebCommonWorkerClient.h" 34 #include "WebCommonWorkerClient.h"
35 #include "WebStorageQuotaCallbacks.h" 35 #include "WebStorageQuotaCallbacks.h"
36 #include "WebStorageQuotaCallbacksImpl.h" 36 #include "WebStorageQuotaCallbacksImpl.h"
37 #include "WebWorkerBase.h" 37 #include "WebWorkerBase.h"
38 #include "core/dom/CrossThreadTask.h" 38 #include "core/dom/CrossThreadTask.h"
39 #include "core/workers/WorkerContext.h" 39 #include "core/workers/WorkerGlobalScope.h"
40 #include "core/workers/WorkerLoaderProxy.h" 40 #include "core/workers/WorkerLoaderProxy.h"
41 #include "wtf/MainThread.h" 41 #include "wtf/MainThread.h"
42 42
43 using namespace WebCore; 43 using namespace WebCore;
44 44
45 namespace WebKit { 45 namespace WebKit {
46 46
47 // FIXME: Replace WebFrame parameter in queryStorageUsageAndQuota() with WebStri ng and move the method to Platform so that we can remove all these complexity fo r Worker. 47 // FIXME: Replace WebFrame parameter in queryStorageUsageAndQuota() with WebStri ng and move the method to Platform so that we can remove all these complexity fo r Worker.
48 class MainThreadStorageQuotaCallbacks : public WebStorageQuotaCallbacks { 48 class MainThreadStorageQuotaCallbacks : public WebStorageQuotaCallbacks {
49 public: 49 public:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 ASSERT(m_bridge); 83 ASSERT(m_bridge);
84 } 84 }
85 85
86 RefPtr<WorkerStorageQuotaCallbacksBridge> m_bridge; 86 RefPtr<WorkerStorageQuotaCallbacksBridge> m_bridge;
87 const String m_mode; 87 const String m_mode;
88 }; 88 };
89 89
90 // FIXME: Replace WebFrame parameter in queryStorageUsageAndQuota() with WebStri ng and move the method to Platform so that we can remove all these complexity fo r Worker." 90 // FIXME: Replace WebFrame parameter in queryStorageUsageAndQuota() with WebStri ng and move the method to Platform so that we can remove all these complexity fo r Worker."
91 // Observes the worker context. By keeping this separate, it is easier to verify 91 // Observes the worker context. By keeping this separate, it is easier to verify
92 // that it only gets deleted on the worker context thread which is verified by ~ Observer. 92 // that it only gets deleted on the worker context thread which is verified by ~ Observer.
93 class WorkerStorageQuotaContextObserver : public WebCore::WorkerContext::Observe r { 93 class WorkerStorageQuotaContextObserver : public WebCore::WorkerGlobalScope::Obs erver {
94 public: 94 public:
95 static PassOwnPtr<WorkerStorageQuotaContextObserver> create(WorkerContext* c ontext, PassRefPtr<WorkerStorageQuotaCallbacksBridge> bridge) 95 static PassOwnPtr<WorkerStorageQuotaContextObserver> create(WorkerGlobalScop e* context, PassRefPtr<WorkerStorageQuotaCallbacksBridge> bridge)
96 { 96 {
97 return adoptPtr(new WorkerStorageQuotaContextObserver(context, bridge)); 97 return adoptPtr(new WorkerStorageQuotaContextObserver(context, bridge));
98 } 98 }
99 99
100 // WorkerContext::Observer method. 100 // WorkerGlobalScope::Observer method.
101 virtual void notifyStop() 101 virtual void notifyStop()
102 { 102 {
103 m_bridge->stop(); 103 m_bridge->stop();
104 } 104 }
105 105
106 private: 106 private:
107 WorkerStorageQuotaContextObserver(WorkerContext* context, PassRefPtr<WorkerS torageQuotaCallbacksBridge> bridge) 107 WorkerStorageQuotaContextObserver(WorkerGlobalScope* context, PassRefPtr<Wor kerStorageQuotaCallbacksBridge> bridge)
108 : WebCore::WorkerContext::Observer(context) 108 : WebCore::WorkerGlobalScope::Observer(context)
109 , m_bridge(bridge) 109 , m_bridge(bridge)
110 { 110 {
111 } 111 }
112 112
113 RefPtr<WorkerStorageQuotaCallbacksBridge> m_bridge; 113 RefPtr<WorkerStorageQuotaCallbacksBridge> m_bridge;
114 }; 114 };
115 115
116 void WorkerStorageQuotaCallbacksBridge::stop() 116 void WorkerStorageQuotaCallbacksBridge::stop()
117 { 117 {
118 ASSERT(m_workerContext->isContextThread()); 118 ASSERT(m_workerGlobalScope->isContextThread());
119 { 119 {
120 MutexLocker locker(m_loaderProxyMutex); 120 MutexLocker locker(m_loaderProxyMutex);
121 m_workerLoaderProxy = 0; 121 m_workerLoaderProxy = 0;
122 } 122 }
123 123
124 if (m_callbacksOnWorkerThread) 124 if (m_callbacksOnWorkerThread)
125 m_callbacksOnWorkerThread->didFail(WebStorageQuotaErrorAbort); 125 m_callbacksOnWorkerThread->didFail(WebStorageQuotaErrorAbort);
126 126
127 cleanUpAfterCallback(); 127 cleanUpAfterCallback();
128 } 128 }
129 129
130 void WorkerStorageQuotaCallbacksBridge::cleanUpAfterCallback() 130 void WorkerStorageQuotaCallbacksBridge::cleanUpAfterCallback()
131 { 131 {
132 ASSERT(m_workerContext->isContextThread()); 132 ASSERT(m_workerGlobalScope->isContextThread());
133 133
134 m_callbacksOnWorkerThread = 0; 134 m_callbacksOnWorkerThread = 0;
135 if (m_workerContextObserver) { 135 if (m_workerGlobalScopeObserver) {
136 WorkerStorageQuotaContextObserver* observer = m_workerContextObserver; 136 WorkerStorageQuotaContextObserver* observer = m_workerGlobalScopeObserve r;
137 m_workerContextObserver = 0; 137 m_workerGlobalScopeObserver = 0;
138 // The next line may delete this. 138 // The next line may delete this.
139 delete observer; 139 delete observer;
140 } 140 }
141 } 141 }
142 142
143 WorkerStorageQuotaCallbacksBridge::WorkerStorageQuotaCallbacksBridge(WebCore::Wo rkerLoaderProxy* workerLoaderProxy, WebCore::ScriptExecutionContext* workerConte xt, WebStorageQuotaCallbacksImpl* callbacks) 143 WorkerStorageQuotaCallbacksBridge::WorkerStorageQuotaCallbacksBridge(WebCore::Wo rkerLoaderProxy* workerLoaderProxy, WebCore::ScriptExecutionContext* workerGloba lScope, WebStorageQuotaCallbacksImpl* callbacks)
144 : m_workerLoaderProxy(workerLoaderProxy) 144 : m_workerLoaderProxy(workerLoaderProxy)
145 , m_workerContext(workerContext) 145 , m_workerGlobalScope(workerGlobalScope)
146 , m_workerContextObserver(WorkerStorageQuotaContextObserver::create(static_c ast<WorkerContext*>(m_workerContext), this).leakPtr()) 146 , m_workerGlobalScopeObserver(WorkerStorageQuotaContextObserver::create(stat ic_cast<WorkerGlobalScope*>(m_workerGlobalScope), this).leakPtr())
147 , m_callbacksOnWorkerThread(callbacks) 147 , m_callbacksOnWorkerThread(callbacks)
148 { 148 {
149 ASSERT(m_workerContext->isContextThread()); 149 ASSERT(m_workerGlobalScope->isContextThread());
150 } 150 }
151 151
152 WorkerStorageQuotaCallbacksBridge::~WorkerStorageQuotaCallbacksBridge() 152 WorkerStorageQuotaCallbacksBridge::~WorkerStorageQuotaCallbacksBridge()
153 { 153 {
154 // One way or another, the bridge should be stopped before it is destroyed. 154 // One way or another, the bridge should be stopped before it is destroyed.
155 ASSERT(!m_callbacksOnWorkerThread); 155 ASSERT(!m_callbacksOnWorkerThread);
156 } 156 }
157 157
158 void WorkerStorageQuotaCallbacksBridge::postQueryUsageAndQuotaToMainThread(WebCo mmonWorkerClient* commonClient, WebStorageQuotaType storageType, const String& m ode) 158 void WorkerStorageQuotaCallbacksBridge::postQueryUsageAndQuotaToMainThread(WebCo mmonWorkerClient* commonClient, WebStorageQuotaType storageType, const String& m ode)
159 { 159 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 { 192 {
193 ASSERT(isMainThread()); 193 ASSERT(isMainThread());
194 taskToRun->performTask(scriptExecutionContext); 194 taskToRun->performTask(scriptExecutionContext);
195 } 195 }
196 196
197 void WorkerStorageQuotaCallbacksBridge::runTaskOnWorkerThread(WebCore::ScriptExe cutionContext* scriptExecutionContext, PassRefPtr<WorkerStorageQuotaCallbacksBri dge> bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun) 197 void WorkerStorageQuotaCallbacksBridge::runTaskOnWorkerThread(WebCore::ScriptExe cutionContext* scriptExecutionContext, PassRefPtr<WorkerStorageQuotaCallbacksBri dge> bridge, PassOwnPtr<WebCore::ScriptExecutionContext::Task> taskToRun)
198 { 198 {
199 ASSERT(bridge); 199 ASSERT(bridge);
200 if (!bridge->m_callbacksOnWorkerThread) 200 if (!bridge->m_callbacksOnWorkerThread)
201 return; 201 return;
202 ASSERT(bridge->m_workerContext); 202 ASSERT(bridge->m_workerGlobalScope);
203 ASSERT(bridge->m_workerContext->isContextThread()); 203 ASSERT(bridge->m_workerGlobalScope->isContextThread());
204 ASSERT(taskToRun); 204 ASSERT(taskToRun);
205 taskToRun->performTask(scriptExecutionContext); 205 taskToRun->performTask(scriptExecutionContext);
206 206
207 // taskToRun does the callback. 207 // taskToRun does the callback.
208 bridge->cleanUpAfterCallback(); 208 bridge->cleanUpAfterCallback();
209 209
210 // WorkerStorageQuotaCallbacksBridge may be deleted here when bridge goes ou t of scope. 210 // WorkerStorageQuotaCallbacksBridge may be deleted here when bridge goes ou t of scope.
211 } 211 }
212 212
213 void WorkerStorageQuotaCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<WebC ore::ScriptExecutionContext::Task> task) 213 void WorkerStorageQuotaCallbacksBridge::dispatchTaskToMainThread(PassOwnPtr<WebC ore::ScriptExecutionContext::Task> task)
214 { 214 {
215 ASSERT(m_workerLoaderProxy); 215 ASSERT(m_workerLoaderProxy);
216 ASSERT(m_workerContext->isContextThread()); 216 ASSERT(m_workerGlobalScope->isContextThread());
217 WebWorkerBase::dispatchTaskToMainThread(createCallbackTask(&runTaskOnMainThr ead, RefPtr<WorkerStorageQuotaCallbacksBridge>(this).release(), task)); 217 WebWorkerBase::dispatchTaskToMainThread(createCallbackTask(&runTaskOnMainThr ead, RefPtr<WorkerStorageQuotaCallbacksBridge>(this).release(), task));
218 } 218 }
219 219
220 void WorkerStorageQuotaCallbacksBridge::mayPostTaskToWorker(PassOwnPtr<ScriptExe cutionContext::Task> task, const String& mode) 220 void WorkerStorageQuotaCallbacksBridge::mayPostTaskToWorker(PassOwnPtr<ScriptExe cutionContext::Task> task, const String& mode)
221 { 221 {
222 // Relies on its caller (MainThreadStorageQuotaCallbacks:did*) to keep Worke rStorageQuotaCallbacksBridge alive. 222 // Relies on its caller (MainThreadStorageQuotaCallbacks:did*) to keep Worke rStorageQuotaCallbacksBridge alive.
223 ASSERT(isMainThread()); 223 ASSERT(isMainThread());
224 224
225 MutexLocker locker(m_loaderProxyMutex); 225 MutexLocker locker(m_loaderProxyMutex);
226 if (m_workerLoaderProxy) 226 if (m_workerLoaderProxy)
227 m_workerLoaderProxy->postTaskForModeToWorkerContext(createCallbackTask(& runTaskOnWorkerThread, this, task), mode); 227 m_workerLoaderProxy->postTaskForModeToWorkerGlobalScope(createCallbackTa sk(&runTaskOnWorkerThread, this, task), mode);
228 } 228 }
229 229
230 } // namespace WebCore 230 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/src/WorkerStorageQuotaCallbacksBridge.h ('k') | Source/bindings/bindings.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698