| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DataConsumerHandleTestUtil_h | 5 #ifndef DataConsumerHandleTestUtil_h |
| 6 #define DataConsumerHandleTestUtil_h | 6 #define DataConsumerHandleTestUtil_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "core/testing/NullExecutionContext.h" | 9 #include "core/testing/NullExecutionContext.h" |
| 10 #include "gin/public/isolate_holder.h" | 10 #include "gin/public/isolate_holder.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 virtual ~ThreadingTestBase() { } | 81 virtual ~ThreadingTestBase() { } |
| 82 | 82 |
| 83 class ThreadHolder; | 83 class ThreadHolder; |
| 84 | 84 |
| 85 class Context : public ThreadSafeRefCounted<Context> { | 85 class Context : public ThreadSafeRefCounted<Context> { |
| 86 public: | 86 public: |
| 87 static PassRefPtr<Context> create() { return adoptRef(new Context);
} | 87 static PassRefPtr<Context> create() { return adoptRef(new Context);
} |
| 88 void recordAttach(const String& handle) | 88 void recordAttach(const String& handle) |
| 89 { | 89 { |
| 90 MutexLocker locker(m_loggingMutex); | 90 MutexLocker locker(m_loggingMutex); |
| 91 m_result.append("A reader is attached to " + handle + " on " + c
urrentThreadName() + ".\n"); | 91 m_result.append("A reader is attached to "); |
| 92 m_result.append(handle); |
| 93 m_result.append(" on "); |
| 94 m_result.append(currentThreadName()); |
| 95 m_result.append(".\n"); |
| 92 } | 96 } |
| 93 void recordDetach(const String& handle) | 97 void recordDetach(const String& handle) |
| 94 { | 98 { |
| 95 MutexLocker locker(m_loggingMutex); | 99 MutexLocker locker(m_loggingMutex); |
| 96 m_result.append("A reader is detached from " + handle + " on " +
currentThreadName() + ".\n"); | 100 m_result.append("A reader is detached from "); |
| 101 m_result.append(handle); |
| 102 m_result.append(" on "); |
| 103 m_result.append(currentThreadName()); |
| 104 m_result.append(".\n"); |
| 97 } | 105 } |
| 98 | 106 |
| 99 const String& result() | 107 String result() |
| 100 { | 108 { |
| 101 MutexLocker locker(m_loggingMutex); | 109 MutexLocker locker(m_loggingMutex); |
| 102 return m_result; | 110 return m_result.toString(); |
| 103 } | 111 } |
| 104 | 112 |
| 105 void registerThreadHolder(ThreadHolder* holder) | 113 void registerThreadHolder(ThreadHolder* holder) |
| 106 { | 114 { |
| 107 MutexLocker locker(m_holderMutex); | 115 MutexLocker locker(m_holderMutex); |
| 108 ASSERT(!m_holder); | 116 ASSERT(!m_holder); |
| 109 m_holder = holder; | 117 m_holder = holder; |
| 110 } | 118 } |
| 111 void unregisterThreadHolder() | 119 void unregisterThreadHolder() |
| 112 { | 120 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 137 if (m_holder->readingThread()->isCurrentThread()) | 145 if (m_holder->readingThread()->isCurrentThread()) |
| 138 return "the reading thread"; | 146 return "the reading thread"; |
| 139 if (m_holder->updatingThread()->isCurrentThread()) | 147 if (m_holder->updatingThread()->isCurrentThread()) |
| 140 return "the updating thread"; | 148 return "the updating thread"; |
| 141 } | 149 } |
| 142 return "an unknown thread"; | 150 return "an unknown thread"; |
| 143 } | 151 } |
| 144 | 152 |
| 145 // Protects |m_result|. | 153 // Protects |m_result|. |
| 146 Mutex m_loggingMutex; | 154 Mutex m_loggingMutex; |
| 147 String m_result; | 155 StringBuilder m_result; |
| 148 | 156 |
| 149 // Protects |m_holder|. | 157 // Protects |m_holder|. |
| 150 Mutex m_holderMutex; | 158 Mutex m_holderMutex; |
| 151 // Because Context outlives ThreadHolder, holding a raw pointer | 159 // Because Context outlives ThreadHolder, holding a raw pointer |
| 152 // here is safe. | 160 // here is safe. |
| 153 ThreadHolder* m_holder; | 161 ThreadHolder* m_holder; |
| 154 }; | 162 }; |
| 155 | 163 |
| 156 // The reading/updating threads are alive while ThreadHolder is alive. | 164 // The reading/updating threads are alive while ThreadHolder is alive. |
| 157 class ThreadHolder { | 165 class ThreadHolder { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 217 |
| 210 std::unique_ptr<Reader> obtainReader(Client*) { return WTF::wrapUniq
ue(new ReaderImpl(m_name, m_context)); } | 218 std::unique_ptr<Reader> obtainReader(Client*) { return WTF::wrapUniq
ue(new ReaderImpl(m_name, m_context)); } |
| 211 const char* debugName() const override { return "ThreadingTestBase::
DataConsumerHandle"; } | 219 const char* debugName() const override { return "ThreadingTestBase::
DataConsumerHandle"; } |
| 212 | 220 |
| 213 const String m_name; | 221 const String m_name; |
| 214 RefPtr<Context> m_context; | 222 RefPtr<Context> m_context; |
| 215 }; | 223 }; |
| 216 | 224 |
| 217 void resetReader() { m_reader = nullptr; } | 225 void resetReader() { m_reader = nullptr; } |
| 218 void signalDone() { m_waitableEvent->signal(); } | 226 void signalDone() { m_waitableEvent->signal(); } |
| 219 const String& result() { return m_context->result(); } | 227 String result() { return m_context->result(); } |
| 220 void postTaskToReadingThread(const WebTraceLocation& location, std::uniq
ue_ptr<CrossThreadClosure> task) | 228 void postTaskToReadingThread(const WebTraceLocation& location, std::uniq
ue_ptr<CrossThreadClosure> task) |
| 221 { | 229 { |
| 222 m_context->postTaskToReadingThread(location, std::move(task)); | 230 m_context->postTaskToReadingThread(location, std::move(task)); |
| 223 } | 231 } |
| 224 void postTaskToUpdatingThread(const WebTraceLocation& location, std::uni
que_ptr<CrossThreadClosure> task) | 232 void postTaskToUpdatingThread(const WebTraceLocation& location, std::uni
que_ptr<CrossThreadClosure> task) |
| 225 { | 233 { |
| 226 m_context->postTaskToUpdatingThread(location, std::move(task)); | 234 m_context->postTaskToUpdatingThread(location, std::move(task)); |
| 227 } | 235 } |
| 228 void postTaskToReadingThreadAndWait(const WebTraceLocation& location, st
d::unique_ptr<CrossThreadClosure> task) | 236 void postTaskToReadingThreadAndWait(const WebTraceLocation& location, st
d::unique_ptr<CrossThreadClosure> task) |
| 229 { | 237 { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 std::unique_ptr<HandleReadResult> m_result; | 541 std::unique_ptr<HandleReadResult> m_result; |
| 534 bool m_isDone; | 542 bool m_isDone; |
| 535 | 543 |
| 536 std::unique_ptr<T> m_handleReader; | 544 std::unique_ptr<T> m_handleReader; |
| 537 }; | 545 }; |
| 538 }; | 546 }; |
| 539 | 547 |
| 540 } // namespace blink | 548 } // namespace blink |
| 541 | 549 |
| 542 #endif // DataConsumerHandleTestUtil_h | 550 #endif // DataConsumerHandleTestUtil_h |
| OLD | NEW |