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

Unified 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: Add DecompressingInForegroundTab 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/text/CompressibleString.h
diff --git a/third_party/WebKit/Source/platform/text/CompressibleString.h b/third_party/WebKit/Source/platform/text/CompressibleString.h
new file mode 100644
index 0000000000000000000000000000000000000000..15948120ec962a2c9ed35b44e0003b8a946df4a5
--- /dev/null
+++ b/third_party/WebKit/Source/platform/text/CompressibleString.h
@@ -0,0 +1,86 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CompressibleString_h
+#define CompressibleString_h
+
+#include "platform/PlatformExport.h"
+#include "wtf/text/Unicode.h"
+#include "wtf/text/WTFString.h"
+
+namespace blink {
+
+// TODO(hajimehoshi): Now these classes are in platform/text to use UMA. Move
+// them to wtf/text.
+
+// This method must be called only by Platform::initialize.
+void initializeCompressibleStringTable();
+
+class PLATFORM_EXPORT CompressibleStringImpl final : public RefCounted<CompressibleStringImpl> {
+ WTF_MAKE_NONCOPYABLE(CompressibleStringImpl);
+public:
+ static void compressAll();
+ static void setPageBackground(bool);
+
+ CompressibleStringImpl();
+ CompressibleStringImpl(PassRefPtr<StringImpl>);
haraken 2016/01/19 07:43:36 Add explicit.
hajimehoshi 2016/01/19 10:19:21 Done.
+ ~CompressibleStringImpl();
+
+ bool isEmpty() const { return originalLength() == 0; }
+
+ bool isCompressed() const { return m_isCompressed; }
+ unsigned originalLength() const { return m_string.length(); }
+ bool is8Bit() const { return m_string.is8Bit(); }
+
+ unsigned originalContentSizeInBytes() const;
+ unsigned currentSizeInBytes() const;
+
+ const String& toString();
+ const LChar* characters8();
+ const UChar* characters16();
+
+ void compressString();
+ void decompressString();
+
+private:
+ static bool s_isPageBackground;
+
+ String m_string;
+ bool m_isCompressed;
+};
+
+class PLATFORM_EXPORT CompressibleString final {
+public:
+ CompressibleString();
+ CompressibleString(const CompressibleString&);
+ explicit CompressibleString(PassRefPtr<StringImpl>);
+
+ bool isNull() const { return !m_impl; }
+ bool isEmpty() const { return isNull() || m_impl->isEmpty(); }
+ unsigned length() const { return m_impl ? m_impl->originalLength() : 0; }
+
+ unsigned currentSizeInBytes() const { return m_impl ? m_impl->currentSizeInBytes() : 0; }
+
+ bool isCompressed() const { return m_impl ? m_impl->isCompressed() : false; }
+ bool is8Bit() const { return m_impl ? m_impl->is8Bit() : false; }
+
+ const String& toString() const { return m_impl ? m_impl->toString() : emptyString(); }
+ const LChar* characters8() const { return m_impl ? m_impl->characters8() : nullptr; }
+ const UChar* characters16() const { return m_impl ? m_impl->characters16() : nullptr; }
+
+ PassRefPtr<CompressibleStringImpl> impl() const { return m_impl; }
haraken 2016/01/19 07:43:35 This is a getter for impl, so it should return Com
hajimehoshi 2016/01/19 10:19:21 Done.
+
+private:
+ void compressString() const;
+ void decompressString() const;
+
+ mutable RefPtr<CompressibleStringImpl> m_impl;
+};
+
+} // namespace blink
+
+using blink::CompressibleString;
+using blink::CompressibleStringImpl;
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698