Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: Source/core/workers/WorkerLoaderProxy.h

Issue 887463003: Turn WorkerLoaderProxy into a threadsafe, ref-counted object. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Clarify WorkerLoaderProxyProvider's obligations on shutdown Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/workers/SharedWorkerThread.cpp ('k') | Source/core/workers/WorkerLoaderProxy.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « Source/core/workers/SharedWorkerThread.cpp ('k') | Source/core/workers/WorkerLoaderProxy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698