Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / RemoteFontFaceSource.h
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
3 // found in the LICENSE file.
4
5 #ifndef RemoteFontFaceSource_h
6 #define RemoteFontFaceSource_h
7
8 #include "core/css/CSSFontFaceSource.h"
9 #include "core/fetch/FontResource.h"
10 #include "core/fetch/ResourcePtr.h"
11
12 namespace blink {
13
14 class FontLoader;
15
16 class RemoteFontFaceSource : public CSSFontFaceSource, public FontResourceClient {
17 public:
18     explicit RemoteFontFaceSource(FontResource*, PassRefPtrWillBeRawPtr<FontLoader>);
19     virtual ~RemoteFontFaceSource();
20
21     virtual FontResource* resource() override { return m_font.get(); }
22     virtual bool isLoading() const override;
23     virtual bool isLoaded() const override;
24     virtual bool isValid() const override;
25
26     void beginLoadIfNeeded() override;
27     virtual bool ensureFontData();
28
29     virtual void didStartFontLoad(FontResource*) override;
30     virtual void fontLoaded(FontResource*) override;
31     virtual void fontLoadWaitLimitExceeded(FontResource*) override;
32
33     // For UMA reporting
34     virtual bool hadBlankText() override { return m_histograms.hadBlankText(); }
35     void paintRequested() { m_histograms.fallbackFontPainted(); }
36
37     virtual void trace(Visitor*) override;
38
39 protected:
40     virtual PassRefPtr<SimpleFontData> createFontData(const FontDescription&) override;
41     PassRefPtr<SimpleFontData> createLoadingFallbackFontData(const FontDescription&);
42     void pruneTable();
43
44 private:
45     class FontLoadHistograms {
46     public:
47         FontLoadHistograms() : m_loadStartTime(0), m_fallbackPaintTime(0) { }
48         void loadStarted();
49         void fallbackFontPainted();
50         void recordRemoteFont(const FontResource*);
51         void recordFallbackTime(const FontResource*);
52         bool hadBlankText() { return m_fallbackPaintTime; }
53     private:
54         const char* histogramName(const FontResource*);
55         double m_loadStartTime;
56         double m_fallbackPaintTime;
57     };
58
59     ResourcePtr<FontResource> m_font;
60     RefPtrWillBeMember<FontLoader> m_fontLoader;
61     FontLoadHistograms m_histograms;
62 };
63
64 } // namespace blink
65
66 #endif