OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/css/FontLoader.h" | 6 #include "core/css/FontLoader.h" |
7 | 7 |
8 #include "core/css/CSSFontSelector.h" | 8 #include "core/css/CSSFontSelector.h" |
9 #include "core/fetch/FontResource.h" | 9 #include "core/fetch/FontResource.h" |
10 #include "core/fetch/ResourceFetcher.h" | 10 #include "core/fetch/ResourceFetcher.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 FontLoader::FontLoader(CSSFontSelector* fontSelector, ResourceFetcher* resourceF
etcher) | 14 FontLoader::FontLoader(CSSFontSelector* fontSelector, ResourceFetcher* resourceF
etcher) |
15 : m_beginLoadingTimer(this, &FontLoader::beginLoadTimerFired) | 15 : m_beginLoadingTimer(this, &FontLoader::beginLoadTimerFired) |
16 , m_fontSelector(fontSelector) | 16 , m_fontSelector(fontSelector) |
17 , m_resourceFetcher(resourceFetcher) | 17 , m_resourceFetcher(resourceFetcher) |
18 { | 18 { |
19 } | 19 } |
20 | 20 |
21 FontLoader::~FontLoader() | 21 FontLoader::~FontLoader() |
22 { | 22 { |
23 #if ENABLE(OILPAN) | 23 #if ENABLE(OILPAN) |
24 if (!m_resourceFetcher) { | 24 if (!m_resourceFetcher) { |
25 ASSERT(m_fontsToBeginLoading.isEmpty()); | 25 ASSERT(m_fontsToBeginLoading.isEmpty()); |
26 return; | 26 return; |
27 } | 27 } |
28 m_beginLoadingTimer.stop(); | 28 m_beginLoadingTimer.stop(); |
29 | 29 // This will decrement the request counts on the ResourceFetcher for all the |
30 // When the m_fontsToBeginLoading vector is destroyed it will decrement the | 30 // fonts that were pending at the time the FontLoader dies. |
31 // request counts on the ResourceFetcher for all the fonts that were pending | 31 clearPendingFonts(); |
32 // at the time the FontLoader dies. | |
33 #endif | 32 #endif |
34 } | 33 } |
35 | 34 |
36 void FontLoader::addFontToBeginLoading(FontResource* fontResource) | 35 void FontLoader::addFontToBeginLoading(FontResource* fontResource) |
37 { | 36 { |
38 if (!m_resourceFetcher || !fontResource->stillNeedsLoad()) | 37 if (!m_resourceFetcher || !fontResource->stillNeedsLoad() || fontResource->l
oadScheduled()) |
39 return; | 38 return; |
40 | 39 |
41 m_fontsToBeginLoading.append( | 40 m_fontsToBeginLoading.append( |
42 std::make_pair(fontResource, ResourceLoader::RequestCountTracker(m_resou
rceFetcher, fontResource))); | 41 std::make_pair(fontResource, ResourceLoader::RequestCountTracker(m_resou
rceFetcher, fontResource))); |
| 42 fontResource->setLoadScheduled(true); |
43 if (!m_beginLoadingTimer.isActive()) | 43 if (!m_beginLoadingTimer.isActive()) |
44 m_beginLoadingTimer.startOneShot(0, FROM_HERE); | 44 m_beginLoadingTimer.startOneShot(0, FROM_HERE); |
45 } | 45 } |
46 | 46 |
47 void FontLoader::beginLoadTimerFired(Timer<blink::FontLoader>*) | 47 void FontLoader::beginLoadTimerFired(Timer<blink::FontLoader>*) |
48 { | 48 { |
49 loadPendingFonts(); | 49 loadPendingFonts(); |
50 } | 50 } |
51 | 51 |
52 void FontLoader::loadPendingFonts() | 52 void FontLoader::loadPendingFonts() |
(...skipping 20 matching lines...) Expand all Loading... |
73 | 73 |
74 #if !ENABLE(OILPAN) | 74 #if !ENABLE(OILPAN) |
75 void FontLoader::clearResourceFetcherAndFontSelector() | 75 void FontLoader::clearResourceFetcherAndFontSelector() |
76 { | 76 { |
77 if (!m_resourceFetcher) { | 77 if (!m_resourceFetcher) { |
78 ASSERT(m_fontsToBeginLoading.isEmpty()); | 78 ASSERT(m_fontsToBeginLoading.isEmpty()); |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
82 m_beginLoadingTimer.stop(); | 82 m_beginLoadingTimer.stop(); |
83 m_fontsToBeginLoading.clear(); | 83 clearPendingFonts(); |
84 m_resourceFetcher = nullptr; | 84 m_resourceFetcher = nullptr; |
85 m_fontSelector = nullptr; | 85 m_fontSelector = nullptr; |
86 } | 86 } |
87 #endif | 87 #endif |
88 | 88 |
| 89 void FontLoader::clearPendingFonts() |
| 90 { |
| 91 for (FontsToLoadVector::iterator it = m_fontsToBeginLoading.begin(); it != m
_fontsToBeginLoading.end(); ++it) |
| 92 it->first->setLoadScheduled(false); |
| 93 m_fontsToBeginLoading.clear(); |
| 94 } |
| 95 |
89 void FontLoader::trace(Visitor* visitor) | 96 void FontLoader::trace(Visitor* visitor) |
90 { | 97 { |
91 visitor->trace(m_resourceFetcher); | 98 visitor->trace(m_resourceFetcher); |
92 visitor->trace(m_fontSelector); | 99 visitor->trace(m_fontSelector); |
93 } | 100 } |
94 | 101 |
95 } // namespace blink | 102 } // namespace blink |
OLD | NEW |