| OLD | NEW |
| 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 #ifndef RemoteFontFaceSource_h | 5 #ifndef RemoteFontFaceSource_h |
| 6 #define RemoteFontFaceSource_h | 6 #define RemoteFontFaceSource_h |
| 7 | 7 |
| 8 #include "core/css/CSSFontFaceSource.h" | 8 #include "core/css/CSSFontFaceSource.h" |
| 9 #include "core/fetch/FontResource.h" | 9 #include "core/fetch/FontResource.h" |
| 10 #include "core/fetch/ResourcePtr.h" | 10 #include "core/fetch/ResourcePtr.h" |
| 11 #include "wtf/Allocator.h" | 11 #include "wtf/Allocator.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 class FontLoader; | 15 class FontLoader; |
| 16 | 16 |
| 17 enum FontDisplay { |
| 18 FontDisplayAuto, |
| 19 FontDisplayBlock, |
| 20 FontDisplaySwap, |
| 21 FontDisplayFallback, |
| 22 FontDisplayOptional |
| 23 }; |
| 24 |
| 17 class RemoteFontFaceSource final : public CSSFontFaceSource, public FontResource
Client { | 25 class RemoteFontFaceSource final : public CSSFontFaceSource, public FontResource
Client { |
| 18 public: | 26 public: |
| 19 explicit RemoteFontFaceSource(FontResource*, PassRefPtrWillBeRawPtr<FontLoad
er>); | 27 explicit RemoteFontFaceSource(FontResource*, PassRefPtrWillBeRawPtr<FontLoad
er>, FontDisplay); |
| 20 ~RemoteFontFaceSource() override; | 28 ~RemoteFontFaceSource() override; |
| 21 | 29 |
| 22 FontResource* resource() override { return m_font.get(); } | 30 FontResource* resource() override { return m_font.get(); } |
| 23 bool isLoading() const override; | 31 bool isLoading() const override; |
| 24 bool isLoaded() const override; | 32 bool isLoaded() const override; |
| 25 bool isValid() const override; | 33 bool isValid() const override; |
| 26 | 34 |
| 27 void beginLoadIfNeeded() override; | 35 void beginLoadIfNeeded() override; |
| 28 | 36 |
| 29 void didStartFontLoad(FontResource*) override; | 37 void didStartFontLoad(FontResource*) override; |
| 30 void fontLoaded(FontResource*) override; | 38 void fontLoaded(FontResource*) override; |
| 31 void fontLoadWaitLimitExceeded(FontResource*) override; | 39 void fontLoadShortLimitExceeded(FontResource*) override; |
| 40 void fontLoadLongLimitExceeded(FontResource*) override; |
| 32 | 41 |
| 33 // For UMA reporting | 42 // For UMA reporting |
| 34 bool hadBlankText() override { return m_histograms.hadBlankText(); } | 43 bool hadBlankText() override { return m_histograms.hadBlankText(); } |
| 35 void paintRequested() { m_histograms.fallbackFontPainted(); } | 44 void paintRequested() { m_histograms.fallbackFontPainted(); } |
| 36 | 45 |
| 37 DECLARE_VIRTUAL_TRACE(); | 46 DECLARE_VIRTUAL_TRACE(); |
| 38 | 47 |
| 39 protected: | 48 protected: |
| 40 PassRefPtr<SimpleFontData> createFontData(const FontDescription&) override; | 49 PassRefPtr<SimpleFontData> createFontData(const FontDescription&) override; |
| 41 PassRefPtr<SimpleFontData> createLoadingFallbackFontData(const FontDescripti
on&); | 50 PassRefPtr<SimpleFontData> createLoadingFallbackFontData(const FontDescripti
on&); |
| 42 void pruneTable(); | 51 void pruneTable(); |
| 43 | 52 |
| 44 private: | 53 private: |
| 54 enum DisplayPeriod { BlockPeriod, SwapPeriod, FailurePeriod }; |
| 55 |
| 45 class FontLoadHistograms { | 56 class FontLoadHistograms { |
| 46 DISALLOW_ALLOCATION(); | 57 DISALLOW_ALLOCATION(); |
| 47 public: | 58 public: |
| 48 FontLoadHistograms() : m_loadStartTime(0), m_fallbackPaintTime(0) { } | 59 FontLoadHistograms() : m_loadStartTime(0), m_fallbackPaintTime(0) { } |
| 49 void loadStarted(); | 60 void loadStarted(); |
| 50 void fallbackFontPainted(); | 61 void fallbackFontPainted(); |
| 51 void recordRemoteFont(const FontResource*); | 62 void recordRemoteFont(const FontResource*); |
| 52 void recordFallbackTime(const FontResource*); | 63 void recordFallbackTime(const FontResource*); |
| 53 bool hadBlankText() { return m_fallbackPaintTime; } | 64 bool hadBlankText() { return m_fallbackPaintTime; } |
| 54 private: | 65 private: |
| 55 const char* histogramName(const FontResource*); | 66 const char* histogramName(const FontResource*); |
| 56 double m_loadStartTime; | 67 double m_loadStartTime; |
| 57 double m_fallbackPaintTime; | 68 double m_fallbackPaintTime; |
| 58 }; | 69 }; |
| 59 | 70 |
| 71 void switchToSwapPeriod(); |
| 72 void switchToFailurePeriod(); |
| 73 |
| 60 ResourcePtr<FontResource> m_font; | 74 ResourcePtr<FontResource> m_font; |
| 61 RefPtrWillBeMember<FontLoader> m_fontLoader; | 75 RefPtrWillBeMember<FontLoader> m_fontLoader; |
| 76 const FontDisplay m_display; |
| 77 DisplayPeriod m_period; |
| 62 FontLoadHistograms m_histograms; | 78 FontLoadHistograms m_histograms; |
| 63 }; | 79 }; |
| 64 | 80 |
| 65 } // namespace blink | 81 } // namespace blink |
| 66 | 82 |
| 67 #endif | 83 #endif |
| OLD | NEW |