OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef FontResource_h | 26 #ifndef FontResource_h |
27 #define FontResource_h | 27 #define FontResource_h |
28 | 28 |
| 29 #include "base/gtest_prod_util.h" |
29 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
30 #include "core/fetch/Resource.h" | 31 #include "core/fetch/Resource.h" |
31 #include "core/fetch/ResourceClient.h" | 32 #include "core/fetch/ResourceClient.h" |
32 #include "platform/Timer.h" | 33 #include "platform/Timer.h" |
33 #include "platform/fonts/FontOrientation.h" | 34 #include "platform/fonts/FontOrientation.h" |
34 #include "platform/heap/Handle.h" | 35 #include "platform/heap/Handle.h" |
35 #include <memory> | 36 #include <memory> |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
38 | 39 |
(...skipping 26 matching lines...) Expand all Loading... |
65 float size, | 66 float size, |
66 bool bold, | 67 bool bold, |
67 bool italic, | 68 bool italic, |
68 FontOrientation = FontOrientation::Horizontal); | 69 FontOrientation = FontOrientation::Horizontal); |
69 | 70 |
70 // Returns true if the loading priority of the remote font resource can be | 71 // Returns true if the loading priority of the remote font resource can be |
71 // lowered. The loading priority of the font can be lowered only if the | 72 // lowered. The loading priority of the font can be lowered only if the |
72 // font is not needed for painting the text. | 73 // font is not needed for painting the text. |
73 bool isLowPriorityLoadingAllowedForRemoteFont() const; | 74 bool isLowPriorityLoadingAllowedForRemoteFont() const; |
74 | 75 |
| 76 void willReloadAfterDiskCacheMiss() override; |
| 77 |
75 void onMemoryDump(WebMemoryDumpLevelOfDetail, | 78 void onMemoryDump(WebMemoryDumpLevelOfDetail, |
76 WebProcessMemoryDump*) const override; | 79 WebProcessMemoryDump*) const override; |
77 | 80 |
78 private: | 81 private: |
79 class FontResourceFactory : public ResourceFactory { | 82 class FontResourceFactory : public ResourceFactory { |
80 public: | 83 public: |
81 FontResourceFactory() : ResourceFactory(Resource::Font) {} | 84 FontResourceFactory() : ResourceFactory(Resource::Font) {} |
82 | 85 |
83 Resource* create(const ResourceRequest& request, | 86 Resource* create(const ResourceRequest& request, |
84 const ResourceLoaderOptions& options, | 87 const ResourceLoaderOptions& options, |
85 const String& charset) const override { | 88 const String& charset) const override { |
86 return new FontResource(request, options); | 89 return new FontResource(request, options); |
87 } | 90 } |
88 }; | 91 }; |
89 FontResource(const ResourceRequest&, const ResourceLoaderOptions&); | 92 FontResource(const ResourceRequest&, const ResourceLoaderOptions&); |
90 | 93 |
91 void checkNotify() override; | 94 void checkNotify() override; |
92 void fontLoadShortLimitCallback(TimerBase*); | 95 void fontLoadShortLimitCallback(TimerBase*); |
93 void fontLoadLongLimitCallback(TimerBase*); | 96 void fontLoadLongLimitCallback(TimerBase*); |
| 97 void notifyClientsShortLimitExceeded(); |
| 98 void notifyClientsLongLimitExceeded(); |
94 | 99 |
| 100 // This is used in UMA histograms, should not change order. |
95 enum LoadLimitState { | 101 enum LoadLimitState { |
96 LoadNotStarted, | 102 LoadNotStarted, |
97 UnderLimit, | 103 UnderLimit, |
98 ShortLimitExceeded, | 104 ShortLimitExceeded, |
99 LongLimitExceeded | 105 LongLimitExceeded, |
| 106 LoadLimitStateEnumMax |
100 }; | 107 }; |
101 | 108 |
102 std::unique_ptr<FontCustomPlatformData> m_fontData; | 109 std::unique_ptr<FontCustomPlatformData> m_fontData; |
103 String m_otsParsingMessage; | 110 String m_otsParsingMessage; |
104 LoadLimitState m_loadLimitState; | 111 LoadLimitState m_loadLimitState; |
105 bool m_corsFailed; | 112 bool m_corsFailed; |
106 Timer<FontResource> m_fontLoadShortLimitTimer; | 113 Timer<FontResource> m_fontLoadShortLimitTimer; |
107 Timer<FontResource> m_fontLoadLongLimitTimer; | 114 Timer<FontResource> m_fontLoadLongLimitTimer; |
108 | 115 |
109 friend class MemoryCache; | 116 friend class MemoryCache; |
| 117 FRIEND_TEST_ALL_PREFIXES(FontResourceTest, CacheAwareFontLoading); |
110 }; | 118 }; |
111 | 119 |
112 DEFINE_RESOURCE_TYPE_CASTS(Font); | 120 DEFINE_RESOURCE_TYPE_CASTS(Font); |
113 | 121 |
114 class FontResourceClient : public ResourceClient { | 122 class FontResourceClient : public ResourceClient { |
115 public: | 123 public: |
116 ~FontResourceClient() override {} | 124 ~FontResourceClient() override {} |
117 static bool isExpectedType(ResourceClient* client) { | 125 static bool isExpectedType(ResourceClient* client) { |
118 return client->getResourceClientType() == FontType; | 126 return client->getResourceClientType() == FontType; |
119 } | 127 } |
120 ResourceClientType getResourceClientType() const final { return FontType; } | 128 ResourceClientType getResourceClientType() const final { return FontType; } |
| 129 |
| 130 // If cache-aware loading is activated, both callbacks will be blocked until |
| 131 // disk cache miss. Calls to addClient() and removeClient() in both callbacks |
| 132 // are prohibited to prevent race issues regarding current loading state. |
121 virtual void fontLoadShortLimitExceeded(FontResource*) {} | 133 virtual void fontLoadShortLimitExceeded(FontResource*) {} |
122 virtual void fontLoadLongLimitExceeded(FontResource*) {} | 134 virtual void fontLoadLongLimitExceeded(FontResource*) {} |
123 | 135 |
124 // Returns true if loading priority of remote font resources can be lowered. | 136 // Returns true if loading priority of remote font resources can be lowered. |
125 virtual bool isLowPriorityLoadingAllowedForRemoteFont() const { | 137 virtual bool isLowPriorityLoadingAllowedForRemoteFont() const { |
126 // Only the RemoteFontFaceSources clients can prevent lowering of loading | 138 // Only the RemoteFontFaceSources clients can prevent lowering of loading |
127 // priority of the remote fonts. Set the default to true to prevent | 139 // priority of the remote fonts. Set the default to true to prevent |
128 // other clients from incorrectly returning false. | 140 // other clients from incorrectly returning false. |
129 return true; | 141 return true; |
130 } | 142 } |
131 }; | 143 }; |
132 | 144 |
133 } // namespace blink | 145 } // namespace blink |
134 | 146 |
135 #endif | 147 #endif |
OLD | NEW |