Index: loader/appcache2/ApplicationCacheBridgeImpl.cpp |
=================================================================== |
--- loader/appcache2/ApplicationCacheBridgeImpl.cpp (revision 0) |
+++ loader/appcache2/ApplicationCacheBridgeImpl.cpp (revision 0) |
@@ -0,0 +1,244 @@ |
+/* |
+ * Copyright (c) 2009, Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#include "config.h" |
+#include "ApplicationCacheBridgeImpl.h" |
+ |
+#if ENABLE(APPLICATION_CACHE) |
+ |
+#include "ApplicationCacheBridgeClientImpl.h" |
+#include "MainThread.h" |
+#include <wtf/PassRefPtr.h> |
+ |
+namespace WebCore { |
+ |
+// static |
+void ApplicationCacheBridgeImpl::startup() |
+{ |
+ ASSERT(isMainThread()); |
+ ASSERT(!m_instance); |
+ setInstance(new ApplicationCacheBridgeImpl(new ApplicationCacheBridgeClientImpl)); |
+} |
+ |
+// static |
+void ApplicationCacheBridgeImpl::shutdown() |
+{ |
+ ASSERT(isMainThread()); |
+ ApplicationCacheBridgeImpl* instance = static_cast<ApplicationCacheBridgeImpl*>(m_instance); |
+ if (instance) { |
+ delete instance->m_client; |
+ delete instance; |
+ } |
+} |
+ |
+ApplicationCacheBridgeImpl::ApplicationCacheBridgeImpl(ApplicationCacheBridgeClient *client) |
+ : ApplicationCacheBridge(client) |
+{ |
+ m_threadID = createThread(appcacheThreadStart, this, "WebCore: ApplicationCache"); |
+} |
+ |
+ApplicationCacheBridgeImpl::~ApplicationCacheBridgeImpl() |
+{ |
+ m_queue.kill(); |
+ waitForThreadCompletion(m_threadID, 0); |
+} |
+ |
+void ApplicationCacheBridgeImpl::postTaskToBackendThread(PassRefPtr<Task> task) |
+{ |
+ ASSERT(!m_queue.killed() && m_threadID); |
+ m_queue.append(task); |
+} |
+ |
+void ApplicationCacheBridgeImpl::postTaskToFrontendThread(PassRefPtr<Task> task) |
+{ |
+ ASSERT(currentThread() == m_threadID); |
+ m_frontendQueue.append(task); |
+ callOnMainThread(performFrontendThreadTask, this); |
+} |
+ |
+// static |
+void ApplicationCacheBridgeImpl::performFrontendThreadTask(void* self) |
+{ |
+ ApplicationCacheBridgeImpl* thisPtr = static_cast<ApplicationCacheBridgeImpl*>(self); |
+ RefPtr<Task> task; |
+ if (thisPtr->m_frontendQueue.tryGetMessage(task)) |
+ task->performTask(thisPtr); |
+} |
+ |
+// static |
+void* ApplicationCacheBridgeImpl::appcacheThreadStart(void* self) |
+{ |
+ return static_cast<ApplicationCacheBridgeImpl*>(self)->appcacheThread(); |
+} |
+ |
+void* ApplicationCacheBridgeImpl::appcacheThread() |
+{ |
+ while (true) { |
+ RefPtr<Task> task; |
+ if (!m_queue.waitForMessage(task)) |
+ break; |
+ task->performTask(this); |
+ } |
+ return 0; |
+} |
+ |
+void ApplicationCacheBridgeImpl::initializeContextAsync(const GlobalApplicationCacheContextID &contextID, |
+ ApplicationCacheContextType contextType, |
+ const GlobalApplicationCacheContextID& parentContextID) |
+{ |
+ postTaskToBackendThread(InitaliazeContextTask::create(contextID, contextType, parentContextID)); |
+} |
+ |
+void ApplicationCacheBridgeImpl::uninitializeContextAsync(const GlobalApplicationCacheContextID &contextID) |
+{ |
+ postTaskToBackendThread(UninitializeContextTask::create(contextID)); |
+} |
+ |
+void ApplicationCacheBridgeImpl::selectInitialCacheAsync(const GlobalApplicationCacheContextID &contextID, |
+ int sequenceNumber, |
+ const KURL& documentURL, |
+ ApplicationCacheID cacheDocumentWasLoadedFrom) |
+{ |
+ postTaskToBackendThread(SelectCacheTask::create(contextID, sequenceNumber)); |
+} |
+ |
+void ApplicationCacheBridgeImpl::selectCacheWithoutManifestAsync(const GlobalApplicationCacheContextID &contextID, |
+ int sequenceNumber, |
+ const KURL& documentURL, |
+ ApplicationCacheID cacheDocumentWasLoadedFrom) |
+{ |
+ postTaskToBackendThread(SelectCacheTask::create(contextID, sequenceNumber)); |
+} |
+ |
+void ApplicationCacheBridgeImpl::selectCacheWithManifestAsync(const GlobalApplicationCacheContextID &contextID, |
+ int sequenceNumber, |
+ const KURL& documentURL, |
+ ApplicationCacheID cacheDocumentWasLoadedFrom, |
+ const KURL& manifestURLofCacheDocumentWasLoadedFrom, |
+ const KURL& manifestURL) |
+{ |
+ postTaskToBackendThread(SelectCacheTask::create(contextID, sequenceNumber)); |
+} |
+ |
+ApplicationCacheStatus ApplicationCacheBridgeImpl::status(const GlobalApplicationCacheContextID &contextID) |
+{ |
+ RefPtr<GetStatusTask> task = GetStatusTask::create(contextID); |
+ postTaskToBackendThread(task); |
+ task->waitForCompletion(); |
+ return task->m_status; |
+} |
+ |
+bool ApplicationCacheBridgeImpl::startUpdate(const GlobalApplicationCacheContextID &contextID) |
+{ |
+ ASSERT(!m_queue.killed() && m_threadID); |
+ RefPtr<StartUpdateTask> task = StartUpdateTask::create(contextID); |
+ postTaskToBackendThread(task); |
+ task->waitForCompletion(); |
+ return task->m_result; |
+} |
+ |
+bool ApplicationCacheBridgeImpl::swapCache(const GlobalApplicationCacheContextID &contextID) |
+{ |
+ ASSERT(!m_queue.killed() && m_threadID); |
+ RefPtr<SwapCacheTask> task = SwapCacheTask::create(contextID); |
+ postTaskToBackendThread(task); |
+ task->waitForCompletion(); |
+ return task->m_result; |
+} |
+ |
+void ApplicationCacheBridgeImpl::SyncTask::waitForCompletion() |
+{ |
+ MutexLocker locker(m_lock); |
+ m_completionCondition.wait(m_lock); |
+} |
+ |
+void ApplicationCacheBridgeImpl::SyncTask::signalCompletion() |
+{ |
+ MutexLocker locker(m_lock); |
+ m_completionCondition.signal(); |
+} |
+ |
+void ApplicationCacheBridgeImpl::InitaliazeContextTask::performTask(ApplicationCacheBridgeImpl* bridge) |
+{ |
+ // FIXME: implement me |
+} |
+ |
+void ApplicationCacheBridgeImpl::UninitializeContextTask::performTask(ApplicationCacheBridgeImpl* bridge) |
+{ |
+ // FIXME: implement me |
+} |
+ |
+void ApplicationCacheBridgeImpl::SelectCacheTask::performTask(ApplicationCacheBridgeImpl* bridge) |
+{ |
+ // FIXME: implement me |
+ bridge->postTaskToFrontendThread(NotifySelectCompleteTask::create(m_contextID, |
+ m_cacheSequenceNumber, |
+ APPCACHE_UNCACHED)); |
+} |
+ |
+void ApplicationCacheBridgeImpl::GetStatusTask::performTask(ApplicationCacheBridgeImpl* bridge) |
+{ |
+ // FIXME: implement me |
+ m_status = APPCACHE_UNCACHED; |
+ signalCompletion(); |
+} |
+ |
+void ApplicationCacheBridgeImpl::StartUpdateTask::performTask(ApplicationCacheBridgeImpl* bridge) |
+{ |
+ // FIXME: implement me |
+ m_result = false; |
+ signalCompletion(); |
+} |
+ |
+void ApplicationCacheBridgeImpl::SwapCacheTask::performTask(ApplicationCacheBridgeImpl* bridge) |
+{ |
+ // FIXME: implement me |
+ m_result = false; |
+ signalCompletion(); |
+} |
+ |
+void ApplicationCacheBridgeImpl::NotifySelectCompleteTask::performTask(ApplicationCacheBridgeImpl* bridge) |
+{ |
+ bridge->m_client->selectCacheComplete(m_contextID, m_cacheSequenceNumber, m_status); |
+} |
+ |
+void ApplicationCacheBridgeImpl::NotifyStatusChangedTask::performTask(ApplicationCacheBridgeImpl* bridge) |
+{ |
+ bridge->m_client->notifyStatusChanged(m_contextIDs, m_cacheSequenceNumber, m_status); |
+} |
+ |
+void ApplicationCacheBridgeImpl::NotifyEventListenerTask::performTask(ApplicationCacheBridgeImpl* bridge) |
+{ |
+ bridge->m_client->notifyEventListener(m_contextIDs, m_cacheSequenceNumber, m_eventType); |
+} |
+ |
+} // namespace Webcore |
+#endif // ENABLE(APPLICATION_CACHE) |
+ |
Property changes on: loader\appcache2\ApplicationCacheBridgeImpl.cpp |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |