| OLD | NEW |
| 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 29 matching lines...) Expand all Loading... |
| 40 #include "core/dom/Microtask.h" | 40 #include "core/dom/Microtask.h" |
| 41 #include "core/frame/Settings.h" | 41 #include "core/frame/Settings.h" |
| 42 #include "core/page/Page.h" | 42 #include "core/page/Page.h" |
| 43 #include "gin/public/v8_platform.h" | 43 #include "gin/public/v8_platform.h" |
| 44 #include "mojo/common/message_pump_mojo.h" | 44 #include "mojo/common/message_pump_mojo.h" |
| 45 #include "platform/LayoutTestSupport.h" | 45 #include "platform/LayoutTestSupport.h" |
| 46 #include "platform/Logging.h" | 46 #include "platform/Logging.h" |
| 47 #include "platform/RuntimeEnabledFeatures.h" | 47 #include "platform/RuntimeEnabledFeatures.h" |
| 48 #include "platform/graphics/ImageDecodingStore.h" | 48 #include "platform/graphics/ImageDecodingStore.h" |
| 49 #include "platform/graphics/media/MediaPlayer.h" | 49 #include "platform/graphics/media/MediaPlayer.h" |
| 50 #include "platform/heap/Heap.h" | |
| 51 #include "public/platform/Platform.h" | 50 #include "public/platform/Platform.h" |
| 52 #include "web/WebMediaPlayerClientImpl.h" | 51 #include "web/WebMediaPlayerClientImpl.h" |
| 53 #include "wtf/Assertions.h" | 52 #include "wtf/Assertions.h" |
| 54 #include "wtf/CryptographicallyRandomNumber.h" | 53 #include "wtf/CryptographicallyRandomNumber.h" |
| 55 #include "wtf/MainThread.h" | 54 #include "wtf/MainThread.h" |
| 56 #include "wtf/WTF.h" | 55 #include "wtf/WTF.h" |
| 57 #include "wtf/text/AtomicString.h" | 56 #include "wtf/text/AtomicString.h" |
| 58 #include "wtf/text/TextEncoding.h" | 57 #include "wtf/text/TextEncoding.h" |
| 59 #include <v8.h> | 58 #include <v8.h> |
| 60 | 59 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 delete s_taskObserver; | 108 delete s_taskObserver; |
| 110 s_taskObserver = 0; | 109 s_taskObserver = 0; |
| 111 | 110 |
| 112 ASSERT(s_signalObserver); | 111 ASSERT(s_signalObserver); |
| 113 delete s_signalObserver; | 112 delete s_signalObserver; |
| 114 s_signalObserver = 0; | 113 s_signalObserver = 0; |
| 115 } | 114 } |
| 116 | 115 |
| 117 } // namespace | 116 } // namespace |
| 118 | 117 |
| 119 static ThreadState::Interruptor* s_isolateInterruptor = 0; | |
| 120 | |
| 121 // Make sure we are not re-initialized in the same address space. | 118 // Make sure we are not re-initialized in the same address space. |
| 122 // Doing so may cause hard to reproduce crashes. | 119 // Doing so may cause hard to reproduce crashes. |
| 123 static bool s_webKitInitialized = false; | 120 static bool s_webKitInitialized = false; |
| 124 | 121 |
| 125 void initialize(Platform* platform) | 122 void initialize(Platform* platform) |
| 126 { | 123 { |
| 127 initializeWithoutV8(platform); | 124 initializeWithoutV8(platform); |
| 128 | 125 |
| 129 V8Initializer::initializeMainThreadIfNeeded(); | 126 V8Initializer::initializeMainThreadIfNeeded(); |
| 130 | 127 |
| 131 s_isolateInterruptor = new V8IsolateInterruptor(V8PerIsolateData::mainThread
Isolate()); | |
| 132 ThreadState::current()->addInterruptor(s_isolateInterruptor); | |
| 133 | |
| 134 addMessageLoopObservers(); | 128 addMessageLoopObservers(); |
| 135 } | 129 } |
| 136 | 130 |
| 137 v8::Isolate* mainThreadIsolate() | 131 v8::Isolate* mainThreadIsolate() |
| 138 { | 132 { |
| 139 return V8PerIsolateData::mainThreadIsolate(); | 133 return V8PerIsolateData::mainThreadIsolate(); |
| 140 } | 134 } |
| 141 | 135 |
| 142 static double currentTimeFunction() | 136 static double currentTimeFunction() |
| 143 { | 137 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 163 { | 157 { |
| 164 ASSERT(!s_webKitInitialized); | 158 ASSERT(!s_webKitInitialized); |
| 165 s_webKitInitialized = true; | 159 s_webKitInitialized = true; |
| 166 | 160 |
| 167 ASSERT(platform); | 161 ASSERT(platform); |
| 168 Platform::initialize(platform); | 162 Platform::initialize(platform); |
| 169 | 163 |
| 170 WTF::setRandomSource(cryptographicallyRandomValues); | 164 WTF::setRandomSource(cryptographicallyRandomValues); |
| 171 WTF::initialize(currentTimeFunction, monotonicallyIncreasingTimeFunction); | 165 WTF::initialize(currentTimeFunction, monotonicallyIncreasingTimeFunction); |
| 172 WTF::initializeMainThread(callOnMainThreadFunction); | 166 WTF::initializeMainThread(callOnMainThreadFunction); |
| 173 Heap::init(); | |
| 174 | |
| 175 ThreadState::attachMainThread(); | |
| 176 | 167 |
| 177 DEFINE_STATIC_LOCAL(CoreInitializer, initializer, ()); | 168 DEFINE_STATIC_LOCAL(CoreInitializer, initializer, ()); |
| 178 initializer.init(); | 169 initializer.init(); |
| 179 | 170 |
| 180 // There are some code paths (for example, running WebKit in the browser | 171 // There are some code paths (for example, running WebKit in the browser |
| 181 // process and calling into LocalStorage before anything else) where the | 172 // process and calling into LocalStorage before anything else) where the |
| 182 // UTF8 string encoding tables are used on a background thread before | 173 // UTF8 string encoding tables are used on a background thread before |
| 183 // they're set up. This is a problem because their set up routines assert | 174 // they're set up. This is a problem because their set up routines assert |
| 184 // they're running on the main WebKitThread. It might be possible to make | 175 // they're running on the main WebKitThread. It might be possible to make |
| 185 // the initialization thread-safe, but given that so many code paths use | 176 // the initialization thread-safe, but given that so many code paths use |
| 186 // this, initializing this lazily probably doesn't buy us much. | 177 // this, initializing this lazily probably doesn't buy us much. |
| 187 WTF::UTF8Encoding(); | 178 WTF::UTF8Encoding(); |
| 188 | 179 |
| 189 MediaPlayer::setMediaEngineCreateFunction(WebMediaPlayerClientImpl::create); | 180 MediaPlayer::setMediaEngineCreateFunction(WebMediaPlayerClientImpl::create); |
| 190 } | 181 } |
| 191 | 182 |
| 192 void shutdown() | 183 void shutdown() |
| 193 { | 184 { |
| 194 removeMessageLoopObservers(); | 185 removeMessageLoopObservers(); |
| 195 | 186 |
| 196 ASSERT(s_isolateInterruptor); | |
| 197 ThreadState::current()->removeInterruptor(s_isolateInterruptor); | |
| 198 | |
| 199 // Detach the main thread before starting the shutdown sequence | |
| 200 // so that the main thread won't get involved in a GC during the shutdown. | |
| 201 ThreadState::detachMainThread(); | |
| 202 | |
| 203 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | 187 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); |
| 204 V8PerIsolateData::dispose(isolate); | 188 V8PerIsolateData::dispose(isolate); |
| 205 | 189 |
| 206 shutdownWithoutV8(); | 190 shutdownWithoutV8(); |
| 207 } | 191 } |
| 208 | 192 |
| 209 void shutdownWithoutV8() | 193 void shutdownWithoutV8() |
| 210 { | 194 { |
| 211 CoreInitializer::shutdown(); | 195 CoreInitializer::shutdown(); |
| 212 Heap::shutdown(); | |
| 213 WTF::shutdown(); | 196 WTF::shutdown(); |
| 214 Platform::shutdown(); | 197 Platform::shutdown(); |
| 215 } | 198 } |
| 216 | 199 |
| 217 void setLayoutTestMode(bool value) | 200 void setLayoutTestMode(bool value) |
| 218 { | 201 { |
| 219 LayoutTestSupport::setIsRunningLayoutTest(value); | 202 LayoutTestSupport::setIsRunningLayoutTest(value); |
| 220 } | 203 } |
| 221 | 204 |
| 222 bool layoutTestMode() | 205 bool layoutTestMode() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 237 void enableLogChannel(const char* name) | 220 void enableLogChannel(const char* name) |
| 238 { | 221 { |
| 239 #if !LOG_DISABLED | 222 #if !LOG_DISABLED |
| 240 WTFLogChannel* channel = getChannelFromName(name); | 223 WTFLogChannel* channel = getChannelFromName(name); |
| 241 if (channel) | 224 if (channel) |
| 242 channel->state = WTFLogChannelOn; | 225 channel->state = WTFLogChannelOn; |
| 243 #endif // !LOG_DISABLED | 226 #endif // !LOG_DISABLED |
| 244 } | 227 } |
| 245 | 228 |
| 246 } // namespace blink | 229 } // namespace blink |
| OLD | NEW |