OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. | 3 * Copyright (C) 2009 Torch Mobile, Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 static void recordPackageFormatHistogram(FontPackageFormat format) | 67 static void recordPackageFormatHistogram(FontPackageFormat format) |
68 { | 68 { |
69 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, packageFormatHistogram , new EnumerationHistogram("WebFont.PackageFormat", PackageFormatEnumMax)); | 69 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, packageFormatHistogram , new EnumerationHistogram("WebFont.PackageFormat", PackageFormatEnumMax)); |
70 packageFormatHistogram.count(format); | 70 packageFormatHistogram.count(format); |
71 } | 71 } |
72 | 72 |
73 FontResource* FontResource::fetch(FetchRequest& request, ResourceFetcher* fetche r) | 73 FontResource* FontResource::fetch(FetchRequest& request, ResourceFetcher* fetche r) |
74 { | 74 { |
75 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone ); | 75 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone ); |
76 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon textFont); | 76 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon textFont); |
77 // Defer the load until the font is actually needed unless this is a preload . | |
78 if (!request.forPreload()) | |
79 request.setDefer(FetchRequest::DeferredByClient); | |
77 return toFontResource(fetcher->requestResource(request, FontResourceFactory( ))); | 80 return toFontResource(fetcher->requestResource(request, FontResourceFactory( ))); |
78 } | 81 } |
79 | 82 |
80 FontResource::FontResource(const ResourceRequest& resourceRequest, const Resourc eLoaderOptions& options) | 83 FontResource::FontResource(const ResourceRequest& resourceRequest, const Resourc eLoaderOptions& options) |
81 : Resource(resourceRequest, Font, options) | 84 : Resource(resourceRequest, Font, options) |
82 , m_loadLimitState(UnderLimit) | 85 , m_loadLimitState(UnderLimit) |
83 , m_corsFailed(false) | 86 , m_corsFailed(false) |
84 , m_fontLoadShortLimitTimer(this, &FontResource::fontLoadShortLimitCallback) | 87 , m_fontLoadShortLimitTimer(this, &FontResource::fontLoadShortLimitCallback) |
85 , m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) | 88 , m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) |
86 { | 89 { |
87 } | 90 } |
88 | 91 |
89 FontResource::~FontResource() | 92 FontResource::~FontResource() |
90 { | 93 { |
91 } | 94 } |
92 | 95 |
93 void FontResource::didScheduleLoad() | |
94 { | |
95 if (getStatus() == NotStarted) | |
96 setStatus(LoadStartScheduled); | |
97 } | |
98 | |
99 void FontResource::didUnscheduleLoad() | |
100 { | |
101 if (getStatus() == LoadStartScheduled) | |
102 setStatus(NotStarted); | |
103 } | |
104 | |
105 void FontResource::load(ResourceFetcher*) | |
106 { | |
107 // Don't load the file yet. Wait for an access before triggering the load. | |
108 if (!m_revalidatingRequest.isNull()) | |
109 setStatus(NotStarted); | |
110 } | |
111 | |
112 void FontResource::didAddClient(ResourceClient* c) | 96 void FontResource::didAddClient(ResourceClient* c) |
113 { | 97 { |
114 ASSERT(FontResourceClient::isExpectedType(c)); | 98 ASSERT(FontResourceClient::isExpectedType(c)); |
115 Resource::didAddClient(c); | 99 Resource::didAddClient(c); |
116 if (isLoaded()) | 100 if (isLoaded()) |
117 static_cast<FontResourceClient*>(c)->fontLoaded(this); | 101 static_cast<FontResourceClient*>(c)->fontLoaded(this); |
118 if (m_loadLimitState == ShortLimitExceeded || m_loadLimitState == LongLimitE xceeded) | 102 if (m_loadLimitState == ShortLimitExceeded || m_loadLimitState == LongLimitE xceeded) |
119 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); | 103 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); |
120 if (m_loadLimitState == LongLimitExceeded) | 104 if (m_loadLimitState == LongLimitExceeded) |
121 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); | 105 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); |
122 } | 106 } |
123 | 107 |
124 void FontResource::beginLoadIfNeeded(ResourceFetcher* dl) | 108 void FontResource::startLoadLimitTimersIfNeeded() |
125 { | 109 { |
126 if (stillNeedsLoad()) { | 110 ASSERT(!stillNeedsLoad()); |
127 Resource::load(dl); | 111 if (isLoaded() || m_fontLoadLongLimitTimer.isActive()) |
128 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_ FROM_HERE); | 112 return; |
129 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FR OM_HERE); | 113 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, BLINK_FROM _HERE); |
130 | 114 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, BLINK_FROM_H ERE); |
131 ResourceClientWalker<FontResourceClient> walker(m_clients); | |
132 while (FontResourceClient* client = walker.next()) | |
133 client->didStartFontLoad(this); | |
134 } | |
135 } | 115 } |
136 | 116 |
137 bool FontResource::ensureCustomFontData() | 117 bool FontResource::ensureCustomFontData() |
138 { | 118 { |
139 if (!m_fontData && !errorOccurred() && !isLoading()) { | 119 if (!m_fontData && !errorOccurred() && !isLoading()) { |
140 if (m_data) | 120 if (m_data) |
141 m_fontData = FontCustomPlatformData::create(m_data.get(), m_otsParsi ngMessage); | 121 m_fontData = FontCustomPlatformData::create(m_data.get(), m_otsParsi ngMessage); |
142 | 122 |
143 if (m_fontData) { | 123 if (m_fontData) { |
144 recordPackageFormatHistogram(packageFormatOf(m_data.get())); | 124 recordPackageFormatHistogram(packageFormatOf(m_data.get())); |
(...skipping 13 matching lines...) Expand all Loading... | |
158 | 138 |
159 bool FontResource::isSafeToUnlock() const | 139 bool FontResource::isSafeToUnlock() const |
160 { | 140 { |
161 return m_data->hasOneRef(); | 141 return m_data->hasOneRef(); |
162 } | 142 } |
163 | 143 |
164 void FontResource::fontLoadShortLimitCallback(Timer<FontResource>*) | 144 void FontResource::fontLoadShortLimitCallback(Timer<FontResource>*) |
165 { | 145 { |
166 if (!isLoading()) | 146 if (!isLoading()) |
167 return; | 147 return; |
168 ASSERT(m_loadLimitState == UnderLimit); | 148 ASSERT(m_loadLimitState == UnderLimit); |
Takashi Toyoshima
2016/04/11 11:51:54
On reviewing this change, I noticed this assertion
| |
169 m_loadLimitState = ShortLimitExceeded; | 149 m_loadLimitState = ShortLimitExceeded; |
170 ResourceClientWalker<FontResourceClient> walker(m_clients); | 150 ResourceClientWalker<FontResourceClient> walker(m_clients); |
171 while (FontResourceClient* client = walker.next()) | 151 while (FontResourceClient* client = walker.next()) |
172 client->fontLoadShortLimitExceeded(this); | 152 client->fontLoadShortLimitExceeded(this); |
173 } | 153 } |
174 | 154 |
175 void FontResource::fontLoadLongLimitCallback(Timer<FontResource>*) | 155 void FontResource::fontLoadLongLimitCallback(Timer<FontResource>*) |
176 { | 156 { |
177 if (!isLoading()) | 157 if (!isLoading()) |
178 return; | 158 return; |
(...skipping 13 matching lines...) Expand all Loading... | |
192 void FontResource::checkNotify() | 172 void FontResource::checkNotify() |
193 { | 173 { |
194 m_fontLoadShortLimitTimer.stop(); | 174 m_fontLoadShortLimitTimer.stop(); |
195 m_fontLoadLongLimitTimer.stop(); | 175 m_fontLoadLongLimitTimer.stop(); |
196 ResourceClientWalker<FontResourceClient> w(m_clients); | 176 ResourceClientWalker<FontResourceClient> w(m_clients); |
197 while (FontResourceClient* c = w.next()) | 177 while (FontResourceClient* c = w.next()) |
198 c->fontLoaded(this); | 178 c->fontLoaded(this); |
199 } | 179 } |
200 | 180 |
201 } // namespace blink | 181 } // namespace blink |
OLD | NEW |