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

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

Issue 2811993007: Worker: Remove cross-thread PostTask functions from WorkerLoaderProxy (Closed)
Patch Set: address review comments Created 3 years, 8 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 18 matching lines...) Expand all
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/CoreExport.h" 34 #include "core/CoreExport.h"
35 #include "platform/wtf/Forward.h" 35 #include "platform/wtf/Forward.h"
36 #include "platform/wtf/Functional.h" 36 #include "platform/wtf/Functional.h"
37 #include "platform/wtf/PassRefPtr.h" 37 #include "platform/wtf/PassRefPtr.h"
38 #include "platform/wtf/ThreadSafeRefCounted.h" 38 #include "platform/wtf/ThreadSafeRefCounted.h"
39 #include "platform/wtf/ThreadingPrimitives.h"
40 #include "public/platform/WebTraceLocation.h" 39 #include "public/platform/WebTraceLocation.h"
41 40
42 namespace blink { 41 namespace blink {
43 42
44 class ThreadableLoadingContext; 43 class ThreadableLoadingContext;
45 44
46 // The WorkerLoaderProxy is a proxy to the loader context. Normally, the 45 // The abstract interface to provider ThreadableLoadingContext; separated from
haraken 2017/04/21 09:48:49 provide
47 // document on the main thread provides loading services for the subordinate 46 // the thread-safe & ref-counted WorkerLoaderProxy object which keeps a
48 // workers. WorkerLoaderProxy provides 2-way communications to the Document 47 // protected reference to the provider object. This to support non-overlapping
haraken 2017/04/21 09:48:49 This is to
49 // context and back to the worker. 48 // lifetimes, the provider may be destructed before all references to the
50 // 49 // WorkerLoaderProxy object have been dropped.
51 // Note that in multi-process browsers, the Worker object context and the
52 // Document context can be distinct.
53
54 // The abstract interface providing the methods for actually posting tasks;
55 // separated from the thread-safe & ref-counted WorkerLoaderProxy object which
56 // keeps a protected reference to the provider object. This to support
57 // non-overlapping lifetimes, the provider may be destructed before all
58 // references to the WorkerLoaderProxy object have been dropped.
59 // 50 //
60 // A provider implementation must detach itself when finalizing by calling 51 // A provider implementation must detach itself when finalizing by calling
61 // WorkerLoaderProxy::detachProvider(). This stops the WorkerLoaderProxy from 52 // WorkerLoaderProxy::detachProvider(). This stops the WorkerLoaderProxy from
62 // accessing the now-dead object, but it will remain alive while ref-ptrs are 53 // accessing the now-dead object, but it will remain alive while ref-ptrs are
63 // still kept to it. 54 // still kept to it.
55 //
56 // TODO(nhiroki): Clean up or remove this class (https://crbug.com/694914).
64 class CORE_EXPORT WorkerLoaderProxyProvider { 57 class CORE_EXPORT WorkerLoaderProxyProvider {
65 public: 58 public:
66 virtual ~WorkerLoaderProxyProvider() {} 59 virtual ~WorkerLoaderProxyProvider() {}
67 60
68 // Posts a task to the thread which runs the loading code (normally, the main
69 // thread). This must be called from a worker thread.
70 virtual void PostTaskToLoader(const WebTraceLocation&,
71 std::unique_ptr<WTF::CrossThreadClosure>) = 0;
72
73 // Posts callbacks from loading code to the WorkerGlobalScope. This must be
74 // called from the main thread.
75 virtual void PostTaskToWorkerGlobalScope(
76 const WebTraceLocation&,
77 std::unique_ptr<WTF::CrossThreadClosure>) = 0;
78
79 // It is guaranteed that this gets accessed only on the thread where 61 // It is guaranteed that this gets accessed only on the thread where
80 // the loading context is bound. 62 // the loading context is bound.
81 virtual ThreadableLoadingContext* GetThreadableLoadingContext() = 0; 63 virtual ThreadableLoadingContext* GetThreadableLoadingContext() {
64 return nullptr;
65 }
82 }; 66 };
83 67
84 class CORE_EXPORT WorkerLoaderProxy final 68 class CORE_EXPORT WorkerLoaderProxy final
85 : public ThreadSafeRefCounted<WorkerLoaderProxy> { 69 : public ThreadSafeRefCounted<WorkerLoaderProxy> {
86 public: 70 public:
87 static PassRefPtr<WorkerLoaderProxy> Create( 71 static PassRefPtr<WorkerLoaderProxy> Create(
88 WorkerLoaderProxyProvider* loader_proxy_provider) { 72 WorkerLoaderProxyProvider* loader_proxy_provider) {
89 return AdoptRef(new WorkerLoaderProxy(loader_proxy_provider)); 73 return AdoptRef(new WorkerLoaderProxy(loader_proxy_provider));
90 } 74 }
91 75
92 ~WorkerLoaderProxy(); 76 ~WorkerLoaderProxy();
93 77
94 // This must be called from a worker thread.
95 void PostTaskToLoader(const WebTraceLocation&,
96 std::unique_ptr<WTF::CrossThreadClosure>);
97
98 // This must be called from the main thread.
99 void PostTaskToWorkerGlobalScope(const WebTraceLocation&,
100 std::unique_ptr<WTF::CrossThreadClosure>);
101
102 // This may return nullptr. 78 // This may return nullptr.
103 // This must be called from the main thread (== the thread of the 79 // This must be called from the main thread (== the thread of the
104 // loading context). 80 // loading context).
105 ThreadableLoadingContext* GetThreadableLoadingContext(); 81 ThreadableLoadingContext* GetThreadableLoadingContext();
106 82
107 // Notification from the provider that it can no longer be accessed. An 83 // Notification from the provider that it can no longer be accessed. An
108 // implementation of WorkerLoaderProxyProvider is required to call 84 // implementation of WorkerLoaderProxyProvider is required to call
109 // detachProvider() when finalizing. This must be called from the main thread. 85 // detachProvider() when finalizing. This must be called from the main thread.
110 void DetachProvider(WorkerLoaderProxyProvider*); 86 void DetachProvider(WorkerLoaderProxyProvider*);
111 87
112 private: 88 private:
113 explicit WorkerLoaderProxy(WorkerLoaderProxyProvider*); 89 explicit WorkerLoaderProxy(WorkerLoaderProxyProvider*);
114 90
115 WTF::Mutex lock_;
116 WorkerLoaderProxyProvider* loader_proxy_provider_; 91 WorkerLoaderProxyProvider* loader_proxy_provider_;
117 }; 92 };
118 93
119 } // namespace blink 94 } // namespace blink
120 95
121 #endif // WorkerLoaderProxy_h 96 #endif // WorkerLoaderProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698