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

Side by Side Diff: Source/web/WebKit.cpp

Issue 471503002: Cleanup namespace usage in Source/web/Web[I-Z]*.cpp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 | « Source/web/WebInputEventConversion.cpp ('k') | Source/web/WebLabelElement.cpp » ('j') | 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "web/IndexedDBClientImpl.h" 57 #include "web/IndexedDBClientImpl.h"
58 #include "web/WebMediaPlayerClientImpl.h" 58 #include "web/WebMediaPlayerClientImpl.h"
59 #include "wtf/Assertions.h" 59 #include "wtf/Assertions.h"
60 #include "wtf/CryptographicallyRandomNumber.h" 60 #include "wtf/CryptographicallyRandomNumber.h"
61 #include "wtf/MainThread.h" 61 #include "wtf/MainThread.h"
62 #include "wtf/WTF.h" 62 #include "wtf/WTF.h"
63 #include "wtf/text/AtomicString.h" 63 #include "wtf/text/AtomicString.h"
64 #include "wtf/text/TextEncoding.h" 64 #include "wtf/text/TextEncoding.h"
65 #include <v8.h> 65 #include <v8.h>
66 66
67 using blink::LayoutTestSupport;
68
69 namespace blink { 67 namespace blink {
70 68
71 namespace { 69 namespace {
72 70
73 class EndOfTaskRunner : public WebThread::TaskObserver { 71 class EndOfTaskRunner : public WebThread::TaskObserver {
74 public: 72 public:
75 virtual void willProcessTask() OVERRIDE 73 virtual void willProcessTask() OVERRIDE
76 { 74 {
77 blink::AnimationClock::notifyTaskStart(); 75 AnimationClock::notifyTaskStart();
78 } 76 }
79 virtual void didProcessTask() OVERRIDE 77 virtual void didProcessTask() OVERRIDE
80 { 78 {
81 blink::Microtask::performCheckpoint(); 79 Microtask::performCheckpoint();
82 blink::V8GCController::reportDOMMemoryUsageToV8(mainThreadIsolate()); 80 V8GCController::reportDOMMemoryUsageToV8(mainThreadIsolate());
83 } 81 }
84 }; 82 };
85 83
86 } // namespace 84 } // namespace
87 85
88 static WebThread::TaskObserver* s_endOfTaskRunner = 0; 86 static WebThread::TaskObserver* s_endOfTaskRunner = 0;
89 static WebThread::TaskObserver* s_pendingGCRunner = 0; 87 static WebThread::TaskObserver* s_pendingGCRunner = 0;
90 static blink::ThreadState::Interruptor* s_messageLoopInterruptor = 0; 88 static ThreadState::Interruptor* s_messageLoopInterruptor = 0;
91 static blink::ThreadState::Interruptor* s_isolateInterruptor = 0; 89 static ThreadState::Interruptor* s_isolateInterruptor = 0;
92 90
93 // Make sure we are not re-initialized in the same address space. 91 // Make sure we are not re-initialized in the same address space.
94 // Doing so may cause hard to reproduce crashes. 92 // Doing so may cause hard to reproduce crashes.
95 static bool s_webKitInitialized = false; 93 static bool s_webKitInitialized = false;
96 94
97 static bool generateEntropy(unsigned char* buffer, size_t length) 95 static bool generateEntropy(unsigned char* buffer, size_t length)
98 { 96 {
99 if (Platform::current()) { 97 if (Platform::current()) {
100 Platform::current()->cryptographicallyRandomValues(buffer, length); 98 Platform::current()->cryptographicallyRandomValues(buffer, length);
101 return true; 99 return true;
102 } 100 }
103 return false; 101 return false;
104 } 102 }
105 103
106 void initialize(Platform* platform) 104 void initialize(Platform* platform)
107 { 105 {
108 initializeWithoutV8(platform); 106 initializeWithoutV8(platform);
109 107
110 v8::V8::InitializePlatform(gin::V8Platform::Get()); 108 v8::V8::InitializePlatform(gin::V8Platform::Get());
111 v8::Isolate* isolate = v8::Isolate::New(); 109 v8::Isolate* isolate = v8::Isolate::New();
112 isolate->Enter(); 110 isolate->Enter();
113 blink::V8Initializer::initializeMainThreadIfNeeded(isolate); 111 V8Initializer::initializeMainThreadIfNeeded(isolate);
114 v8::V8::SetEntropySource(&generateEntropy); 112 v8::V8::SetEntropySource(&generateEntropy);
115 v8::V8::SetArrayBufferAllocator(blink::v8ArrayBufferAllocator()); 113 v8::V8::SetArrayBufferAllocator(v8ArrayBufferAllocator());
116 v8::V8::Initialize(); 114 v8::V8::Initialize();
117 blink::V8PerIsolateData::ensureInitialized(isolate); 115 V8PerIsolateData::ensureInitialized(isolate);
118 116
119 s_isolateInterruptor = new blink::V8IsolateInterruptor(v8::Isolate::GetCurre nt()); 117 s_isolateInterruptor = new V8IsolateInterruptor(v8::Isolate::GetCurrent());
120 blink::ThreadState::current()->addInterruptor(s_isolateInterruptor); 118 ThreadState::current()->addInterruptor(s_isolateInterruptor);
121 119
122 // currentThread will always be non-null in production, but can be null in C hromium unit tests. 120 // currentThread will always be non-null in production, but can be null in C hromium unit tests.
123 if (WebThread* currentThread = platform->currentThread()) { 121 if (WebThread* currentThread = platform->currentThread()) {
124 ASSERT(!s_endOfTaskRunner); 122 ASSERT(!s_endOfTaskRunner);
125 s_endOfTaskRunner = new EndOfTaskRunner; 123 s_endOfTaskRunner = new EndOfTaskRunner;
126 currentThread->addTaskObserver(s_endOfTaskRunner); 124 currentThread->addTaskObserver(s_endOfTaskRunner);
127 } 125 }
128 } 126 }
129 127
130 v8::Isolate* mainThreadIsolate() 128 v8::Isolate* mainThreadIsolate()
131 { 129 {
132 return blink::V8PerIsolateData::mainThreadIsolate(); 130 return V8PerIsolateData::mainThreadIsolate();
133 } 131 }
134 132
135 static double currentTimeFunction() 133 static double currentTimeFunction()
136 { 134 {
137 return Platform::current()->currentTime(); 135 return Platform::current()->currentTime();
138 } 136 }
139 137
140 static double monotonicallyIncreasingTimeFunction() 138 static double monotonicallyIncreasingTimeFunction()
141 { 139 {
142 return Platform::current()->monotonicallyIncreasingTime(); 140 return Platform::current()->monotonicallyIncreasingTime();
143 } 141 }
144 142
145 static void cryptographicallyRandomValues(unsigned char* buffer, size_t length) 143 static void cryptographicallyRandomValues(unsigned char* buffer, size_t length)
146 { 144 {
147 Platform::current()->cryptographicallyRandomValues(buffer, length); 145 Platform::current()->cryptographicallyRandomValues(buffer, length);
148 } 146 }
149 147
150 static void callOnMainThreadFunction(WTF::MainThreadFunction function, void* con text) 148 static void callOnMainThreadFunction(WTF::MainThreadFunction function, void* con text)
151 { 149 {
152 blink::Scheduler::shared()->postTask(FROM_HERE, bind(function, context)); 150 Scheduler::shared()->postTask(FROM_HERE, bind(function, context));
153 } 151 }
154 152
155 void initializeWithoutV8(Platform* platform) 153 void initializeWithoutV8(Platform* platform)
156 { 154 {
157 ASSERT(!s_webKitInitialized); 155 ASSERT(!s_webKitInitialized);
158 s_webKitInitialized = true; 156 s_webKitInitialized = true;
159 157
160 ASSERT(platform); 158 ASSERT(platform);
161 Platform::initialize(platform); 159 Platform::initialize(platform);
162 160
163 WTF::setRandomSource(cryptographicallyRandomValues); 161 WTF::setRandomSource(cryptographicallyRandomValues);
164 WTF::initialize(currentTimeFunction, monotonicallyIncreasingTimeFunction); 162 WTF::initialize(currentTimeFunction, monotonicallyIncreasingTimeFunction);
165 WTF::initializeMainThread(callOnMainThreadFunction); 163 WTF::initializeMainThread(callOnMainThreadFunction);
166 blink::Heap::init(); 164 Heap::init();
167 blink::Scheduler::initializeOnMainThread(); 165 Scheduler::initializeOnMainThread();
168 166
169 blink::ThreadState::attachMainThread(); 167 ThreadState::attachMainThread();
170 // currentThread will always be non-null in production, but can be null in C hromium unit tests. 168 // currentThread will always be non-null in production, but can be null in C hromium unit tests.
171 if (WebThread* currentThread = platform->currentThread()) { 169 if (WebThread* currentThread = platform->currentThread()) {
172 ASSERT(!s_pendingGCRunner); 170 ASSERT(!s_pendingGCRunner);
173 s_pendingGCRunner = new blink::PendingGCRunner; 171 s_pendingGCRunner = new PendingGCRunner;
174 currentThread->addTaskObserver(s_pendingGCRunner); 172 currentThread->addTaskObserver(s_pendingGCRunner);
175 173
176 ASSERT(!s_messageLoopInterruptor); 174 ASSERT(!s_messageLoopInterruptor);
177 s_messageLoopInterruptor = new blink::MessageLoopInterruptor(currentThre ad); 175 s_messageLoopInterruptor = new MessageLoopInterruptor(currentThread);
178 blink::ThreadState::current()->addInterruptor(s_messageLoopInterruptor); 176 ThreadState::current()->addInterruptor(s_messageLoopInterruptor);
179 } 177 }
180 178
181 DEFINE_STATIC_LOCAL(blink::ModulesInitializer, initializer, ()); 179 DEFINE_STATIC_LOCAL(ModulesInitializer, initializer, ());
182 initializer.init(); 180 initializer.init();
183 181
184 // There are some code paths (for example, running WebKit in the browser 182 // There are some code paths (for example, running WebKit in the browser
185 // process and calling into LocalStorage before anything else) where the 183 // process and calling into LocalStorage before anything else) where the
186 // UTF8 string encoding tables are used on a background thread before 184 // UTF8 string encoding tables are used on a background thread before
187 // they're set up. This is a problem because their set up routines assert 185 // they're set up. This is a problem because their set up routines assert
188 // they're running on the main WebKitThread. It might be possible to make 186 // they're running on the main WebKitThread. It might be possible to make
189 // the initialization thread-safe, but given that so many code paths use 187 // the initialization thread-safe, but given that so many code paths use
190 // this, initializing this lazily probably doesn't buy us much. 188 // this, initializing this lazily probably doesn't buy us much.
191 WTF::UTF8Encoding(); 189 WTF::UTF8Encoding();
192 190
193 blink::setIndexedDBClientCreateFunction(blink::IndexedDBClientImpl::create); 191 setIndexedDBClientCreateFunction(IndexedDBClientImpl::create);
194 192
195 blink::MediaPlayer::setMediaEngineCreateFunction(blink::WebMediaPlayerClient Impl::create); 193 MediaPlayer::setMediaEngineCreateFunction(WebMediaPlayerClientImpl::create);
196 } 194 }
197 195
198 void shutdown() 196 void shutdown()
199 { 197 {
200 // currentThread will always be non-null in production, but can be null in C hromium unit tests. 198 // currentThread will always be non-null in production, but can be null in C hromium unit tests.
201 if (Platform::current()->currentThread()) { 199 if (Platform::current()->currentThread()) {
202 ASSERT(s_endOfTaskRunner); 200 ASSERT(s_endOfTaskRunner);
203 Platform::current()->currentThread()->removeTaskObserver(s_endOfTaskRunn er); 201 Platform::current()->currentThread()->removeTaskObserver(s_endOfTaskRunn er);
204 delete s_endOfTaskRunner; 202 delete s_endOfTaskRunner;
205 s_endOfTaskRunner = 0; 203 s_endOfTaskRunner = 0;
206 } 204 }
207 205
208 ASSERT(s_isolateInterruptor); 206 ASSERT(s_isolateInterruptor);
209 blink::ThreadState::current()->removeInterruptor(s_isolateInterruptor); 207 ThreadState::current()->removeInterruptor(s_isolateInterruptor);
210 208
211 // currentThread will always be non-null in production, but can be null in C hromium unit tests. 209 // currentThread will always be non-null in production, but can be null in C hromium unit tests.
212 if (Platform::current()->currentThread()) { 210 if (Platform::current()->currentThread()) {
213 ASSERT(s_pendingGCRunner); 211 ASSERT(s_pendingGCRunner);
214 delete s_pendingGCRunner; 212 delete s_pendingGCRunner;
215 s_pendingGCRunner = 0; 213 s_pendingGCRunner = 0;
216 214
217 ASSERT(s_messageLoopInterruptor); 215 ASSERT(s_messageLoopInterruptor);
218 blink::ThreadState::current()->removeInterruptor(s_messageLoopInterrupto r); 216 ThreadState::current()->removeInterruptor(s_messageLoopInterruptor);
219 delete s_messageLoopInterruptor; 217 delete s_messageLoopInterruptor;
220 s_messageLoopInterruptor = 0; 218 s_messageLoopInterruptor = 0;
221 } 219 }
222 220
223 // Detach the main thread before starting the shutdown sequence 221 // Detach the main thread before starting the shutdown sequence
224 // so that the main thread won't get involved in a GC during the shutdown. 222 // so that the main thread won't get involved in a GC during the shutdown.
225 blink::ThreadState::detachMainThread(); 223 ThreadState::detachMainThread();
226 224
227 v8::Isolate* isolate = blink::V8PerIsolateData::mainThreadIsolate(); 225 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
228 blink::V8PerIsolateData::dispose(isolate); 226 V8PerIsolateData::dispose(isolate);
229 isolate->Exit(); 227 isolate->Exit();
230 isolate->Dispose(); 228 isolate->Dispose();
231 229
232 shutdownWithoutV8(); 230 shutdownWithoutV8();
233 } 231 }
234 232
235 void shutdownWithoutV8() 233 void shutdownWithoutV8()
236 { 234 {
237 ASSERT(!s_endOfTaskRunner); 235 ASSERT(!s_endOfTaskRunner);
238 blink::CoreInitializer::shutdown(); 236 CoreInitializer::shutdown();
239 blink::Heap::shutdown(); 237 Heap::shutdown();
240 WTF::shutdown(); 238 WTF::shutdown();
241 blink::Scheduler::shutdown(); 239 Scheduler::shutdown();
242 Platform::shutdown(); 240 Platform::shutdown();
243 WebPrerenderingSupport::shutdown(); 241 WebPrerenderingSupport::shutdown();
244 } 242 }
245 243
246 void setLayoutTestMode(bool value) 244 void setLayoutTestMode(bool value)
247 { 245 {
248 LayoutTestSupport::setIsRunningLayoutTest(value); 246 LayoutTestSupport::setIsRunningLayoutTest(value);
249 } 247 }
250 248
251 bool layoutTestMode() 249 bool layoutTestMode()
252 { 250 {
253 return LayoutTestSupport::isRunningLayoutTest(); 251 return LayoutTestSupport::isRunningLayoutTest();
254 } 252 }
255 253
256 void setFontAntialiasingEnabledForTest(bool value) 254 void setFontAntialiasingEnabledForTest(bool value)
257 { 255 {
258 LayoutTestSupport::setFontAntialiasingEnabledForTest(value); 256 LayoutTestSupport::setFontAntialiasingEnabledForTest(value);
259 } 257 }
260 258
261 bool fontAntialiasingEnabledForTest() 259 bool fontAntialiasingEnabledForTest()
262 { 260 {
263 return LayoutTestSupport::isFontAntialiasingEnabledForTest(); 261 return LayoutTestSupport::isFontAntialiasingEnabledForTest();
264 } 262 }
265 263
266 void enableLogChannel(const char* name) 264 void enableLogChannel(const char* name)
267 { 265 {
268 #if !LOG_DISABLED 266 #if !LOG_DISABLED
269 WTFLogChannel* channel = blink::getChannelFromName(name); 267 WTFLogChannel* channel = getChannelFromName(name);
270 if (channel) 268 if (channel)
271 channel->state = WTFLogChannelOn; 269 channel->state = WTFLogChannelOn;
272 #endif // !LOG_DISABLED 270 #endif // !LOG_DISABLED
273 } 271 }
274 272
275 void resetPluginCache(bool reloadPages) 273 void resetPluginCache(bool reloadPages)
276 { 274 {
277 blink::Page::refreshPlugins(reloadPages); 275 Page::refreshPlugins(reloadPages);
278 } 276 }
279 277
280 } // namespace blink 278 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebInputEventConversion.cpp ('k') | Source/web/WebLabelElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698