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

Side by Side Diff: third_party/WebKit/Source/wtf/FunctionalTest.cpp

Issue 2250373002: Readd base::UnwrapTraits to support rvalue-reference wrappers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20_oneshot
Patch Set: rebase Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/wtf/Functional.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 : m_value(value) 71 : m_value(value)
72 { 72 {
73 } 73 }
74 74
75 UnwrappedClass unwrap() const { return UnwrappedClass(m_value); } 75 UnwrappedClass unwrap() const { return UnwrappedClass(m_value); }
76 76
77 private: 77 private:
78 int m_value; 78 int m_value;
79 }; 79 };
80 80
81 UnwrappedClass Unwrap(const WrappedClass& wrapped)
82 {
83 return wrapped.unwrap();
84 }
85
86 template<> struct ParamStorageTraits<ClassToBeWrapped> { 81 template<> struct ParamStorageTraits<ClassToBeWrapped> {
87 using StorageType = WrappedClass; 82 using StorageType = WrappedClass;
88 }; 83 };
89 84
90 class HasWeakPtrSupport { 85 class HasWeakPtrSupport {
91 public: 86 public:
92 HasWeakPtrSupport() : m_weakPtrFactory(this) {} 87 HasWeakPtrSupport() : m_weakPtrFactory(this) {}
93 88
94 WTF::WeakPtr<HasWeakPtrSupport> createWeakPtr() { 89 WTF::WeakPtr<HasWeakPtrSupport> createWeakPtr() {
95 return m_weakPtrFactory.createWeakPtr(); 90 return m_weakPtrFactory.createWeakPtr();
96 } 91 }
97 92
98 void revokeAll() 93 void revokeAll()
99 { 94 {
100 m_weakPtrFactory.revokeAll(); 95 m_weakPtrFactory.revokeAll();
101 } 96 }
102 97
103 void increment(int* counter) 98 void increment(int* counter)
104 { 99 {
105 ++*counter; 100 ++*counter;
106 } 101 }
107 102
108 private: 103 private:
109 WTF::WeakPtrFactory<HasWeakPtrSupport> m_weakPtrFactory; 104 WTF::WeakPtrFactory<HasWeakPtrSupport> m_weakPtrFactory;
110 }; 105 };
111 106
107 } // namespace WTF
108
109 namespace base {
110
111 template <>
112 struct BindUnwrapTraits<WTF::WrappedClass> {
113 static WTF::UnwrappedClass Unwrap(const WTF::WrappedClass& wrapped)
114 {
115 return wrapped.unwrap();
116 }
117 };
118
119 } // namespace base
120
121 namespace WTF {
112 namespace { 122 namespace {
113 123
114 int returnFortyTwo() 124 int returnFortyTwo()
115 { 125 {
116 return 42; 126 return 42;
117 } 127 }
118 128
119 TEST(FunctionalTest, Basic) 129 TEST(FunctionalTest, Basic)
120 { 130 {
121 std::unique_ptr<Function<int()>> returnFortyTwoFunction = bind(returnFortyTw o); 131 std::unique_ptr<Function<int()>> returnFortyTwoFunction = bind(returnFortyTw o);
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 EXPECT_EQ(1, counter); 592 EXPECT_EQ(1, counter);
583 593
584 obj.revokeAll(); 594 obj.revokeAll();
585 (*bound)(); 595 (*bound)();
586 EXPECT_EQ(1, counter); 596 EXPECT_EQ(1, counter);
587 } 597 }
588 598
589 } // anonymous namespace 599 } // anonymous namespace
590 600
591 } // namespace WTF 601 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/Functional.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698