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

Side by Side Diff: third_party/WebKit/Source/platform/Supplementable.h

Issue 2150443002: Supplement should have a Member to the corresponding Supplementable object (Part 1) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: temp Created 4 years, 5 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) 2012 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef Supplementable_h 26 #ifndef Supplementable_h
27 #define Supplementable_h 27 #define Supplementable_h
28 28
29 #include "platform/PlatformExport.h"
29 #include "platform/heap/Handle.h" 30 #include "platform/heap/Handle.h"
30 #include "wtf/Assertions.h" 31 #include "wtf/Assertions.h"
31 #include "wtf/HashMap.h" 32 #include "wtf/HashMap.h"
32 #include "wtf/Noncopyable.h" 33 #include "wtf/Noncopyable.h"
33 34
34 #if ENABLE(ASSERT) 35 #if ENABLE(ASSERT)
35 #include "wtf/Threading.h" 36 #include "wtf/Threading.h"
36 #endif 37 #endif
37 38
38 namespace blink { 39 namespace blink {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // worker thread). Please be extremely careful to use the method though, 85 // worker thread). Please be extremely careful to use the method though,
85 // as randomly calling the method could easily cause racy condition. 86 // as randomly calling the method could easily cause racy condition.
86 // 87 //
87 // Note that reattachThread() does nothing if assertion is not enabled. 88 // Note that reattachThread() does nothing if assertion is not enabled.
88 // 89 //
89 90
90 template<typename T> 91 template<typename T>
91 class Supplementable; 92 class Supplementable;
92 93
93 template<typename T> 94 template<typename T>
94 class Supplement : public GarbageCollectedMixin { 95 class PLATFORM_EXPORT Supplement : public GarbageCollectedMixin {
95 public: 96 public:
97 // TODO(haraken): Remove the default constructor.
98 // All Supplement objects should be instantiated with m_host.
99 Supplement() { }
100 explicit Supplement(T& host) : m_host(&host) { }
101 T* host() const { return m_host; }
102
96 static void provideTo(Supplementable<T>& host, const char* key, Supplement<T >* supplement) 103 static void provideTo(Supplementable<T>& host, const char* key, Supplement<T >* supplement)
97 { 104 {
98 host.provideSupplement(key, supplement); 105 host.provideSupplement(key, supplement);
99 } 106 }
100 107
101 static Supplement<T>* from(Supplementable<T>& host, const char* key) 108 static Supplement<T>* from(Supplementable<T>& host, const char* key)
102 { 109 {
103 return host.requireSupplement(key); 110 return host.requireSupplement(key);
104 } 111 }
105 112
106 static Supplement<T>* from(Supplementable<T>* host, const char* key) 113 static Supplement<T>* from(Supplementable<T>* host, const char* key)
107 { 114 {
108 return host ? host->requireSupplement(key) : 0; 115 return host ? host->requireSupplement(key) : 0;
109 } 116 }
110 117
111 DEFINE_INLINE_VIRTUAL_TRACE() { } 118 DEFINE_INLINE_VIRTUAL_TRACE()
119 {
120 visitor->trace(m_host);
121 }
122
123 private:
124 Member<T> m_host;
112 }; 125 };
113 126
114 // Supplementable<T> inherits from GarbageCollectedMixin virtually 127 // Supplementable<T> inherits from GarbageCollectedMixin virtually
115 // to allow ExecutionContext to derive from two GC mixin classes. 128 // to allow ExecutionContext to derive from two GC mixin classes.
116 template<typename T> 129 template<typename T>
117 class Supplementable : public virtual GarbageCollectedMixin { 130 class Supplementable : public virtual GarbageCollectedMixin {
118 WTF_MAKE_NONCOPYABLE(Supplementable); 131 WTF_MAKE_NONCOPYABLE(Supplementable);
119 public: 132 public:
120 void provideSupplement(const char* key, Supplement<T>* supplement) 133 void provideSupplement(const char* key, Supplement<T>* supplement)
121 { 134 {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 }; 184 };
172 185
173 template<typename T> 186 template<typename T>
174 struct ThreadingTrait<Supplementable<T>> { 187 struct ThreadingTrait<Supplementable<T>> {
175 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity; 188 static const ThreadAffinity Affinity = ThreadingTrait<T>::Affinity;
176 }; 189 };
177 190
178 } // namespace blink 191 } // namespace blink
179 192
180 #endif // Supplementable_h 193 #endif // Supplementable_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698