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

Side by Side Diff: Source/core/css/FontFaceSet.cpp

Issue 27571005: Replace Timers used in ActiveDOMObject with AsyncMethodRunner (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 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 | « Source/core/css/FontFaceSet.h ('k') | Source/core/xml/XMLHttpRequest.h » ('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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
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
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 , m_resolver(ScriptPromiseResolver::create(promise, context)) 131 , m_resolver(ScriptPromiseResolver::create(promise, context))
132 { } 132 { }
133 ScriptState* m_scriptState; 133 ScriptState* m_scriptState;
134 RefPtr<ScriptPromiseResolver> m_resolver; 134 RefPtr<ScriptPromiseResolver> m_resolver;
135 }; 135 };
136 136
137 FontFaceSet::FontFaceSet(Document* document) 137 FontFaceSet::FontFaceSet(Document* document)
138 : ActiveDOMObject(document) 138 : ActiveDOMObject(document)
139 , m_loadingCount(0) 139 , m_loadingCount(0)
140 , m_shouldFireDoneEvent(false) 140 , m_shouldFireDoneEvent(false)
141 , m_timer(this, &FontFaceSet::timerFired) 141 , m_asyncRunner(this, &FontFaceSet::handlePendingEventsAndPromises)
142 { 142 {
143 suspendIfNeeded(); 143 suspendIfNeeded();
144 } 144 }
145 145
146 FontFaceSet::~FontFaceSet() 146 FontFaceSet::~FontFaceSet()
147 { 147 {
148 } 148 }
149 149
150 Document* FontFaceSet::document() const 150 Document* FontFaceSet::document() const
151 { 151 {
(...skipping 10 matching lines...) Expand all
162 return ActiveDOMObject::executionContext(); 162 return ActiveDOMObject::executionContext();
163 } 163 }
164 164
165 AtomicString FontFaceSet::status() const 165 AtomicString FontFaceSet::status() const
166 { 166 {
167 DEFINE_STATIC_LOCAL(AtomicString, loading, ("loading", AtomicString::Constru ctFromLiteral)); 167 DEFINE_STATIC_LOCAL(AtomicString, loading, ("loading", AtomicString::Constru ctFromLiteral));
168 DEFINE_STATIC_LOCAL(AtomicString, loaded, ("loaded", AtomicString::Construct FromLiteral)); 168 DEFINE_STATIC_LOCAL(AtomicString, loaded, ("loaded", AtomicString::Construct FromLiteral));
169 return (m_loadingCount > 0 || m_shouldFireDoneEvent) ? loading : loaded; 169 return (m_loadingCount > 0 || m_shouldFireDoneEvent) ? loading : loaded;
170 } 170 }
171 171
172 void FontFaceSet::handlePendingEventsAndPromisesSoon()
173 {
174 // setPendingActivity() is unnecessary because m_asyncRunner will be
175 // automatically stopped on destruction.
176 m_asyncRunner.runAsync();
177 }
178
172 void FontFaceSet::didLayout() 179 void FontFaceSet::didLayout()
173 { 180 {
174 Document* d = document(); 181 Document* d = document();
175 if (d->page() && d->page()->mainFrame() == d->frame()) 182 if (d->page() && d->page()->mainFrame() == d->frame())
176 m_histogram.record(); 183 m_histogram.record();
177 if (!RuntimeEnabledFeatures::fontLoadEventsEnabled()) 184 if (!RuntimeEnabledFeatures::fontLoadEventsEnabled())
178 return; 185 return;
179 if (m_loadingCount || (!m_shouldFireDoneEvent && m_readyResolvers.isEmpty()) ) 186 if (m_loadingCount || (!m_shouldFireDoneEvent && m_readyResolvers.isEmpty()) )
180 return; 187 return;
181 if (!m_timer.isActive()) 188 handlePendingEventsAndPromisesSoon();
182 m_timer.startOneShot(0);
183 } 189 }
184 190
185 void FontFaceSet::timerFired(Timer<FontFaceSet>*) 191 void FontFaceSet::handlePendingEventsAndPromises()
186 { 192 {
187 firePendingEvents(); 193 firePendingEvents();
188 resolvePendingLoadPromises(); 194 resolvePendingLoadPromises();
189 fireDoneEventIfPossible(); 195 fireDoneEventIfPossible();
190 } 196 }
191 197
192 void FontFaceSet::scheduleEvent(PassRefPtr<Event> event) 198 void FontFaceSet::scheduleEvent(PassRefPtr<Event> event)
193 { 199 {
194 m_pendingEvents.append(event); 200 m_pendingEvents.append(event);
195 if (!m_timer.isActive()) 201 handlePendingEventsAndPromisesSoon();
196 m_timer.startOneShot(0);
197 } 202 }
198 203
199 void FontFaceSet::firePendingEvents() 204 void FontFaceSet::firePendingEvents()
200 { 205 {
201 if (m_pendingEvents.isEmpty()) 206 if (m_pendingEvents.isEmpty())
202 return; 207 return;
203 208
204 Vector<RefPtr<Event> > pendingEvents; 209 Vector<RefPtr<Event> > pendingEvents;
205 m_pendingEvents.swap(pendingEvents); 210 m_pendingEvents.swap(pendingEvents);
206 for (size_t index = 0; index < pendingEvents.size(); ++index) 211 for (size_t index = 0; index < pendingEvents.size(); ++index)
207 dispatchEvent(pendingEvents[index].release()); 212 dispatchEvent(pendingEvents[index].release());
208 } 213 }
209 214
215 void FontFaceSet::suspend()
216 {
217 m_asyncRunner.suspend();
218 }
219
220 void FontFaceSet::resume()
221 {
222 m_asyncRunner.resume();
223 }
224
225 void FontFaceSet::stop()
226 {
227 m_asyncRunner.stop();
228 }
229
210 void FontFaceSet::scheduleResolve(LoadFontPromiseResolver* resolver) 230 void FontFaceSet::scheduleResolve(LoadFontPromiseResolver* resolver)
211 { 231 {
212 m_pendingLoadResolvers.append(resolver); 232 m_pendingLoadResolvers.append(resolver);
213 if (!m_timer.isActive()) 233 handlePendingEventsAndPromisesSoon();
214 m_timer.startOneShot(0);
215 } 234 }
216 235
217 void FontFaceSet::resolvePendingLoadPromises() 236 void FontFaceSet::resolvePendingLoadPromises()
218 { 237 {
219 if (m_pendingLoadResolvers.isEmpty()) 238 if (m_pendingLoadResolvers.isEmpty())
220 return; 239 return;
221 240
222 Vector<RefPtr<LoadFontPromiseResolver> > resolvers; 241 Vector<RefPtr<LoadFontPromiseResolver> > resolvers;
223 m_pendingLoadResolvers.swap(resolvers); 242 m_pendingLoadResolvers.swap(resolvers);
224 for (size_t index = 0; index < resolvers.size(); ++index) 243 for (size_t index = 0; index < resolvers.size(); ++index)
(...skipping 28 matching lines...) Expand all
253 queueDoneEvent(fontFace); 272 queueDoneEvent(fontFace);
254 } 273 }
255 274
256 void FontFaceSet::queueDoneEvent(FontFace* fontFace) 275 void FontFaceSet::queueDoneEvent(FontFace* fontFace)
257 { 276 {
258 ASSERT(m_loadingCount > 0); 277 ASSERT(m_loadingCount > 0);
259 --m_loadingCount; 278 --m_loadingCount;
260 if (!m_loadingCount) { 279 if (!m_loadingCount) {
261 ASSERT(!m_shouldFireDoneEvent); 280 ASSERT(!m_shouldFireDoneEvent);
262 m_shouldFireDoneEvent = true; 281 m_shouldFireDoneEvent = true;
263 if (!m_timer.isActive()) 282 handlePendingEventsAndPromisesSoon();
264 m_timer.startOneShot(0);
265 } 283 }
266 } 284 }
267 285
268 ScriptPromise FontFaceSet::ready() 286 ScriptPromise FontFaceSet::ready()
269 { 287 {
270 ScriptPromise promise = ScriptPromise::createPending(executionContext()); 288 ScriptPromise promise = ScriptPromise::createPending(executionContext());
271 OwnPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseResolver::crea te(promise, executionContext()); 289 OwnPtr<FontsReadyPromiseResolver> resolver = FontsReadyPromiseResolver::crea te(promise, executionContext());
272 m_readyResolvers.append(resolver.release()); 290 m_readyResolvers.append(resolver.release());
273 if (!m_timer.isActive()) 291 handlePendingEventsAndPromisesSoon();
274 m_timer.startOneShot(0);
275 return promise; 292 return promise;
276 } 293 }
277 294
278 void FontFaceSet::fireDoneEventIfPossible() 295 void FontFaceSet::fireDoneEventIfPossible()
279 { 296 {
280 if (!m_pendingEvents.isEmpty() || !m_pendingLoadResolvers.isEmpty()) 297 if (!m_pendingEvents.isEmpty() || !m_pendingLoadResolvers.isEmpty())
281 return; 298 return;
282 if (m_loadingCount || (!m_shouldFireDoneEvent && m_readyResolvers.isEmpty()) ) 299 if (m_loadingCount || (!m_shouldFireDoneEvent && m_readyResolvers.isEmpty()) )
283 return; 300 return;
284 301
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 439
423 void FontFaceSet::FontLoadHistogram::record() 440 void FontFaceSet::FontLoadHistogram::record()
424 { 441 {
425 if (m_recorded) 442 if (m_recorded)
426 return; 443 return;
427 m_recorded = true; 444 m_recorded = true;
428 HistogramSupport::histogramCustomCounts("WebFont.WebFontsInPage", m_count, 1 , 100, 50); 445 HistogramSupport::histogramCustomCounts("WebFont.WebFontsInPage", m_count, 1 , 100, 50);
429 } 446 }
430 447
431 } // namespace WebCore 448 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/FontFaceSet.h ('k') | Source/core/xml/XMLHttpRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698