Chromium Code Reviews| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 WebURLRequest::RequestContextFont); | 78 WebURLRequest::RequestContextFont); |
| 79 return toFontResource( | 79 return toFontResource( |
| 80 fetcher->requestResource(request, FontResourceFactory())); | 80 fetcher->requestResource(request, FontResourceFactory())); |
| 81 } | 81 } |
| 82 | 82 |
| 83 FontResource::FontResource(const ResourceRequest& resourceRequest, | 83 FontResource::FontResource(const ResourceRequest& resourceRequest, |
| 84 const ResourceLoaderOptions& options) | 84 const ResourceLoaderOptions& options) |
| 85 : Resource(resourceRequest, Font, options), | 85 : Resource(resourceRequest, Font, options), |
| 86 m_loadLimitState(UnderLimit), | 86 m_loadLimitState(UnderLimit), |
| 87 m_corsFailed(false), | 87 m_corsFailed(false), |
| 88 m_isLoadLimitTimersStarted(false), | |
| 88 m_fontLoadShortLimitTimer(this, | 89 m_fontLoadShortLimitTimer(this, |
| 89 &FontResource::fontLoadShortLimitCallback), | 90 &FontResource::fontLoadShortLimitCallback), |
| 90 m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) { | 91 m_fontLoadLongLimitTimer(this, &FontResource::fontLoadLongLimitCallback) { |
| 91 } | 92 } |
| 92 | 93 |
| 93 FontResource::~FontResource() {} | 94 FontResource::~FontResource() {} |
| 94 | 95 |
| 95 void FontResource::didAddClient(ResourceClient* c) { | 96 void FontResource::didAddClient(ResourceClient* c) { |
| 96 DCHECK(FontResourceClient::isExpectedType(c)); | 97 DCHECK(FontResourceClient::isExpectedType(c)); |
| 97 Resource::didAddClient(c); | 98 Resource::didAddClient(c); |
| 98 if (m_loadLimitState == ShortLimitExceeded || | 99 if (m_loadLimitState == ShortLimitExceeded || |
| 99 m_loadLimitState == LongLimitExceeded) | 100 m_loadLimitState == LongLimitExceeded) |
| 100 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); | 101 static_cast<FontResourceClient*>(c)->fontLoadShortLimitExceeded(this); |
| 101 if (m_loadLimitState == LongLimitExceeded) | 102 if (m_loadLimitState == LongLimitExceeded) |
| 102 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); | 103 static_cast<FontResourceClient*>(c)->fontLoadLongLimitExceeded(this); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void FontResource::setRevalidatingRequest(const ResourceRequest& request) { | 106 void FontResource::setRevalidatingRequest(const ResourceRequest& request) { |
| 106 // Reload will use the same object, and needs to reset |m_loadLimitState| | 107 // Reload will use the same object, and needs to reset |m_loadLimitState| |
| 107 // before any didAddClient() is called again. | 108 // before any didAddClient() is called again. |
| 108 m_loadLimitState = UnderLimit; | 109 m_loadLimitState = UnderLimit; |
| 109 Resource::setRevalidatingRequest(request); | 110 Resource::setRevalidatingRequest(request); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void FontResource::startLoadLimitTimersIfNeeded() { | 113 void FontResource::startLoadLimitTimers() { |
| 113 DCHECK(!stillNeedsLoad()); | 114 DCHECK(!m_isLoadLimitTimersStarted); |
|
Kunihiko Sakamoto
2016/10/13 05:55:19
Can you add DCHECK(isLoading()) here?
Shao-Chuan Lee
2016/10/13 06:12:58
Done.
| |
| 114 if (isLoaded() || m_fontLoadLongLimitTimer.isActive()) | |
| 115 return; | |
| 116 DCHECK_EQ(m_loadLimitState, UnderLimit); | 115 DCHECK_EQ(m_loadLimitState, UnderLimit); |
| 117 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, | 116 m_fontLoadShortLimitTimer.startOneShot(fontLoadWaitShortLimitSec, |
| 118 BLINK_FROM_HERE); | 117 BLINK_FROM_HERE); |
| 119 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, | 118 m_fontLoadLongLimitTimer.startOneShot(fontLoadWaitLongLimitSec, |
| 120 BLINK_FROM_HERE); | 119 BLINK_FROM_HERE); |
| 120 m_isLoadLimitTimersStarted = true; | |
| 121 } | 121 } |
| 122 | 122 |
| 123 bool FontResource::ensureCustomFontData() { | 123 bool FontResource::ensureCustomFontData() { |
| 124 if (!m_fontData && !errorOccurred() && !isLoading()) { | 124 if (!m_fontData && !errorOccurred() && !isLoading()) { |
| 125 if (data()) | 125 if (data()) |
| 126 m_fontData = FontCustomPlatformData::create(data(), m_otsParsingMessage); | 126 m_fontData = FontCustomPlatformData::create(data(), m_otsParsingMessage); |
| 127 | 127 |
| 128 if (m_fontData) { | 128 if (m_fontData) { |
| 129 recordPackageFormatHistogram(packageFormatOf(data())); | 129 recordPackageFormatHistogram(packageFormatOf(data())); |
| 130 } else { | 130 } else { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 } | 165 } |
| 166 | 166 |
| 167 void FontResource::allClientsAndObserversRemoved() { | 167 void FontResource::allClientsAndObserversRemoved() { |
| 168 m_fontData.reset(); | 168 m_fontData.reset(); |
| 169 Resource::allClientsAndObserversRemoved(); | 169 Resource::allClientsAndObserversRemoved(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void FontResource::checkNotify() { | 172 void FontResource::checkNotify() { |
| 173 m_fontLoadShortLimitTimer.stop(); | 173 m_fontLoadShortLimitTimer.stop(); |
| 174 m_fontLoadLongLimitTimer.stop(); | 174 m_fontLoadLongLimitTimer.stop(); |
| 175 m_isLoadLimitTimersStarted = false; | |
|
Kunihiko Sakamoto
2016/10/13 05:55:19
Does this mean startLoadLimitTimers() can be calle
Shao-Chuan Lee
2016/10/13 06:12:58
Yes, in revalidation cases.
Kunihiko Sakamoto
2016/10/13 06:36:18
Hm, then we have to reset m_loadLimitState too?
Ca
Shao-Chuan Lee
2016/10/13 07:14:06
Adding new LoadLimitState to indicate that timers
| |
| 175 | 176 |
| 176 Resource::checkNotify(); | 177 Resource::checkNotify(); |
| 177 } | 178 } |
| 178 | 179 |
| 179 } // namespace blink | 180 } // namespace blink |
| OLD | NEW |