| 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 26 matching lines...) Expand all Loading... |
| 37 #include "wtf/Forward.h" | 37 #include "wtf/Forward.h" |
| 38 #include "wtf/ThreadSafeRefCounted.h" | 38 #include "wtf/ThreadSafeRefCounted.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 // The WorkerLoaderProxy is a proxy to the loader context. Normally, the | 42 // The WorkerLoaderProxy is a proxy to the loader context. Normally, the |
| 43 // document on the main thread provides loading services for the subordinate | 43 // document on the main thread provides loading services for the subordinate |
| 44 // workers. WorkerLoaderProxy provides 2-way communications to the Document | 44 // workers. WorkerLoaderProxy provides 2-way communications to the Document |
| 45 // context and back to the worker. | 45 // context and back to the worker. |
| 46 // | 46 // |
| 47 // Note that in multi-process browsers, the Worker object context and the Docume
nt | 47 // Note that in multi-process browsers, the Worker object context and the |
| 48 // context can be distinct. | 48 // Document context can be distinct. |
| 49 | 49 |
| 50 // The abstract interface providing the methods for actually posting tasks; sepa
rated | 50 // The abstract interface providing the methods for actually posting tasks; |
| 51 // from the thread-safe & ref-counted WorkerLoaderProxy object which keeps a pro
tected | 51 // separated from the thread-safe & ref-counted WorkerLoaderProxy object which |
| 52 // reference to the provider object. This to support non-overlapping lifetimes,
the | 52 // keeps a protected reference to the provider object. This to support |
| 53 // provider may be destructed before all references to the WorkerLoaderProxy obj
ect | 53 // non-overlapping lifetimes, the provider may be destructed before all |
| 54 // have been dropped. | 54 // references to the WorkerLoaderProxy object have been dropped. |
| 55 // | 55 // |
| 56 // A provider implementation must detach itself when finalizing by calling | 56 // A provider implementation must detach itself when finalizing by calling |
| 57 // WorkerLoaderProxy::detachProvider(). This stops the WorkerLoaderProxy from ac
cessing | 57 // WorkerLoaderProxy::detachProvider(). This stops the WorkerLoaderProxy from |
| 58 // the now-dead object, but it will remain alive while ref-ptrs are still kept t
o it. | 58 // accessing the now-dead object, but it will remain alive while ref-ptrs are |
| 59 // still kept to it. |
| 59 class CORE_EXPORT WorkerLoaderProxyProvider { | 60 class CORE_EXPORT WorkerLoaderProxyProvider { |
| 60 public: | 61 public: |
| 61 virtual ~WorkerLoaderProxyProvider() {} | 62 virtual ~WorkerLoaderProxyProvider() {} |
| 62 | 63 |
| 63 // Posts a task to the thread which runs the loading code (normally, the main
thread). | 64 // Posts a task to the thread which runs the loading code (normally, the main |
| 65 // thread). |
| 64 virtual void postTaskToLoader(const WebTraceLocation&, | 66 virtual void postTaskToLoader(const WebTraceLocation&, |
| 65 std::unique_ptr<ExecutionContextTask>) = 0; | 67 std::unique_ptr<ExecutionContextTask>) = 0; |
| 66 | 68 |
| 67 // Posts callbacks from loading code to the WorkerGlobalScope. | 69 // Posts callbacks from loading code to the WorkerGlobalScope. |
| 68 virtual void postTaskToWorkerGlobalScope( | 70 virtual void postTaskToWorkerGlobalScope( |
| 69 const WebTraceLocation&, | 71 const WebTraceLocation&, |
| 70 std::unique_ptr<ExecutionContextTask>) = 0; | 72 std::unique_ptr<ExecutionContextTask>) = 0; |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 class CORE_EXPORT WorkerLoaderProxy final | 75 class CORE_EXPORT WorkerLoaderProxy final |
| 74 : public ThreadSafeRefCounted<WorkerLoaderProxy> { | 76 : public ThreadSafeRefCounted<WorkerLoaderProxy> { |
| 75 public: | 77 public: |
| 76 static PassRefPtr<WorkerLoaderProxy> create( | 78 static PassRefPtr<WorkerLoaderProxy> create( |
| 77 WorkerLoaderProxyProvider* loaderProxyProvider) { | 79 WorkerLoaderProxyProvider* loaderProxyProvider) { |
| 78 return adoptRef(new WorkerLoaderProxy(loaderProxyProvider)); | 80 return adoptRef(new WorkerLoaderProxy(loaderProxyProvider)); |
| 79 } | 81 } |
| 80 | 82 |
| 81 ~WorkerLoaderProxy(); | 83 ~WorkerLoaderProxy(); |
| 82 | 84 |
| 83 void postTaskToLoader(const WebTraceLocation&, | 85 void postTaskToLoader(const WebTraceLocation&, |
| 84 std::unique_ptr<ExecutionContextTask>); | 86 std::unique_ptr<ExecutionContextTask>); |
| 85 void postTaskToWorkerGlobalScope(const WebTraceLocation&, | 87 void postTaskToWorkerGlobalScope(const WebTraceLocation&, |
| 86 std::unique_ptr<ExecutionContextTask>); | 88 std::unique_ptr<ExecutionContextTask>); |
| 87 | 89 |
| 88 // Notification from the provider that it can no longer be | 90 // Notification from the provider that it can no longer be accessed. An |
| 89 // accessed. An implementation of WorkerLoaderProxyProvider is | 91 // implementation of WorkerLoaderProxyProvider is required to call |
| 90 // required to call detachProvider() when finalizing. | 92 // detachProvider() when finalizing. |
| 91 void detachProvider(WorkerLoaderProxyProvider*); | 93 void detachProvider(WorkerLoaderProxyProvider*); |
| 92 | 94 |
| 93 private: | 95 private: |
| 94 explicit WorkerLoaderProxy(WorkerLoaderProxyProvider*); | 96 explicit WorkerLoaderProxy(WorkerLoaderProxyProvider*); |
| 95 | 97 |
| 96 Mutex m_lock; | 98 Mutex m_lock; |
| 97 WorkerLoaderProxyProvider* m_loaderProxyProvider; | 99 WorkerLoaderProxyProvider* m_loaderProxyProvider; |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 } // namespace blink | 102 } // namespace blink |
| 101 | 103 |
| 102 #endif // WorkerLoaderProxy_h | 104 #endif // WorkerLoaderProxy_h |
| OLD | NEW |