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

Side by Side Diff: third_party/WebKit/Source/core/css/FontLoader.cpp

Issue 1667843003: Make Resource RefCountedWillBeGarbageCollectedFinalized, attempt #2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + address review comments Created 4 years, 10 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
OLDNEW
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 "core/css/FontLoader.h" 5 #include "core/css/FontLoader.h"
6 6
7 #include "core/css/CSSFontSelector.h" 7 #include "core/css/CSSFontSelector.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/IncrementLoadEventDelayCount.h" 9 #include "core/dom/IncrementLoadEventDelayCount.h"
10 #include "core/fetch/FontResource.h" 10 #include "core/fetch/FontResource.h"
11 #include "core/inspector/ConsoleMessage.h" 11 #include "core/inspector/ConsoleMessage.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 struct FontLoader::FontToLoad { 15 struct FontLoader::FontToLoad : public NoBaseWillBeGarbageCollectedFinalized<Fon tLoader::FontToLoad> {
16 public: 16 public:
17 static PassOwnPtr<FontToLoad> create(FontResource* fontResource, Document& d ocument) 17 static PassOwnPtrWillBeRawPtr<FontToLoad> create(FontResource* fontResource, Document& document)
18 { 18 {
19 return adoptPtr(new FontToLoad(fontResource, document)); 19 return adoptPtrWillBeNoop(new FontToLoad(fontResource, document));
20 } 20 }
21 21
22 ResourcePtr<FontResource> fontResource; 22 virtual ~FontToLoad()
23 {
24 ASSERT(!fontResource);
25 }
26
27 RefPtrWillBeMember<FontResource> fontResource;
23 OwnPtr<IncrementLoadEventDelayCount> delay; 28 OwnPtr<IncrementLoadEventDelayCount> delay;
24 29
30 void dispose()
31 {
32 fontResource = nullptr;
33 delay.clear();
34 }
35
36 DEFINE_INLINE_TRACE() { visitor->trace(fontResource); }
37
25 private: 38 private:
26 FontToLoad(FontResource* resource, Document& document) 39 FontToLoad(FontResource* resource, Document& document)
27 : fontResource(resource) 40 : fontResource(resource)
28 , delay(IncrementLoadEventDelayCount::create(document)) 41 , delay(IncrementLoadEventDelayCount::create(document))
29 { 42 {
30 } 43 }
31 }; 44 };
32 45
33 FontLoader::FontLoader(CSSFontSelector* fontSelector, Document* document) 46 FontLoader::FontLoader(CSSFontSelector* fontSelector, Document* document)
34 : m_beginLoadingTimer(this, &FontLoader::beginLoadTimerFired) 47 : m_beginLoadingTimer(this, &FontLoader::beginLoadTimerFired)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 { 84 {
72 ASSERT(m_document); 85 ASSERT(m_document);
73 86
74 FontsToLoadVector fontsToBeginLoading; 87 FontsToLoadVector fontsToBeginLoading;
75 fontsToBeginLoading.swap(m_fontsToBeginLoading); 88 fontsToBeginLoading.swap(m_fontsToBeginLoading);
76 for (const auto& fontToLoad : fontsToBeginLoading) { 89 for (const auto& fontToLoad : fontsToBeginLoading) {
77 if (m_document->frame()) 90 if (m_document->frame())
78 fontToLoad->fontResource->beginLoadIfNeeded(m_document->fetcher()); 91 fontToLoad->fontResource->beginLoadIfNeeded(m_document->fetcher());
79 else 92 else
80 fontToLoad->fontResource->error(Resource::LoadError); 93 fontToLoad->fontResource->error(Resource::LoadError);
94 fontToLoad->dispose();
81 } 95 }
82 96
83 // When the local fontsToBeginLoading vector goes out of scope it will 97 // When the local fontsToBeginLoading vector goes out of scope it will
84 // decrement the request counts on the ResourceFetcher for all the fonts 98 // decrement the request counts on the ResourceFetcher for all the fonts
85 // that were just loaded. 99 // that were just loaded.
86 } 100 }
87 101
88 void FontLoader::fontFaceInvalidated() 102 void FontLoader::fontFaceInvalidated()
89 { 103 {
90 if (m_fontSelector) 104 if (m_fontSelector)
(...skipping 21 matching lines...) Expand all
112 126
113 m_beginLoadingTimer.stop(); 127 m_beginLoadingTimer.stop();
114 clearPendingFonts(); 128 clearPendingFonts();
115 m_document = nullptr; 129 m_document = nullptr;
116 m_fontSelector = nullptr; 130 m_fontSelector = nullptr;
117 } 131 }
118 #endif 132 #endif
119 133
120 void FontLoader::clearPendingFonts() 134 void FontLoader::clearPendingFonts()
121 { 135 {
122 for (const auto& fontToLoad : m_fontsToBeginLoading) 136 for (const auto& fontToLoad : m_fontsToBeginLoading) {
123 fontToLoad->fontResource->didUnscheduleLoad(); 137 fontToLoad->fontResource->didUnscheduleLoad();
138 fontToLoad->dispose();
139 }
124 m_fontsToBeginLoading.clear(); 140 m_fontsToBeginLoading.clear();
125 } 141 }
126 142
127 DEFINE_TRACE(FontLoader) 143 DEFINE_TRACE(FontLoader)
128 { 144 {
145 visitor->trace(m_fontsToBeginLoading);
129 visitor->trace(m_document); 146 visitor->trace(m_document);
130 visitor->trace(m_fontSelector); 147 visitor->trace(m_fontSelector);
131 } 148 }
132 149
133 } // namespace blink 150 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/FontLoader.h ('k') | third_party/WebKit/Source/core/css/RemoteFontFaceSource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698