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