Index: loader/appcache2/ApplicationCacheBridgeImpl.h |
=================================================================== |
--- loader/appcache2/ApplicationCacheBridgeImpl.h (revision 0) |
+++ loader/appcache2/ApplicationCacheBridgeImpl.h (revision 0) |
@@ -0,0 +1,336 @@ |
+/* |
+ * 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. |
+ */ |
+ |
+#ifndef ApplicationCacheBridgeImpl_h |
+#define ApplicationCacheBridgeImpl_h |
+ |
+#if ENABLE(APPLICATION_CACHE) |
+ |
+#include "ApplicationCacheBridge.h" |
+#include <wtf/MessageQueue.h> |
+#include <wtf/RefPtr.h> |
+#include <wtf/Threading.h> |
+ |
+namespace WebCore { |
+ |
+ class ApplicationCacheBackend; |
+ class ApplicationCacheTask; |
+ |
+ // A implementation for use in single-process browsers. This impl starts |
+ // a background thread in the current process and queues tasks to be performed |
+ // by the backend on that thread. Async results are delivered back to the |
+ // frontend thread. |
+ // |
+ // FIXME: sooner, put in place interfaces for use by a fatter appcache |
+ // savvy ResourceHandle so appcached responses are retrieved in the act |
+ // of resource handle loading. |
+ // |
+ // FIXME: later, integrate with workers. accomodate method calls and client |
+ // callbacks on worker threads too. Either allow this interface to be used on |
+ // worker threads too, or use a worker specific 'frontendproxy' to to the |
+ // thread hopping on behalf of workers (probably the latter). |
+ // At present this impl can only be used on the main thread. |
+ class ApplicationCacheBridgeImpl : public ApplicationCacheBridge { |
+ public: |
+ // A host browser should call startup and shutdown on the main thread |
+ // at browser startup and shutdown time respectively. |
+ static void startup(); |
+ static void shutdown(); |
+ |
+ // ApplicationCacheBridge interface |
+ |
+ virtual void initializeContextAsync(const GlobalApplicationCacheContextID &contextID, |
+ ApplicationCacheContextType contextType, |
+ const GlobalApplicationCacheContextID& parentContextID); |
+ virtual void uninitializeContextAsync(const GlobalApplicationCacheContextID &contextID); |
+ |
+ virtual void selectInitialCacheAsync(const GlobalApplicationCacheContextID &contextID, |
+ int sequenceNumber, |
+ const KURL& documentURL, |
+ ApplicationCacheID cacheDocumentWasLoadedFrom); |
+ virtual void selectCacheWithoutManifestAsync(const GlobalApplicationCacheContextID &contextID, |
+ int sequenceNumber, |
+ const KURL& documentURL, |
+ ApplicationCacheID cacheDocumentWasLoadedFrom); |
+ virtual void selectCacheWithManifestAsync(const GlobalApplicationCacheContextID &contextID, |
+ int sequenceNumber, |
+ const KURL& documentURL, |
+ ApplicationCacheID cacheDocumentWasLoadedFrom, |
+ const KURL& manifestURLofCacheDocumentWasLoadedFrom, |
+ const KURL& manifestURL); |
+ |
+ virtual ApplicationCacheStatus status(const GlobalApplicationCacheContextID &contextID); |
+ virtual bool startUpdate(const GlobalApplicationCacheContextID &contextID); |
+ virtual bool swapCache(const GlobalApplicationCacheContextID &contextID); |
+ |
+ private: |
+ ApplicationCacheBridgeImpl(ApplicationCacheBridgeClient* client); |
+ virtual ~ApplicationCacheBridgeImpl(); |
+ |
+ class Task; // See the concrete task classes below. |
+ void postTaskToBackendThread(PassRefPtr<Task> task); |
+ void postTaskToFrontendThread(PassRefPtr<Task> task); |
+ |
+ static void performFrontendThreadTask(void* self); |
+ static void* appcacheThreadStart(void*); |
+ void* appcacheThread(); |
+ |
+ ThreadIdentifier m_threadID; |
+ MessageQueue<RefPtr<Task> > m_queue; |
+ MessageQueue<RefPtr<Task> > m_frontendQueue; |
+ |
+ // FIXME: sooner, instantiate the backend on the background thread |
+ // ApplicationCacheBackend m_appcacheBackend |
+ |
+ // Task base class |
+ class Task : public ThreadSafeShared<Task> { |
+ public: |
+ const GlobalApplicationCacheContextID m_contextID; // many, but not all, tasks are associated with a specific context |
+ |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge) = 0; |
+ protected: |
+ friend ThreadSafeShared<Task>; |
+ Task() {} |
+ Task(const GlobalApplicationCacheContextID& contextID) : m_contextID(contextID) {} |
+ virtual ~Task() {} |
+ }; |
+ |
+ // SyncTask base class |
+ class SyncTask : public Task { |
+ public: |
+ void waitForCompletion(); |
+ void signalCompletion(); |
+ protected: |
+ SyncTask() : Task() {} |
+ SyncTask(const GlobalApplicationCacheContextID& contextID) : Task(contextID) {} |
+ private: |
+ Mutex m_lock; |
+ ThreadCondition m_completionCondition; |
+ }; |
+ |
+ // Sent from the frontend to the backend |
+ class InitaliazeContextTask : public Task { |
+ public: |
+ const ApplicationCacheContextType m_contextType; |
+ const GlobalApplicationCacheContextID& m_parentContextID; |
+ |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge); |
+ |
+ static PassRefPtr<InitaliazeContextTask> create(const GlobalApplicationCacheContextID &contextID, |
+ ApplicationCacheContextType contextType, |
+ const GlobalApplicationCacheContextID& parentContextID) |
+ { |
+ return new InitaliazeContextTask(contextID, contextType, parentContextID); |
+ } |
+ private: |
+ InitaliazeContextTask(const GlobalApplicationCacheContextID& contextID, |
+ ApplicationCacheContextType contextType, |
+ const GlobalApplicationCacheContextID& parentContextID) |
+ : Task(contextID) |
+ , m_contextType(contextType) |
+ , m_parentContextID(parentContextID) |
+ { |
+ } |
+ }; |
+ |
+ // Sent from the frontend to the backend |
+ class UninitializeContextTask : public Task { |
+ public: |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge); |
+ |
+ static PassRefPtr<UninitializeContextTask> create(const GlobalApplicationCacheContextID &contextID) |
+ { |
+ return new UninitializeContextTask(contextID); |
+ } |
+ private: |
+ UninitializeContextTask(const GlobalApplicationCacheContextID& contextID) : Task(contextID) {} |
+ }; |
+ |
+ // Sent from the frontend to the backend |
+ class SelectCacheTask : public Task { |
+ public: |
+ const int m_cacheSequenceNumber; |
+ |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge); |
+ |
+ // FIXME: create/ctor variants that cover all use cases |
+ static PassRefPtr<SelectCacheTask> create(const GlobalApplicationCacheContextID &contextID, int sequenceNumber) |
+ { |
+ return new SelectCacheTask(contextID, sequenceNumber); |
+ } |
+ private: |
+ SelectCacheTask(const GlobalApplicationCacheContextID& contextID, int sequenceNumber) |
+ : Task(contextID) |
+ , m_cacheSequenceNumber(sequenceNumber) |
+ { |
+ } |
+ }; |
+ |
+ // Sent from the frontend to the backend |
+ class GetStatusTask : public SyncTask { |
+ public: |
+ ApplicationCacheStatus m_status; |
+ |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge); |
+ |
+ static PassRefPtr<GetStatusTask> create(const GlobalApplicationCacheContextID &contextID) |
+ { |
+ return new GetStatusTask(contextID); |
+ } |
+ private: |
+ GetStatusTask(const GlobalApplicationCacheContextID& contextID) |
+ : SyncTask(contextID) |
+ , m_status(APPCACHE_UNCACHED) |
+ { |
+ } |
+ |
+ }; |
+ |
+ // Sent from the frontend to the backend |
+ class StartUpdateTask : public SyncTask { |
+ public: |
+ bool m_result; |
+ |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge); |
+ |
+ static PassRefPtr<StartUpdateTask> create(const GlobalApplicationCacheContextID &contextID) |
+ { |
+ return new StartUpdateTask(contextID); |
+ } |
+ private: |
+ StartUpdateTask(const GlobalApplicationCacheContextID& contextID) |
+ : SyncTask(contextID) |
+ , m_result(false) |
+ { |
+ } |
+ }; |
+ |
+ // Sent from the frontend to the backend |
+ class SwapCacheTask : public SyncTask { |
+ public: |
+ bool m_result; |
+ |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge); |
+ |
+ static PassRefPtr<SwapCacheTask> create(const GlobalApplicationCacheContextID &contextID) |
+ { |
+ return new SwapCacheTask(contextID); |
+ } |
+ private: |
+ SwapCacheTask(const GlobalApplicationCacheContextID& contextID) |
+ : SyncTask(contextID) |
+ , m_result(false) |
+ { |
+ } |
+ }; |
+ |
+ // Sent from the backend to the frontend in response to a SelectCacheTask |
+ class NotifySelectCompleteTask : public Task { |
+ public: |
+ const int m_cacheSequenceNumber; |
+ const ApplicationCacheStatus m_status; |
+ |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge); |
+ |
+ static PassRefPtr<NotifySelectCompleteTask> create(const GlobalApplicationCacheContextID &contextID, |
+ int sequenceNumber, |
+ ApplicationCacheStatus status) |
+ { |
+ return new NotifySelectCompleteTask(contextID, sequenceNumber, status); |
+ } |
+ private: |
+ NotifySelectCompleteTask(const GlobalApplicationCacheContextID &contextID, |
+ int sequenceNumber, |
+ ApplicationCacheStatus status) |
+ : Task(contextID) |
+ , m_cacheSequenceNumber(sequenceNumber) |
+ , m_status(status) |
+ { |
+ } |
+ |
+ }; |
+ |
+ // Sent from the backend to the frontend to broadcast status changes |
+ class NotifyStatusChangedTask : public Task { |
+ public: |
+ const Vector<GlobalApplicationCacheContextID> m_contextIDs; |
+ const int m_cacheSequenceNumber; |
+ const ApplicationCacheStatus m_status; |
+ |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge); |
+ |
+ static PassRefPtr<NotifyStatusChangedTask> create(const Vector<GlobalApplicationCacheContextID> &contextIDs, |
+ int sequenceNumber, |
+ ApplicationCacheStatus status) |
+ { |
+ return new NotifyStatusChangedTask(contextIDs, sequenceNumber, status); |
+ } |
+ private: |
+ NotifyStatusChangedTask(const Vector<GlobalApplicationCacheContextID> &contextIDs, |
+ int sequenceNumber, |
+ ApplicationCacheStatus status) |
+ : m_contextIDs(contextIDs) |
+ , m_cacheSequenceNumber(sequenceNumber) |
+ , m_status(status) |
+ { |
+ } |
+ }; |
+ |
+ // Sent from the backend to the frontend to broadcast events |
+ class NotifyEventListenerTask : public Task { |
+ public: |
+ const Vector<GlobalApplicationCacheContextID> m_contextIDs; |
+ const int m_cacheSequenceNumber; |
+ const ApplicationCacheEventType m_eventType; |
+ |
+ virtual void performTask(ApplicationCacheBridgeImpl* bridge); |
+ |
+ static PassRefPtr<NotifyEventListenerTask> create(const Vector<GlobalApplicationCacheContextID> &contextIDs, |
+ int sequenceNumber, |
+ ApplicationCacheEventType eventType) |
+ { |
+ return new NotifyEventListenerTask(contextIDs, sequenceNumber, eventType); |
+ } |
+ private: |
+ NotifyEventListenerTask(const Vector<GlobalApplicationCacheContextID> &contextIDs, |
+ int sequenceNumber, |
+ ApplicationCacheEventType eventType) |
+ : m_contextIDs(contextIDs) |
+ , m_cacheSequenceNumber(sequenceNumber) |
+ , m_eventType(eventType) |
+ { |
+ } |
+ }; |
+ }; |
+ |
+} // namespace WebCore |
+ |
+#endif // ENABLE(APPLICATION_CACHE) |
+#endif // ApplicationCacheBridgeImpl_h |
Property changes on: loader\appcache2\ApplicationCacheBridgeImpl.h |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |