| 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 21 matching lines...) Expand all Loading... |
| 32 #include "platform/Histogram.h" | 32 #include "platform/Histogram.h" |
| 33 #include "platform/SharedBuffer.h" | 33 #include "platform/SharedBuffer.h" |
| 34 #include "platform/fonts/FontCustomPlatformData.h" | 34 #include "platform/fonts/FontCustomPlatformData.h" |
| 35 #include "platform/fonts/FontPlatformData.h" | 35 #include "platform/fonts/FontPlatformData.h" |
| 36 #include "wtf/CurrentTime.h" | 36 #include "wtf/CurrentTime.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 // Durations of font-display periods. | 40 // Durations of font-display periods. |
| 41 // https://tabatkins.github.io/specs/css-font-display/#font-display-desc | 41 // https://tabatkins.github.io/specs/css-font-display/#font-display-desc |
| 42 // TODO(shaochuan): Revisit short limit value once cache-aware font display is |
| 43 // launched. crbug.com/570205 |
| 42 static const double fontLoadWaitShortLimitSec = 0.1; | 44 static const double fontLoadWaitShortLimitSec = 0.1; |
| 43 static const double fontLoadWaitLongLimitSec = 3.0; | 45 static const double fontLoadWaitLongLimitSec = 3.0; |
| 44 | 46 |
| 45 enum FontPackageFormat { | 47 enum FontPackageFormat { |
| 46 PackageFormatUnknown, | 48 PackageFormatUnknown, |
| 47 PackageFormatSFNT, | 49 PackageFormatSFNT, |
| 48 PackageFormatWOFF, | 50 PackageFormatWOFF, |
| 49 PackageFormatWOFF2, | 51 PackageFormatWOFF2, |
| 50 PackageFormatSVG, | 52 PackageFormatSVG, |
| 51 PackageFormatEnumMax | 53 PackageFormatEnumMax |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 138 |
| 137 FontPlatformData FontResource::platformDataFromCustomData( | 139 FontPlatformData FontResource::platformDataFromCustomData( |
| 138 float size, | 140 float size, |
| 139 bool bold, | 141 bool bold, |
| 140 bool italic, | 142 bool italic, |
| 141 FontOrientation orientation) { | 143 FontOrientation orientation) { |
| 142 DCHECK(m_fontData); | 144 DCHECK(m_fontData); |
| 143 return m_fontData->fontPlatformData(size, bold, italic, orientation); | 145 return m_fontData->fontPlatformData(size, bold, italic, orientation); |
| 144 } | 146 } |
| 145 | 147 |
| 148 void FontResource::willReloadAfterDiskCacheMiss() { |
| 149 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this); |
| 150 |
| 151 ResourceClientWalker<FontResourceClient> walker(clients()); |
| 152 while (FontResourceClient* client = walker.next()) |
| 153 client->willReloadAfterDiskCacheMiss(this); |
| 154 |
| 155 DCHECK(isLoading()); |
| 156 DCHECK(!resourceRequest().isCacheAwareLoadingActivated()); |
| 157 // Both timers should have been started by calling startLoadLimitTimers() from |
| 158 // RemoteFontFaceSource::beginLoadIfNeeded(). |
| 159 if (!m_fontLoadShortLimitTimer.isActive()) |
| 160 fontLoadShortLimitCallback(nullptr); |
| 161 if (!m_fontLoadLongLimitTimer.isActive()) |
| 162 fontLoadLongLimitCallback(nullptr); |
| 163 } |
| 164 |
| 146 void FontResource::fontLoadShortLimitCallback(TimerBase*) { | 165 void FontResource::fontLoadShortLimitCallback(TimerBase*) { |
| 147 if (!isLoading()) | 166 if (!isLoading()) |
| 148 return; | 167 return; |
| 168 if (resourceRequest().isCacheAwareLoadingActivated()) |
| 169 return; |
| 149 DCHECK_EQ(m_loadLimitState, UnderLimit); | 170 DCHECK_EQ(m_loadLimitState, UnderLimit); |
| 150 m_loadLimitState = ShortLimitExceeded; | 171 m_loadLimitState = ShortLimitExceeded; |
| 151 ResourceClientWalker<FontResourceClient> walker(clients()); | 172 ResourceClientWalker<FontResourceClient> walker(clients()); |
| 152 while (FontResourceClient* client = walker.next()) | 173 while (FontResourceClient* client = walker.next()) |
| 153 client->fontLoadShortLimitExceeded(this); | 174 client->fontLoadShortLimitExceeded(this); |
| 154 } | 175 } |
| 155 | 176 |
| 156 void FontResource::fontLoadLongLimitCallback(TimerBase*) { | 177 void FontResource::fontLoadLongLimitCallback(TimerBase*) { |
| 157 if (!isLoading()) | 178 if (!isLoading()) |
| 158 return; | 179 return; |
| 180 if (resourceRequest().isCacheAwareLoadingActivated()) |
| 181 return; |
| 159 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); | 182 DCHECK_EQ(m_loadLimitState, ShortLimitExceeded); |
| 160 m_loadLimitState = LongLimitExceeded; | 183 m_loadLimitState = LongLimitExceeded; |
| 161 ResourceClientWalker<FontResourceClient> walker(clients()); | 184 ResourceClientWalker<FontResourceClient> walker(clients()); |
| 162 while (FontResourceClient* client = walker.next()) | 185 while (FontResourceClient* client = walker.next()) |
| 163 client->fontLoadLongLimitExceeded(this); | 186 client->fontLoadLongLimitExceeded(this); |
| 164 } | 187 } |
| 165 | 188 |
| 166 void FontResource::allClientsAndObserversRemoved() { | 189 void FontResource::allClientsAndObserversRemoved() { |
| 167 m_fontData.reset(); | 190 m_fontData.reset(); |
| 168 Resource::allClientsAndObserversRemoved(); | 191 Resource::allClientsAndObserversRemoved(); |
| 169 } | 192 } |
| 170 | 193 |
| 171 void FontResource::checkNotify() { | 194 void FontResource::checkNotify() { |
| 172 m_fontLoadShortLimitTimer.stop(); | 195 m_fontLoadShortLimitTimer.stop(); |
| 173 m_fontLoadLongLimitTimer.stop(); | 196 m_fontLoadLongLimitTimer.stop(); |
| 174 | 197 |
| 175 Resource::checkNotify(); | 198 Resource::checkNotify(); |
| 176 } | 199 } |
| 177 | 200 |
| 178 } // namespace blink | 201 } // namespace blink |
| OLD | NEW |