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

Unified Diff: third_party/WebKit/Source/wtf/CrossThreadCopier.h

Issue 2125003002: Move CrossThreadCopier from platform/ to wtf/ Base URL: https://chromium.googlesource.com/chromium/src.git@TRV_RemoveTupleInBind
Patch Set: Rebase Created 4 years, 5 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/wtf/CrossThreadCopier.h
diff --git a/third_party/WebKit/Source/core/dom/custom/V0CustomElementDescriptorHash.h b/third_party/WebKit/Source/wtf/CrossThreadCopier.h
similarity index 54%
copy from third_party/WebKit/Source/core/dom/custom/V0CustomElementDescriptorHash.h
copy to third_party/WebKit/Source/wtf/CrossThreadCopier.h
index 2a0d2f5a37e6967bdc3fc49f02bca4769fe9d67b..f921890f59d866850cad3f186141b15a5ec5f28c 100644
--- a/third_party/WebKit/Source/core/dom/custom/V0CustomElementDescriptorHash.h
+++ b/third_party/WebKit/Source/wtf/CrossThreadCopier.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
+ * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -28,42 +28,55 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef V0CustomElementDescriptorHash_h
-#define V0CustomElementDescriptorHash_h
+#ifndef CrossThreadCopier_h
+#define CrossThreadCopier_h
-#include "core/dom/custom/V0CustomElementDescriptor.h"
#include "wtf/Allocator.h"
-#include "wtf/HashFunctions.h"
-#include "wtf/HashTraits.h"
-#include "wtf/text/AtomicStringHash.h"
+#include <memory>
+#include <type_traits>
-namespace blink {
+namespace WTF {
-struct V0CustomElementDescriptorHash {
- STATIC_ONLY(V0CustomElementDescriptorHash);
- static unsigned hash(const V0CustomElementDescriptor& descriptor)
+template <typename T>
+struct CrossThreadCopierPassThrough {
+ STATIC_ONLY(CrossThreadCopierPassThrough);
+ typedef T Type;
+ static Type copy(const T& parameter)
{
- return WTF::hashInts(AtomicStringHash::hash(descriptor.type()), WTF::hashInts(AtomicStringHash::hash(descriptor.namespaceURI()), AtomicStringHash::hash(descriptor.localName())));
+ return parameter;
}
+};
- static bool equal(const V0CustomElementDescriptor& a, const V0CustomElementDescriptor& b)
- {
- return a == b;
- }
+template <typename T, bool isArithmeticOrEnum>
+struct CrossThreadCopierBase;
- static const bool safeToCompareToEmptyOrDeleted = true;
+// Arithmetic values (integers or floats) and enums can be safely copied.
+template <typename T>
+struct CrossThreadCopierBase<T, true> : public CrossThreadCopierPassThrough<T> {
+ STATIC_ONLY(CrossThreadCopierBase);
};
-} // namespace blink
+template <typename T>
+struct CrossThreadCopier : public CrossThreadCopierBase<T, std::is_arithmetic<T>::value || std::is_enum<T>::value> {
+ STATIC_ONLY(CrossThreadCopier);
+};
-namespace WTF {
+// nullptr_t can be passed through without any changes.
+template <>
+struct CrossThreadCopier<std::nullptr_t> : public CrossThreadCopierPassThrough<std::nullptr_t> {
+ STATIC_ONLY(CrossThreadCopier);
+};
-template<>
-struct HashTraits<blink::V0CustomElementDescriptor> : SimpleClassHashTraits<blink::V0CustomElementDescriptor> {
- STATIC_ONLY(HashTraits);
- static const bool emptyValueIsZero = HashTraits<AtomicString>::emptyValueIsZero;
+template <typename T, typename Deleter>
+struct CrossThreadCopier<std::unique_ptr<T, Deleter>> {
+ STATIC_ONLY(CrossThreadCopier);
+ using Type = std::unique_ptr<T, Deleter>;
+ static std::unique_ptr<T, Deleter> copy(std::unique_ptr<T, Deleter> pointer)
+ {
+ return pointer; // This is in fact a move.
+ }
};
} // namespace WTF
-#endif // V0CustomElementDescriptorHash
+#endif // CrossThreadCopier_h

Powered by Google App Engine
This is Rietveld 408576698