| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WorkerLoaderProxy_h | 31 #ifndef WorkerLoaderProxy_h |
| 32 #define WorkerLoaderProxy_h | 32 #define WorkerLoaderProxy_h |
| 33 | 33 |
| 34 #include "core/dom/ExecutionContext.h" | 34 #include "core/dom/ExecutionContext.h" |
| 35 #include "wtf/Forward.h" | 35 #include "wtf/Forward.h" |
| 36 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
| 37 #include "wtf/ThreadSafeRefCounted.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 // A proxy to talk to the loader context. Normally, the document on the main thr
ead | 41 // The WorkerLoaderProxy is a proxy to the loader context. Normally, the |
| 41 // provides loading services for the subordinate workers. This interface provide
s 2-way | 42 // document on the main thread provides loading services for the subordinate |
| 42 // communications to the Document context and back to the worker. | 43 // workers. WorkerLoaderProxy provides 2-way communications to the Document |
| 44 // context and back to the worker. |
| 45 // |
| 43 // Note that in multi-process browsers, the Worker object context and the Docume
nt | 46 // Note that in multi-process browsers, the Worker object context and the Docume
nt |
| 44 // context can be distinct. | 47 // context can be distinct. |
| 45 class WorkerLoaderProxy { | 48 |
| 49 // The abstract interface providing the methods for actually posting tasks; sepa
rated |
| 50 // from the thread-safe & ref-counted WorkerLoaderProxy object which keeps a pro
tected |
| 51 // reference to the provider object. This to support non-overlapping lifetimes,
the |
| 52 // provider may be destructed before all references to the WorkerLoaderProxy obj
ect |
| 53 // have been dropped. |
| 54 // |
| 55 // A provider implementation must detach itself when finalizing by calling |
| 56 // WorkerLoaderProxy::detachProvider(). This stops the WorkerLoaderProxy from ac
cessing |
| 57 // the now-dead object, but it will remain alive while ref-ptrs are still kept t
o it. |
| 58 class WorkerLoaderProxyProvider { |
| 46 public: | 59 public: |
| 47 virtual ~WorkerLoaderProxy() { } | 60 virtual ~WorkerLoaderProxyProvider() { } |
| 48 | 61 |
| 49 // Posts a task to the thread which runs the loading code (normally, the mai
n thread). | 62 // Posts a task to the thread which runs the loading code (normally, the mai
n thread). |
| 50 virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask>) = 0; | 63 virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask>) = 0; |
| 51 | 64 |
| 52 // Posts callbacks from loading code to the WorkerGlobalScope. | 65 // Posts callbacks from loading code to the WorkerGlobalScope. |
| 53 // Returns true if the task was posted successfully. | 66 // Returns true if the task was posted successfully. |
| 54 virtual bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask>) =
0; | 67 virtual bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask>) =
0; |
| 55 }; | 68 }; |
| 56 | 69 |
| 70 class WorkerLoaderProxy : public ThreadSafeRefCounted<WorkerLoaderProxy>, public
WorkerLoaderProxyProvider { |
| 71 public: |
| 72 static PassRefPtr<WorkerLoaderProxy> create(WorkerLoaderProxyProvider* loade
rProxyProvider) |
| 73 { |
| 74 return adoptRef(new WorkerLoaderProxy(loaderProxyProvider)); |
| 75 } |
| 76 |
| 77 ~WorkerLoaderProxy() override; |
| 78 |
| 79 void postTaskToLoader(PassOwnPtr<ExecutionContextTask>) override; |
| 80 bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask>) override; |
| 81 |
| 82 // Notification from the provider that it can no longer be |
| 83 // accessed. An implementation of WorkerLoaderProxyProvider is |
| 84 // required to call detachProvider() when finalizing. |
| 85 void detachProvider(WorkerLoaderProxyProvider*); |
| 86 |
| 87 private: |
| 88 explicit WorkerLoaderProxy(WorkerLoaderProxyProvider*); |
| 89 |
| 90 Mutex m_lock; |
| 91 WorkerLoaderProxyProvider* m_loaderProxyProvider; |
| 92 }; |
| 93 |
| 57 } // namespace blink | 94 } // namespace blink |
| 58 | 95 |
| 59 #endif // WorkerLoaderProxy_h | 96 #endif // WorkerLoaderProxy_h |
| OLD | NEW |