OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2009, Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 #include "ApplicationCacheBridgeImpl.h" |
| 33 |
| 34 #if ENABLE(APPLICATION_CACHE) |
| 35 |
| 36 #include "ApplicationCacheBridgeClientImpl.h" |
| 37 #include "MainThread.h" |
| 38 #include <wtf/PassRefPtr.h> |
| 39 |
| 40 namespace WebCore { |
| 41 |
| 42 // static |
| 43 void ApplicationCacheBridgeImpl::startup() |
| 44 { |
| 45 ASSERT(isMainThread()); |
| 46 ASSERT(!m_instance); |
| 47 setInstance(new ApplicationCacheBridgeImpl(new ApplicationCacheBridgeClientI
mpl)); |
| 48 } |
| 49 |
| 50 // static |
| 51 void ApplicationCacheBridgeImpl::shutdown() |
| 52 { |
| 53 ASSERT(isMainThread()); |
| 54 ApplicationCacheBridgeImpl* instance = static_cast<ApplicationCacheBridgeImp
l*>(m_instance); |
| 55 if (instance) { |
| 56 delete instance->m_client; |
| 57 delete instance; |
| 58 } |
| 59 } |
| 60 |
| 61 ApplicationCacheBridgeImpl::ApplicationCacheBridgeImpl(ApplicationCacheBridgeCli
ent *client) |
| 62 : ApplicationCacheBridge(client) |
| 63 { |
| 64 m_threadID = createThread(appcacheThreadStart, this, "WebCore: ApplicationCa
che"); |
| 65 } |
| 66 |
| 67 ApplicationCacheBridgeImpl::~ApplicationCacheBridgeImpl() |
| 68 { |
| 69 m_queue.kill(); |
| 70 waitForThreadCompletion(m_threadID, 0); |
| 71 } |
| 72 |
| 73 void ApplicationCacheBridgeImpl::postTaskToBackendThread(PassRefPtr<Task> task) |
| 74 { |
| 75 ASSERT(!m_queue.killed() && m_threadID); |
| 76 m_queue.append(task); |
| 77 } |
| 78 |
| 79 void ApplicationCacheBridgeImpl::postTaskToFrontendThread(PassRefPtr<Task> task) |
| 80 { |
| 81 ASSERT(currentThread() == m_threadID); |
| 82 m_frontendQueue.append(task); |
| 83 callOnMainThread(performFrontendThreadTask, this); |
| 84 } |
| 85 |
| 86 // static |
| 87 void ApplicationCacheBridgeImpl::performFrontendThreadTask(void* self) |
| 88 { |
| 89 ApplicationCacheBridgeImpl* thisPtr = static_cast<ApplicationCacheBridgeImpl
*>(self); |
| 90 RefPtr<Task> task; |
| 91 if (thisPtr->m_frontendQueue.tryGetMessage(task)) |
| 92 task->performTask(thisPtr); |
| 93 } |
| 94 |
| 95 // static |
| 96 void* ApplicationCacheBridgeImpl::appcacheThreadStart(void* self) |
| 97 { |
| 98 return static_cast<ApplicationCacheBridgeImpl*>(self)->appcacheThread(); |
| 99 } |
| 100 |
| 101 void* ApplicationCacheBridgeImpl::appcacheThread() |
| 102 { |
| 103 while (true) { |
| 104 RefPtr<Task> task; |
| 105 if (!m_queue.waitForMessage(task)) |
| 106 break; |
| 107 task->performTask(this); |
| 108 } |
| 109 return 0; |
| 110 } |
| 111 |
| 112 void ApplicationCacheBridgeImpl::initializeContextAsync(const GlobalApplicationC
acheContextID &contextID, |
| 113 ApplicationCacheContex
tType contextType, |
| 114 const GlobalApplicatio
nCacheContextID& parentContextID) |
| 115 { |
| 116 postTaskToBackendThread(InitaliazeContextTask::create(contextID, contextType
, parentContextID)); |
| 117 } |
| 118 |
| 119 void ApplicationCacheBridgeImpl::uninitializeContextAsync(const GlobalApplicatio
nCacheContextID &contextID) |
| 120 { |
| 121 postTaskToBackendThread(UninitializeContextTask::create(contextID)); |
| 122 } |
| 123 |
| 124 void ApplicationCacheBridgeImpl::selectInitialCacheAsync(const GlobalApplication
CacheContextID &contextID, |
| 125 int sequenceNumber, |
| 126 const KURL& documentU
RL, |
| 127 ApplicationCacheID ca
cheDocumentWasLoadedFrom) |
| 128 { |
| 129 postTaskToBackendThread(SelectCacheTask::create(contextID, sequenceNumber)); |
| 130 } |
| 131 |
| 132 void ApplicationCacheBridgeImpl::selectCacheWithoutManifestAsync(const GlobalApp
licationCacheContextID &contextID, |
| 133 int sequenceN
umber, |
| 134 const KURL& d
ocumentURL, |
| 135 ApplicationCa
cheID cacheDocumentWasLoadedFrom) |
| 136 { |
| 137 postTaskToBackendThread(SelectCacheTask::create(contextID, sequenceNumber)); |
| 138 } |
| 139 |
| 140 void ApplicationCacheBridgeImpl::selectCacheWithManifestAsync(const GlobalApplic
ationCacheContextID &contextID, |
| 141 int sequenceNumb
er, |
| 142 const KURL& docu
mentURL, |
| 143 ApplicationCache
ID cacheDocumentWasLoadedFrom, |
| 144 const KURL& mani
festURLofCacheDocumentWasLoadedFrom, |
| 145 const KURL& mani
festURL) |
| 146 { |
| 147 postTaskToBackendThread(SelectCacheTask::create(contextID, sequenceNumber)); |
| 148 } |
| 149 |
| 150 ApplicationCacheStatus ApplicationCacheBridgeImpl::status(const GlobalApplicatio
nCacheContextID &contextID) |
| 151 { |
| 152 RefPtr<GetStatusTask> task = GetStatusTask::create(contextID); |
| 153 postTaskToBackendThread(task); |
| 154 task->waitForCompletion(); |
| 155 return task->m_status; |
| 156 } |
| 157 |
| 158 bool ApplicationCacheBridgeImpl::startUpdate(const GlobalApplicationCacheContext
ID &contextID) |
| 159 { |
| 160 ASSERT(!m_queue.killed() && m_threadID); |
| 161 RefPtr<StartUpdateTask> task = StartUpdateTask::create(contextID); |
| 162 postTaskToBackendThread(task); |
| 163 task->waitForCompletion(); |
| 164 return task->m_result; |
| 165 } |
| 166 |
| 167 bool ApplicationCacheBridgeImpl::swapCache(const GlobalApplicationCacheContextID
&contextID) |
| 168 { |
| 169 ASSERT(!m_queue.killed() && m_threadID); |
| 170 RefPtr<SwapCacheTask> task = SwapCacheTask::create(contextID); |
| 171 postTaskToBackendThread(task); |
| 172 task->waitForCompletion(); |
| 173 return task->m_result; |
| 174 } |
| 175 |
| 176 void ApplicationCacheBridgeImpl::SyncTask::waitForCompletion() |
| 177 { |
| 178 MutexLocker locker(m_lock); |
| 179 m_completionCondition.wait(m_lock); |
| 180 } |
| 181 |
| 182 void ApplicationCacheBridgeImpl::SyncTask::signalCompletion() |
| 183 { |
| 184 MutexLocker locker(m_lock); |
| 185 m_completionCondition.signal(); |
| 186 } |
| 187 |
| 188 void ApplicationCacheBridgeImpl::InitaliazeContextTask::performTask(ApplicationC
acheBridgeImpl* bridge) |
| 189 { |
| 190 // FIXME: implement me |
| 191 } |
| 192 |
| 193 void ApplicationCacheBridgeImpl::UninitializeContextTask::performTask(Applicatio
nCacheBridgeImpl* bridge) |
| 194 { |
| 195 // FIXME: implement me |
| 196 } |
| 197 |
| 198 void ApplicationCacheBridgeImpl::SelectCacheTask::performTask(ApplicationCacheBr
idgeImpl* bridge) |
| 199 { |
| 200 // FIXME: implement me |
| 201 bridge->postTaskToFrontendThread(NotifySelectCompleteTask::create(m_contextI
D, |
| 202 m_cacheSeq
uenceNumber, |
| 203 APPCACHE_U
NCACHED)); |
| 204 } |
| 205 |
| 206 void ApplicationCacheBridgeImpl::GetStatusTask::performTask(ApplicationCacheBrid
geImpl* bridge) |
| 207 { |
| 208 // FIXME: implement me |
| 209 m_status = APPCACHE_UNCACHED; |
| 210 signalCompletion(); |
| 211 } |
| 212 |
| 213 void ApplicationCacheBridgeImpl::StartUpdateTask::performTask(ApplicationCacheBr
idgeImpl* bridge) |
| 214 { |
| 215 // FIXME: implement me |
| 216 m_result = false; |
| 217 signalCompletion(); |
| 218 } |
| 219 |
| 220 void ApplicationCacheBridgeImpl::SwapCacheTask::performTask(ApplicationCacheBrid
geImpl* bridge) |
| 221 { |
| 222 // FIXME: implement me |
| 223 m_result = false; |
| 224 signalCompletion(); |
| 225 } |
| 226 |
| 227 void ApplicationCacheBridgeImpl::NotifySelectCompleteTask::performTask(Applicati
onCacheBridgeImpl* bridge) |
| 228 { |
| 229 bridge->m_client->selectCacheComplete(m_contextID, m_cacheSequenceNumber, m_
status); |
| 230 } |
| 231 |
| 232 void ApplicationCacheBridgeImpl::NotifyStatusChangedTask::performTask(Applicatio
nCacheBridgeImpl* bridge) |
| 233 { |
| 234 bridge->m_client->notifyStatusChanged(m_contextIDs, m_cacheSequenceNumber, m
_status); |
| 235 } |
| 236 |
| 237 void ApplicationCacheBridgeImpl::NotifyEventListenerTask::performTask(Applicatio
nCacheBridgeImpl* bridge) |
| 238 { |
| 239 bridge->m_client->notifyEventListener(m_contextIDs, m_cacheSequenceNumber, m
_eventType); |
| 240 } |
| 241 |
| 242 } // namespace Webcore |
| 243 #endif // ENABLE(APPLICATION_CACHE) |
| 244 |
OLD | NEW |