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

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: Explicitly detach instead of using a weak abstraction 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
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 weakly refe rs
51 // to the provider so as to allow the proxy object to outlive the provider durin g
52 // shutdown.
53 //
54 class WorkerLoaderProxyProvider {
46 public: 55 public:
47 virtual ~WorkerLoaderProxy() { } 56 virtual ~WorkerLoaderProxyProvider() { }
48 57
49 // Posts a task to the thread which runs the loading code (normally, the mai n thread). 58 // Posts a task to the thread which runs the loading code (normally, the mai n thread).
50 virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask>) = 0; 59 virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask>) = 0;
51 60
52 // Posts callbacks from loading code to the WorkerGlobalScope. 61 // Posts callbacks from loading code to the WorkerGlobalScope.
53 // Returns true if the task was posted successfully. 62 // Returns true if the task was posted successfully.
54 virtual bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask>) = 0; 63 virtual bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask>) = 0;
55 }; 64 };
56 65
66 class WorkerLoaderProxy : public ThreadSafeRefCounted<WorkerLoaderProxy>, public WorkerLoaderProxyProvider {
67 public:
68 static PassRefPtr<WorkerLoaderProxy> create(WorkerLoaderProxyProvider* loade rProxyProvider)
69 {
70 return adoptRef(new WorkerLoaderProxy(loaderProxyProvider));
71 }
72
73 ~WorkerLoaderProxy() override;
74
75 void postTaskToLoader(PassOwnPtr<ExecutionContextTask>) override;
76 bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask>) override;
77
78 // Notification from the provider that it must
79 // no longer be accessed.
kinuko 2015/02/05 01:41:16 Can we make this comment more explicit (and maybe
sof 2015/02/05 08:05:27 Yes, the comments here were a bit outdated overall
80 void detachProvider(WorkerLoaderProxyProvider*);
81
82 private:
83 explicit WorkerLoaderProxy(WorkerLoaderProxyProvider*);
84
85 Mutex m_lock;
86 WorkerLoaderProxyProvider* m_loaderProxyProvider;
87 };
88
57 } // namespace blink 89 } // namespace blink
58 90
59 #endif // WorkerLoaderProxy_h 91 #endif // WorkerLoaderProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698