Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: third_party/WebKit/Source/platform/text/CompressibleString.h

Issue 1583263002: Experimental CompressibleString UMA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adopt lazy-initializing way Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 CompressibleString_h
6 #define CompressibleString_h
7
8 #include "platform/PlatformExport.h"
9 #include "wtf/text/Unicode.h"
10 #include "wtf/text/WTFString.h"
11
12 namespace blink {
13
14 // TODO(hajimehoshi): Now these classes are in platform/text to use UMA. Move
15 // them to wtf/text.
16
17 class PLATFORM_EXPORT CompressibleStringImpl final : public RefCounted<Compressi bleStringImpl> {
18 WTF_MAKE_NONCOPYABLE(CompressibleStringImpl);
19 public:
20 static void compressAll();
21 static void setPageBackground(bool);
22
23 CompressibleStringImpl()
24 : m_string()
25 , m_isCompressed(false)
26 {
27 }
28
29 explicit CompressibleStringImpl(PassRefPtr<StringImpl>);
30 ~CompressibleStringImpl();
31
32 bool isEmpty() const { return originalLength() == 0; }
33
34 bool isCompressed() const { return m_isCompressed; }
35 unsigned originalLength() const { return m_string.length(); }
36 bool is8Bit() const { return m_string.is8Bit(); }
37
38 unsigned originalContentSizeInBytes() const
39 {
40 if (is8Bit())
41 return originalLength() * sizeof(LChar);
42 return originalLength() * sizeof(UChar);
43 }
44
45 // TODO(hajimehoshi): Update this once we implement compression.
46 unsigned currentSizeInBytes() const
47 {
48 return originalContentSizeInBytes();
49 }
50
51 const String& toString()
52 {
53 if (UNLIKELY(isCompressed()))
54 decompressString();
55 return m_string;
56 }
57
58 const LChar* characters8()
59 {
60 return toString().characters8();
61 }
62
63 const UChar* characters16()
64 {
65 return toString().characters16();
66 }
67
68 void compressString();
69 void decompressString();
70
71 private:
72 static bool s_isPageBackground;
73
74 String m_string;
75 bool m_isCompressed;
76 };
77
78 class PLATFORM_EXPORT CompressibleString final {
79 public:
80 CompressibleString()
81 : m_impl(nullptr)
82 {
83 }
84
85 CompressibleString(const CompressibleString& rhs)
86 : m_impl(rhs.m_impl)
87 {
88 }
89
90 explicit CompressibleString(PassRefPtr<StringImpl> impl)
91 : m_impl(impl ? adoptRef(new CompressibleStringImpl(impl)) : nullptr)
92 {
93 }
94
95 bool isNull() const { return !m_impl; }
96 bool isEmpty() const { return isNull() || m_impl->isEmpty(); }
97 unsigned length() const { return m_impl ? m_impl->originalLength() : 0; }
98
99 unsigned currentSizeInBytes() const { return m_impl ? m_impl->currentSizeInB ytes() : 0; }
100
101 bool isCompressed() const { return m_impl ? m_impl->isCompressed() : false; }
102 bool is8Bit() const { return m_impl ? m_impl->is8Bit() : false; }
103
104 const String& toString() const { return m_impl ? m_impl->toString() : emptyS tring(); }
105 const LChar* characters8() const { return m_impl ? m_impl->characters8() : n ullptr; }
106 const UChar* characters16() const { return m_impl ? m_impl->characters16() : nullptr; }
107
108 CompressibleStringImpl* impl() const { return m_impl.get(); }
109
110 private:
111 void compressString() const { m_impl->compressString(); }
112 void decompressString() const { m_impl->decompressString(); }
113
114 mutable RefPtr<CompressibleStringImpl> m_impl;
115 };
116
117 } // namespace blink
118
119 using blink::CompressibleString;
120 using blink::CompressibleStringImpl;
121
122 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/blink_platform.gypi ('k') | third_party/WebKit/Source/platform/text/CompressibleString.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698