| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef AsyncOperationMap_h | |
| 6 #define AsyncOperationMap_h | |
| 7 | |
| 8 #include "core/inspector/v8/V8DebuggerAgent.h" | |
| 9 #include "platform/heap/Handle.h" | |
| 10 #include "wtf/HashMap.h" | |
| 11 #include "wtf/PassRefPtr.h" | |
| 12 #include "wtf/RefPtr.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 template <class K> | |
| 17 class AsyncOperationMap final { | |
| 18 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
| 19 public: | |
| 20 using MapType = WillBeHeapHashMap<K, int>; | |
| 21 explicit AsyncOperationMap(V8DebuggerAgent* debuggerAgent) | |
| 22 : m_debuggerAgent(debuggerAgent) | |
| 23 { | |
| 24 } | |
| 25 | |
| 26 ~AsyncOperationMap() | |
| 27 { | |
| 28 // Verify that this object has been explicitly disposed. | |
| 29 ASSERT(hasBeenDisposed()); | |
| 30 } | |
| 31 | |
| 32 #if ENABLE(ASSERT) | |
| 33 bool hasBeenDisposed() const | |
| 34 { | |
| 35 return !m_debuggerAgent; | |
| 36 } | |
| 37 #endif | |
| 38 | |
| 39 void dispose() | |
| 40 { | |
| 41 clear(); | |
| 42 m_debuggerAgent = nullptr; | |
| 43 } | |
| 44 | |
| 45 void clear() | |
| 46 { | |
| 47 ASSERT(m_debuggerAgent); | |
| 48 for (auto it : m_asyncOperations) | |
| 49 m_debuggerAgent->traceAsyncOperationCompleted(it.value); | |
| 50 m_asyncOperations.clear(); | |
| 51 } | |
| 52 | |
| 53 void set(typename MapType::KeyPeekInType key, int operationId) | |
| 54 { | |
| 55 m_asyncOperations.set(key, operationId); | |
| 56 } | |
| 57 | |
| 58 bool contains(typename MapType::KeyPeekInType key) const | |
| 59 { | |
| 60 return m_asyncOperations.contains(key); | |
| 61 } | |
| 62 | |
| 63 int get(typename MapType::KeyPeekInType key) const | |
| 64 { | |
| 65 return m_asyncOperations.get(key); | |
| 66 } | |
| 67 | |
| 68 void remove(typename MapType::KeyPeekInType key) | |
| 69 { | |
| 70 ASSERT(m_debuggerAgent); | |
| 71 int operationId = m_asyncOperations.take(key); | |
| 72 if (operationId) | |
| 73 m_debuggerAgent->traceAsyncOperationCompleted(operationId); | |
| 74 } | |
| 75 | |
| 76 DEFINE_INLINE_TRACE() | |
| 77 { | |
| 78 visitor->trace(m_asyncOperations); | |
| 79 } | |
| 80 | |
| 81 private: | |
| 82 V8DebuggerAgent* m_debuggerAgent; | |
| 83 MapType m_asyncOperations; | |
| 84 }; | |
| 85 | |
| 86 } // namespace blink | |
| 87 | |
| 88 | |
| 89 #endif // AsyncOperationMap_h | |
| OLD | NEW |