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

Side by Side Diff: third_party/WebKit/Source/platform/testing/TestingPlatformSupport.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/testing/TestingPlatformSupport.h" 31 #include "platform/testing/TestingPlatformSupport.h"
32 32
33 #include "wtf/PtrUtil.h"
34 #include <memory>
35
36 namespace blink { 33 namespace blink {
37 34
38 TestingPlatformSupport::TestingPlatformSupport() 35 TestingPlatformSupport::TestingPlatformSupport()
39 : TestingPlatformSupport(TestingPlatformSupport::Config()) 36 : TestingPlatformSupport(TestingPlatformSupport::Config())
40 { 37 {
41 } 38 }
42 39
43 TestingPlatformSupport::TestingPlatformSupport(const Config& config) 40 TestingPlatformSupport::TestingPlatformSupport(const Config& config)
44 : m_config(config) 41 : m_config(config)
45 , m_oldPlatform(Platform::current()) 42 , m_oldPlatform(Platform::current())
(...skipping 18 matching lines...) Expand all
64 } 61 }
65 62
66 WebThread* TestingPlatformSupport::currentThread() 63 WebThread* TestingPlatformSupport::currentThread()
67 { 64 {
68 return m_oldPlatform ? m_oldPlatform->currentThread() : nullptr; 65 return m_oldPlatform ? m_oldPlatform->currentThread() : nullptr;
69 } 66 }
70 67
71 class TestingPlatformMockWebTaskRunner : public WebTaskRunner { 68 class TestingPlatformMockWebTaskRunner : public WebTaskRunner {
72 WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebTaskRunner); 69 WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebTaskRunner);
73 public: 70 public:
74 explicit TestingPlatformMockWebTaskRunner(Deque<std::unique_ptr<WebTaskRunne r::Task>>* tasks) : m_tasks(tasks) { } 71 explicit TestingPlatformMockWebTaskRunner(Deque<OwnPtr<WebTaskRunner::Task>> * tasks) : m_tasks(tasks) { }
75 ~TestingPlatformMockWebTaskRunner() override { } 72 ~TestingPlatformMockWebTaskRunner() override { }
76 73
77 void postTask(const WebTraceLocation&, Task* task) override 74 void postTask(const WebTraceLocation&, Task* task) override
78 { 75 {
79 m_tasks->append(wrapUnique(task)); 76 m_tasks->append(adoptPtr(task));
80 } 77 }
81 78
82 void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) overrid e 79 void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) overrid e
83 { 80 {
84 ASSERT_NOT_REACHED(); 81 ASSERT_NOT_REACHED();
85 } 82 }
86 83
87 WebTaskRunner* clone() override 84 WebTaskRunner* clone() override
88 { 85 {
89 return new TestingPlatformMockWebTaskRunner(m_tasks); 86 return new TestingPlatformMockWebTaskRunner(m_tasks);
90 } 87 }
91 88
92 double virtualTimeSeconds() const override 89 double virtualTimeSeconds() const override
93 { 90 {
94 ASSERT_NOT_REACHED(); 91 ASSERT_NOT_REACHED();
95 return 0.0; 92 return 0.0;
96 } 93 }
97 94
98 double monotonicallyIncreasingVirtualTimeSeconds() const override 95 double monotonicallyIncreasingVirtualTimeSeconds() const override
99 { 96 {
100 ASSERT_NOT_REACHED(); 97 ASSERT_NOT_REACHED();
101 return 0.0; 98 return 0.0;
102 } 99 }
103 100
104 private: 101 private:
105 Deque<std::unique_ptr<WebTaskRunner::Task>>* m_tasks; // NOT OWNED 102 Deque<OwnPtr<WebTaskRunner::Task>>* m_tasks; // NOT OWNED
106 }; 103 };
107 104
108 // TestingPlatformMockScheduler definition: 105 // TestingPlatformMockScheduler definition:
109 106
110 TestingPlatformMockScheduler::TestingPlatformMockScheduler() 107 TestingPlatformMockScheduler::TestingPlatformMockScheduler()
111 : m_mockWebTaskRunner(wrapUnique(new TestingPlatformMockWebTaskRunner(&m_tas ks))) { } 108 : m_mockWebTaskRunner(adoptPtr(new TestingPlatformMockWebTaskRunner(&m_tasks ))) { }
112 109
113 TestingPlatformMockScheduler::~TestingPlatformMockScheduler() { } 110 TestingPlatformMockScheduler::~TestingPlatformMockScheduler() { }
114 111
115 WebTaskRunner* TestingPlatformMockScheduler::loadingTaskRunner() 112 WebTaskRunner* TestingPlatformMockScheduler::loadingTaskRunner()
116 { 113 {
117 return m_mockWebTaskRunner.get(); 114 return m_mockWebTaskRunner.get();
118 } 115 }
119 116
120 WebTaskRunner* TestingPlatformMockScheduler::timerTaskRunner() 117 WebTaskRunner* TestingPlatformMockScheduler::timerTaskRunner()
121 { 118 {
122 return m_mockWebTaskRunner.get(); 119 return m_mockWebTaskRunner.get();
123 } 120 }
124 121
125 void TestingPlatformMockScheduler::runSingleTask() 122 void TestingPlatformMockScheduler::runSingleTask()
126 { 123 {
127 if (m_tasks.isEmpty()) 124 if (m_tasks.isEmpty())
128 return; 125 return;
129 m_tasks.takeFirst()->run(); 126 m_tasks.takeFirst()->run();
130 } 127 }
131 128
132 void TestingPlatformMockScheduler::runAllTasks() 129 void TestingPlatformMockScheduler::runAllTasks()
133 { 130 {
134 while (!m_tasks.isEmpty()) 131 while (!m_tasks.isEmpty())
135 m_tasks.takeFirst()->run(); 132 m_tasks.takeFirst()->run();
136 } 133 }
137 134
138 class TestingPlatformMockWebThread : public WebThread { 135 class TestingPlatformMockWebThread : public WebThread {
139 WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebThread); 136 WTF_MAKE_NONCOPYABLE(TestingPlatformMockWebThread);
140 public: 137 public:
141 TestingPlatformMockWebThread() : m_mockWebScheduler(wrapUnique(new TestingPl atformMockScheduler)) { } 138 TestingPlatformMockWebThread() : m_mockWebScheduler(adoptPtr(new TestingPlat formMockScheduler)) { }
142 ~TestingPlatformMockWebThread() override { } 139 ~TestingPlatformMockWebThread() override { }
143 140
144 WebTaskRunner* getWebTaskRunner() override 141 WebTaskRunner* getWebTaskRunner() override
145 { 142 {
146 return m_mockWebScheduler->timerTaskRunner(); 143 return m_mockWebScheduler->timerTaskRunner();
147 } 144 }
148 145
149 bool isCurrentThread() const override 146 bool isCurrentThread() const override
150 { 147 {
151 ASSERT_NOT_REACHED(); 148 ASSERT_NOT_REACHED();
152 return true; 149 return true;
153 } 150 }
154 151
155 WebScheduler* scheduler() const override 152 WebScheduler* scheduler() const override
156 { 153 {
157 return m_mockWebScheduler.get(); 154 return m_mockWebScheduler.get();
158 } 155 }
159 156
160 TestingPlatformMockScheduler* mockWebScheduler() 157 TestingPlatformMockScheduler* mockWebScheduler()
161 { 158 {
162 return m_mockWebScheduler.get(); 159 return m_mockWebScheduler.get();
163 } 160 }
164 161
165 private: 162 private:
166 std::unique_ptr<TestingPlatformMockScheduler> m_mockWebScheduler; 163 OwnPtr<TestingPlatformMockScheduler> m_mockWebScheduler;
167 }; 164 };
168 165
169 // TestingPlatformSupportWithMockScheduler definition: 166 // TestingPlatformSupportWithMockScheduler definition:
170 167
171 TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler () 168 TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler ()
172 : m_mockWebThread(wrapUnique(new TestingPlatformMockWebThread())) { } 169 : m_mockWebThread(adoptPtr(new TestingPlatformMockWebThread())) { }
173 170
174 TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler (const Config& config) 171 TestingPlatformSupportWithMockScheduler::TestingPlatformSupportWithMockScheduler (const Config& config)
175 : TestingPlatformSupport(config) 172 : TestingPlatformSupport(config)
176 , m_mockWebThread(wrapUnique(new TestingPlatformMockWebThread())) { } 173 , m_mockWebThread(adoptPtr(new TestingPlatformMockWebThread())) { }
177 174
178 TestingPlatformSupportWithMockScheduler::~TestingPlatformSupportWithMockSchedule r() { } 175 TestingPlatformSupportWithMockScheduler::~TestingPlatformSupportWithMockSchedule r() { }
179 176
180 WebThread* TestingPlatformSupportWithMockScheduler::currentThread() 177 WebThread* TestingPlatformSupportWithMockScheduler::currentThread()
181 { 178 {
182 return m_mockWebThread.get(); 179 return m_mockWebThread.get();
183 } 180 }
184 181
185 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc heduler() 182 TestingPlatformMockScheduler* TestingPlatformSupportWithMockScheduler::mockWebSc heduler()
186 { 183 {
187 return m_mockWebThread->mockWebScheduler(); 184 return m_mockWebThread->mockWebScheduler();
188 } 185 }
189 186
190 } // namespace blink 187 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698