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

Side by Side Diff: sky/engine/web/WebKit.cpp

Issue 673783006: Remove the last WebThread task observer (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 2 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 | « sky/engine/web/DEPS ('k') | no next file » | 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 #include "config.h" 31 #include "config.h"
32 #include "public/web/WebKit.h" 32 #include "public/web/WebKit.h"
33 33
34 #include "base/message_loop/message_loop.h"
34 #include "bindings/core/v8/V8Binding.h" 35 #include "bindings/core/v8/V8Binding.h"
35 #include "bindings/core/v8/V8GCController.h" 36 #include "bindings/core/v8/V8GCController.h"
36 #include "bindings/core/v8/V8Initializer.h" 37 #include "bindings/core/v8/V8Initializer.h"
37 #include "core/Init.h" 38 #include "core/Init.h"
38 #include "core/animation/AnimationClock.h" 39 #include "core/animation/AnimationClock.h"
39 #include "core/dom/Microtask.h" 40 #include "core/dom/Microtask.h"
40 #include "core/frame/Settings.h" 41 #include "core/frame/Settings.h"
41 #include "core/page/Page.h" 42 #include "core/page/Page.h"
42 #include "gin/public/v8_platform.h" 43 #include "gin/public/v8_platform.h"
44 #include "mojo/common/message_pump_mojo.h"
43 #include "platform/LayoutTestSupport.h" 45 #include "platform/LayoutTestSupport.h"
44 #include "platform/Logging.h" 46 #include "platform/Logging.h"
45 #include "platform/RuntimeEnabledFeatures.h" 47 #include "platform/RuntimeEnabledFeatures.h"
46 #include "platform/graphics/ImageDecodingStore.h" 48 #include "platform/graphics/ImageDecodingStore.h"
47 #include "platform/graphics/media/MediaPlayer.h" 49 #include "platform/graphics/media/MediaPlayer.h"
48 #include "platform/heap/Heap.h" 50 #include "platform/heap/Heap.h"
49 #include "platform/heap/glue/MessageLoopInterruptor.h" 51 #include "platform/heap/glue/MessageLoopInterruptor.h"
50 #include "platform/heap/glue/PendingGCRunner.h"
51 #include "public/platform/Platform.h" 52 #include "public/platform/Platform.h"
52 #include "public/platform/WebThread.h"
53 #include "web/WebMediaPlayerClientImpl.h" 53 #include "web/WebMediaPlayerClientImpl.h"
54 #include "wtf/Assertions.h" 54 #include "wtf/Assertions.h"
55 #include "wtf/CryptographicallyRandomNumber.h" 55 #include "wtf/CryptographicallyRandomNumber.h"
56 #include "wtf/MainThread.h" 56 #include "wtf/MainThread.h"
57 #include "wtf/WTF.h" 57 #include "wtf/WTF.h"
58 #include "wtf/text/AtomicString.h" 58 #include "wtf/text/AtomicString.h"
59 #include "wtf/text/TextEncoding.h" 59 #include "wtf/text/TextEncoding.h"
60 #include <v8.h> 60 #include <v8.h>
61 61
62 namespace blink { 62 namespace blink {
63 63
64 namespace { 64 namespace {
65 65
66 class EndOfTaskRunner : public WebThread::TaskObserver { 66 void willProcessTask()
67 {
68 AnimationClock::notifyTaskStart();
69 }
70
71 void didProcessTask()
72 {
73 Microtask::performCheckpoint();
74 V8GCController::reportDOMMemoryUsageToV8(mainThreadIsolate());
75 }
76
77 class TaskObserver : public base::MessageLoop::TaskObserver {
67 public: 78 public:
68 virtual void willProcessTask() OVERRIDE 79 void WillProcessTask(const base::PendingTask& pending_task) override { willP rocessTask(); }
69 { 80 void DidProcessTask(const base::PendingTask& pending_task) override { didPro cessTask(); }
70 AnimationClock::notifyTaskStart();
71 }
72 virtual void didProcessTask() OVERRIDE
73 {
74 Microtask::performCheckpoint();
75 V8GCController::reportDOMMemoryUsageToV8(mainThreadIsolate());
76 }
77 }; 81 };
78 82
83 class SignalObserver : public mojo::common::MessagePumpMojo::Observer {
84 public:
85 void WillSignalHandler() override { willProcessTask(); }
86 void DidSignalHandler() override { didProcessTask(); }
87 };
88
89 static TaskObserver* s_taskObserver = 0;
90 static SignalObserver* s_signalObserver = 0;
91
92 void addMessageLoopObservers()
93 {
94 ASSERT(!s_taskObserver);
95 s_taskObserver = new TaskObserver;
96
97 ASSERT(!s_signalObserver);
98 s_signalObserver = new SignalObserver;
99
100 base::MessageLoop::current()->AddTaskObserver(s_taskObserver);
101 mojo::common::MessagePumpMojo::current()->AddObserver(s_signalObserver);
102 }
103
104 void removeMessageLoopObservers()
105 {
106 base::MessageLoop::current()->RemoveTaskObserver(s_taskObserver);
107 mojo::common::MessagePumpMojo::current()->RemoveObserver(s_signalObserver);
108
109 ASSERT(s_taskObserver);
110 delete s_taskObserver;
111 s_taskObserver = 0;
112
113 ASSERT(s_signalObserver);
114 delete s_signalObserver;
115 s_signalObserver = 0;
116 }
117
79 } // namespace 118 } // namespace
80 119
81 static WebThread::TaskObserver* s_endOfTaskRunner = 0;
82 static WebThread::TaskObserver* s_pendingGCRunner = 0;
83 static ThreadState::Interruptor* s_messageLoopInterruptor = 0;
84 static ThreadState::Interruptor* s_isolateInterruptor = 0; 120 static ThreadState::Interruptor* s_isolateInterruptor = 0;
85 121
86 // Make sure we are not re-initialized in the same address space. 122 // Make sure we are not re-initialized in the same address space.
87 // Doing so may cause hard to reproduce crashes. 123 // Doing so may cause hard to reproduce crashes.
88 static bool s_webKitInitialized = false; 124 static bool s_webKitInitialized = false;
89 125
90 void initialize(Platform* platform) 126 void initialize(Platform* platform)
91 { 127 {
92 initializeWithoutV8(platform); 128 initializeWithoutV8(platform);
93 129
94 V8Initializer::initializeMainThreadIfNeeded(); 130 V8Initializer::initializeMainThreadIfNeeded();
95 131
96 s_isolateInterruptor = new V8IsolateInterruptor(V8PerIsolateData::mainThread Isolate()); 132 s_isolateInterruptor = new V8IsolateInterruptor(V8PerIsolateData::mainThread Isolate());
97 ThreadState::current()->addInterruptor(s_isolateInterruptor); 133 ThreadState::current()->addInterruptor(s_isolateInterruptor);
98 134
99 // currentThread will always be non-null in production, but can be null in C hromium unit tests. 135 addMessageLoopObservers();
100 if (WebThread* currentThread = platform->currentThread()) {
101 ASSERT(!s_endOfTaskRunner);
102 s_endOfTaskRunner = new EndOfTaskRunner;
103 currentThread->addTaskObserver(s_endOfTaskRunner);
104 }
105 } 136 }
106 137
107 v8::Isolate* mainThreadIsolate() 138 v8::Isolate* mainThreadIsolate()
108 { 139 {
109 return V8PerIsolateData::mainThreadIsolate(); 140 return V8PerIsolateData::mainThreadIsolate();
110 } 141 }
111 142
112 static double currentTimeFunction() 143 static double currentTimeFunction()
113 { 144 {
114 return Platform::current()->currentTime(); 145 return Platform::current()->currentTime();
(...skipping 21 matching lines...) Expand all
136 167
137 ASSERT(platform); 168 ASSERT(platform);
138 Platform::initialize(platform); 169 Platform::initialize(platform);
139 170
140 WTF::setRandomSource(cryptographicallyRandomValues); 171 WTF::setRandomSource(cryptographicallyRandomValues);
141 WTF::initialize(currentTimeFunction, monotonicallyIncreasingTimeFunction); 172 WTF::initialize(currentTimeFunction, monotonicallyIncreasingTimeFunction);
142 WTF::initializeMainThread(callOnMainThreadFunction); 173 WTF::initializeMainThread(callOnMainThreadFunction);
143 Heap::init(); 174 Heap::init();
144 175
145 ThreadState::attachMainThread(); 176 ThreadState::attachMainThread();
146 // currentThread will always be non-null in production, but can be null in C hromium unit tests.
147 if (WebThread* currentThread = platform->currentThread()) {
148 ASSERT(!s_pendingGCRunner);
149 s_pendingGCRunner = new PendingGCRunner;
150 currentThread->addTaskObserver(s_pendingGCRunner);
151
152 ASSERT(!s_messageLoopInterruptor);
153 s_messageLoopInterruptor = new MessageLoopInterruptor(currentThread);
154 ThreadState::current()->addInterruptor(s_messageLoopInterruptor);
155 }
156 177
157 DEFINE_STATIC_LOCAL(CoreInitializer, initializer, ()); 178 DEFINE_STATIC_LOCAL(CoreInitializer, initializer, ());
158 initializer.init(); 179 initializer.init();
159 180
160 // There are some code paths (for example, running WebKit in the browser 181 // There are some code paths (for example, running WebKit in the browser
161 // process and calling into LocalStorage before anything else) where the 182 // process and calling into LocalStorage before anything else) where the
162 // UTF8 string encoding tables are used on a background thread before 183 // UTF8 string encoding tables are used on a background thread before
163 // they're set up. This is a problem because their set up routines assert 184 // they're set up. This is a problem because their set up routines assert
164 // they're running on the main WebKitThread. It might be possible to make 185 // they're running on the main WebKitThread. It might be possible to make
165 // the initialization thread-safe, but given that so many code paths use 186 // the initialization thread-safe, but given that so many code paths use
166 // this, initializing this lazily probably doesn't buy us much. 187 // this, initializing this lazily probably doesn't buy us much.
167 WTF::UTF8Encoding(); 188 WTF::UTF8Encoding();
168 189
169 MediaPlayer::setMediaEngineCreateFunction(WebMediaPlayerClientImpl::create); 190 MediaPlayer::setMediaEngineCreateFunction(WebMediaPlayerClientImpl::create);
170 } 191 }
171 192
172 void shutdown() 193 void shutdown()
173 { 194 {
174 // currentThread will always be non-null in production, but can be null in C hromium unit tests. 195 removeMessageLoopObservers();
175 if (Platform::current()->currentThread()) {
176 ASSERT(s_endOfTaskRunner);
177 Platform::current()->currentThread()->removeTaskObserver(s_endOfTaskRunn er);
178 delete s_endOfTaskRunner;
179 s_endOfTaskRunner = 0;
180 }
181 196
182 ASSERT(s_isolateInterruptor); 197 ASSERT(s_isolateInterruptor);
183 ThreadState::current()->removeInterruptor(s_isolateInterruptor); 198 ThreadState::current()->removeInterruptor(s_isolateInterruptor);
184 199
185 // currentThread will always be non-null in production, but can be null in C hromium unit tests.
186 if (Platform::current()->currentThread()) {
187 ASSERT(s_pendingGCRunner);
188 delete s_pendingGCRunner;
189 s_pendingGCRunner = 0;
190
191 ASSERT(s_messageLoopInterruptor);
192 ThreadState::current()->removeInterruptor(s_messageLoopInterruptor);
193 delete s_messageLoopInterruptor;
194 s_messageLoopInterruptor = 0;
195 }
196
197 // Detach the main thread before starting the shutdown sequence 200 // Detach the main thread before starting the shutdown sequence
198 // so that the main thread won't get involved in a GC during the shutdown. 201 // so that the main thread won't get involved in a GC during the shutdown.
199 ThreadState::detachMainThread(); 202 ThreadState::detachMainThread();
200 203
201 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); 204 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
202 V8PerIsolateData::dispose(isolate); 205 V8PerIsolateData::dispose(isolate);
203 206
204 shutdownWithoutV8(); 207 shutdownWithoutV8();
205 } 208 }
206 209
207 void shutdownWithoutV8() 210 void shutdownWithoutV8()
208 { 211 {
209 ASSERT(!s_endOfTaskRunner);
210 CoreInitializer::shutdown(); 212 CoreInitializer::shutdown();
211 Heap::shutdown(); 213 Heap::shutdown();
212 WTF::shutdown(); 214 WTF::shutdown();
213 Platform::shutdown(); 215 Platform::shutdown();
214 } 216 }
215 217
216 void setLayoutTestMode(bool value) 218 void setLayoutTestMode(bool value)
217 { 219 {
218 LayoutTestSupport::setIsRunningLayoutTest(value); 220 LayoutTestSupport::setIsRunningLayoutTest(value);
219 } 221 }
(...skipping 16 matching lines...) Expand all
236 void enableLogChannel(const char* name) 238 void enableLogChannel(const char* name)
237 { 239 {
238 #if !LOG_DISABLED 240 #if !LOG_DISABLED
239 WTFLogChannel* channel = getChannelFromName(name); 241 WTFLogChannel* channel = getChannelFromName(name);
240 if (channel) 242 if (channel)
241 channel->state = WTFLogChannelOn; 243 channel->state = WTFLogChannelOn;
242 #endif // !LOG_DISABLED 244 #endif // !LOG_DISABLED
243 } 245 }
244 246
245 } // namespace blink 247 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/web/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698