| OLD | NEW | 
 | (Empty) | 
|    1 /* |  | 
|    2  * Copyright (C) 2013 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 #ifndef WorkerStorageQuotaCallbacksBridge_h |  | 
|   32 #define WorkerStorageQuotaCallbacksBridge_h |  | 
|   33  |  | 
|   34 #include <WebStorageQuotaError.h> |  | 
|   35 #include <WebStorageQuotaType.h> |  | 
|   36 #include "core/dom/ScriptExecutionContext.h" |  | 
|   37 #include "core/storage/StorageArea.h" |  | 
|   38 #include "public/platform/WebVector.h" |  | 
|   39 #include "wtf/PassOwnPtr.h" |  | 
|   40 #include "wtf/PassRefPtr.h" |  | 
|   41 #include "wtf/text/WTFString.h" |  | 
|   42 #include "wtf/Threading.h" |  | 
|   43  |  | 
|   44 namespace WebCore { |  | 
|   45 class WorkerLoaderProxy; |  | 
|   46 } |  | 
|   47  |  | 
|   48 namespace WebKit { |  | 
|   49  |  | 
|   50 class MainThreadStorageQuotaCallbacks; |  | 
|   51 class WebCommonWorkerClient; |  | 
|   52 class WebStorageQuotaCallbacksImpl; |  | 
|   53 class WorkerStorageQuotaContextObserver; |  | 
|   54  |  | 
|   55 // Used to post a queryUsageAndQuota request to the main thread and get called b
     ack for the request. |  | 
|   56 // |  | 
|   57 // Lifetime for this class is maintained by posted "tasks" which ref count it an
     d by MainThreadStorageQuotaCallbacks. |  | 
|   58 // Either a task finishing or the MainThreadStorageQuotaCallbacks being deleted 
     may release the last ref on WorkerStorageQuotaCallbacksBridge. |  | 
|   59 // |  | 
|   60 // A typical flow for queryUsageAndQuota would look like this: |  | 
|   61 // Bridge::postQueryUsageAndQuotaToMainThread() on WorkerThread |  | 
|   62 //  --> Bridge::queryUsageAndQuotaOnMainThread() is called on MainThread |  | 
|   63 //      This makes an IPC with a MainThreadStorageQuotaCallbacks instance |  | 
|   64 //     [actual operation is down in the browser] |  | 
|   65 //  --> MainThreadStorageQuotaCallbacks::didXxx is called on MainThread |  | 
|   66 //  --> Bridge::didXxxOnMainThread is called on MainThread |  | 
|   67 //  --> Bridge::didXxxOnWorkerThread is called on WorkerThread |  | 
|   68 //      This calls the original callbacks (m_callbacksOnWorkerThread). |  | 
|   69 class WorkerStorageQuotaCallbacksBridge : public ThreadSafeRefCounted<WorkerStor
     ageQuotaCallbacksBridge> { |  | 
|   70 public: |  | 
|   71     ~WorkerStorageQuotaCallbacksBridge(); |  | 
|   72  |  | 
|   73     void stop(); |  | 
|   74  |  | 
|   75     static PassRefPtr<WorkerStorageQuotaCallbacksBridge> create(WebCore::WorkerL
     oaderProxy* workerLoaderProxy, WebCore::ScriptExecutionContext* workerGlobalScop
     e, WebStorageQuotaCallbacksImpl* callbacks) |  | 
|   76     { |  | 
|   77         return adoptRef(new WorkerStorageQuotaCallbacksBridge(workerLoaderProxy,
      workerGlobalScope, callbacks)); |  | 
|   78     } |  | 
|   79  |  | 
|   80     // Entry method to post QueryUsageAndQuota task to main thread. |  | 
|   81     void postQueryUsageAndQuotaToMainThread(WebCommonWorkerClient*, WebStorageQu
     otaType, const String& mode); |  | 
|   82  |  | 
|   83     // Callback methods that are called on the main thread. |  | 
|   84     void didFailOnMainThread(WebStorageQuotaError, const String& mode); |  | 
|   85     void didQueryStorageUsageAndQuotaOnMainThread(unsigned long long usageInByte
     s, unsigned long long quotaInBytes, const String& mode); |  | 
|   86  |  | 
|   87 private: |  | 
|   88     WorkerStorageQuotaCallbacksBridge(WebCore::WorkerLoaderProxy*, WebCore::Scri
     ptExecutionContext*, WebStorageQuotaCallbacksImpl*); |  | 
|   89  |  | 
|   90     // Method that is called on the main thread. |  | 
|   91     static void runTaskOnMainThread(WebCore::ScriptExecutionContext*, PassRefPtr
     <WorkerStorageQuotaCallbacksBridge>, PassOwnPtr<WebCore::ScriptExecutionContext:
     :Task>); |  | 
|   92     static void runTaskOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefP
     tr<WorkerStorageQuotaCallbacksBridge>, PassOwnPtr<WebCore::ScriptExecutionContex
     t::Task>); |  | 
|   93     static void queryUsageAndQuotaOnMainThread(WebCore::ScriptExecutionContext*,
      WebCommonWorkerClient*, WebStorageQuotaType, PassRefPtr<WorkerStorageQuotaCallb
     acksBridge>, const String& mode); |  | 
|   94  |  | 
|   95     friend class MainThreadStorageQuotaCallbacks; |  | 
|   96  |  | 
|   97     // Methods that dispatch WebStorageQuotaCallbacks on the worker threads. |  | 
|   98     static void didFailOnWorkerThread(WebCore::ScriptExecutionContext*, PassRefP
     tr<WorkerStorageQuotaCallbacksBridge>, WebStorageQuotaError); |  | 
|   99     static void didQueryStorageUsageAndQuotaOnWorkerThread(WebCore::ScriptExecut
     ionContext*, PassRefPtr<WorkerStorageQuotaCallbacksBridge>, unsigned long long u
     sageInBytes, unsigned long long quotaInBytes); |  | 
|  100  |  | 
|  101     void dispatchTaskToMainThread(PassOwnPtr<WebCore::ScriptExecutionContext::Ta
     sk>); |  | 
|  102     void mayPostTaskToWorker(PassOwnPtr<WebCore::ScriptExecutionContext::Task>, 
     const String& mode); |  | 
|  103  |  | 
|  104     void cleanUpAfterCallback(); |  | 
|  105  |  | 
|  106     Mutex m_loaderProxyMutex; |  | 
|  107     WebCore::WorkerLoaderProxy* m_workerLoaderProxy; |  | 
|  108  |  | 
|  109     WebCore::ScriptExecutionContext* m_workerGlobalScope; |  | 
|  110  |  | 
|  111     // Must be deleted on the WorkerGlobalScope thread. |  | 
|  112     WorkerStorageQuotaContextObserver* m_workerGlobalScopeObserver; |  | 
|  113  |  | 
|  114     // This is self-destructed and must be fired on the worker thread. |  | 
|  115     WebStorageQuotaCallbacksImpl* m_callbacksOnWorkerThread; |  | 
|  116 }; |  | 
|  117  |  | 
|  118 } // namespace WebCore |  | 
|  119  |  | 
|  120 #endif // WorkerStorageQuotaCallbacksBridge_h |  | 
| OLD | NEW |