| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 void TraceEventDispatcher::dispatchEventOnAnyThread(char phase, const unsigned c
har*, const char* name, unsigned long long id, | 42 void TraceEventDispatcher::dispatchEventOnAnyThread(char phase, const unsigned c
har*, const char* name, unsigned long long id, |
| 43 int numArgs, const char* const* argNames, const unsigned char* argTypes, con
st unsigned long long* argValues, | 43 int numArgs, const char* const* argNames, const unsigned char* argTypes, con
st unsigned long long* argValues, |
| 44 unsigned char flags, double timestamp) | 44 unsigned char flags, double timestamp) |
| 45 { | 45 { |
| 46 TraceEventDispatcher* self = instance(); | 46 TraceEventDispatcher* self = instance(); |
| 47 { | 47 { |
| 48 MutexLocker locker(self->m_mutex); | 48 MutexLocker locker(self->m_mutex); |
| 49 if (self->m_handlers.find(std::make_pair(name, phase)) == self->m_handle
rs.end()) | 49 if (self->m_listeners->find(std::make_pair(name, phase)) == self->m_list
eners->end()) |
| 50 return; | 50 return; |
| 51 } | 51 } |
| 52 self->enqueueEvent(TraceEvent(timestamp, phase, name, id, currentThread(), n
umArgs, argNames, argTypes, argValues)); | 52 self->enqueueEvent(TraceEvent(timestamp, phase, name, id, currentThread(), n
umArgs, argNames, argTypes, argValues)); |
| 53 if (isMainThread()) | 53 if (isMainThread()) |
| 54 self->processBackgroundEvents(); | 54 self->processBackgroundEvents(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void TraceEventDispatcher::enqueueEvent(const TraceEvent& event) | 57 void TraceEventDispatcher::enqueueEvent(const TraceEvent& event) |
| 58 { | 58 { |
| 59 const float eventProcessingThresholdInSeconds = 0.1; | 59 const float eventProcessingThresholdInSeconds = 0.1; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 80 { | 80 { |
| 81 MutexLocker locker(m_mutex); | 81 MutexLocker locker(m_mutex); |
| 82 m_lastEventProcessingTime = WTF::monotonicallyIncreasingTime(); | 82 m_lastEventProcessingTime = WTF::monotonicallyIncreasingTime(); |
| 83 if (m_backgroundEvents.isEmpty()) | 83 if (m_backgroundEvents.isEmpty()) |
| 84 return; | 84 return; |
| 85 events.reserveCapacity(m_backgroundEvents.capacity()); | 85 events.reserveCapacity(m_backgroundEvents.capacity()); |
| 86 m_backgroundEvents.swap(events); | 86 m_backgroundEvents.swap(events); |
| 87 } | 87 } |
| 88 for (size_t eventIndex = 0, size = events.size(); eventIndex < size; ++event
Index) { | 88 for (size_t eventIndex = 0, size = events.size(); eventIndex < size; ++event
Index) { |
| 89 const TraceEvent& event = events[eventIndex]; | 89 const TraceEvent& event = events[eventIndex]; |
| 90 HandlersMap::iterator it = m_handlers.find(std::make_pair(event.name(),
event.phase())); | 90 ListenersMap::iterator it = m_listeners->find(std::make_pair(event.name(
), event.phase())); |
| 91 if (it == m_handlers.end()) | 91 if (it == m_listeners->end()) |
| 92 continue; | 92 continue; |
| 93 Vector<BoundTraceEventHandler>& handlers = it->value; | 93 WillBeHeapVector<OwnPtrWillBeMember<TraceEventListener> >& listeners = *
it->value.get(); |
| 94 for (size_t handlerIndex = 0; handlerIndex < handlers.size(); ++handlerI
ndex) | 94 for (size_t listenerIndex = 0; listenerIndex < listeners.size(); ++liste
nerIndex) |
| 95 (handlers[handlerIndex].instance->*(handlers[handlerIndex].method))(
event); | 95 listeners[listenerIndex]->call(event); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 void TraceEventDispatcher::innerAddListener(const char* name, char phase, TraceE
ventTargetBase* instance, TraceEventHandlerMethod method, InspectorClient* clien
t) | 99 void TraceEventDispatcher::addListener(const char* name, char phase, PassOwnPtrW
illBeRawPtr<TraceEventListener> listener, InspectorClient* client) |
| 100 { | 100 { |
| 101 static const char CategoryFilter[] = "-*," TRACE_DISABLED_BY_DEFAULT("devtoo
ls.timeline") "," TRACE_DISABLED_BY_DEFAULT("devtools.timeline.frame"); | 101 static const char CategoryFilter[] = "-*," TRACE_DISABLED_BY_DEFAULT("devtoo
ls.timeline") "," TRACE_DISABLED_BY_DEFAULT("devtools.timeline.frame"); |
| 102 | 102 |
| 103 ASSERT(isMainThread()); | 103 ASSERT(isMainThread()); |
| 104 MutexLocker locker(m_mutex); | 104 MutexLocker locker(m_mutex); |
| 105 if (m_handlers.isEmpty()) | 105 if (m_listeners->isEmpty()) |
| 106 client->setTraceEventCallback(CategoryFilter, dispatchEventOnAnyThread); | 106 client->setTraceEventCallback(CategoryFilter, dispatchEventOnAnyThread); |
| 107 HandlersMap::iterator it = m_handlers.find(std::make_pair(name, phase)); | 107 ListenersMap::iterator it = m_listeners->find(std::make_pair(name, phase)); |
| 108 if (it == m_handlers.end()) | 108 if (it == m_listeners->end()) |
| 109 m_handlers.add(std::make_pair(name, phase), Vector<BoundTraceEventHandle
r>()).storedValue->value.append(BoundTraceEventHandler(instance, method)); | 109 m_listeners->add(std::make_pair(name, phase), adoptPtrWillBeNoop(new Wil
lBeHeapVector<OwnPtrWillBeMember<TraceEventListener> >())).storedValue->value->a
ppend(listener); |
| 110 else | 110 else |
| 111 it->value.append(BoundTraceEventHandler(instance, method)); | 111 it->value->append(listener); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void TraceEventDispatcher::removeAllListeners(TraceEventTargetBase* instance, In
spectorClient* client) | 114 void TraceEventDispatcher::removeAllListeners(void* eventTarget, InspectorClient
* client) |
| 115 { | 115 { |
| 116 ASSERT(isMainThread()); | 116 ASSERT(isMainThread()); |
| 117 processBackgroundEvents(); | 117 processBackgroundEvents(); |
| 118 { | 118 { |
| 119 MutexLocker locker(m_mutex); | 119 MutexLocker locker(m_mutex); |
| 120 | 120 |
| 121 HandlersMap remainingHandlers; | 121 ListenersMap remainingListeners; |
| 122 for (HandlersMap::iterator it = m_handlers.begin(); it != m_handlers.end
(); ++it) { | 122 for (ListenersMap::iterator it = m_listeners->begin(); it != m_listeners
->end(); ++it) { |
| 123 Vector<BoundTraceEventHandler>& handlers = it->value; | 123 WillBeHeapVector<OwnPtrWillBeMember<TraceEventListener> >& listeners
= *it->value.get(); |
| 124 for (size_t j = 0; j < handlers.size();) { | 124 for (size_t j = 0; j < listeners.size();) { |
| 125 if (handlers[j].instance == instance) | 125 if (listeners[j]->target() == eventTarget) |
| 126 handlers.remove(j); | 126 listeners.remove(j); |
| 127 else | 127 else |
| 128 ++j; | 128 ++j; |
| 129 } | 129 } |
| 130 if (!handlers.isEmpty()) | 130 if (!listeners.isEmpty()) |
| 131 remainingHandlers.add(it->key, it->value); | 131 remainingListeners.add(it->key, it->value.release()); |
| 132 } | 132 } |
| 133 m_handlers.swap(remainingHandlers); | 133 m_listeners->swap(remainingListeners); |
| 134 } | 134 } |
| 135 if (m_handlers.isEmpty()) | 135 if (m_listeners->isEmpty()) |
| 136 client->resetTraceEventCallback(); | 136 client->resetTraceEventCallback(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 size_t TraceEventDispatcher::TraceEvent::findParameter(const char* name) const | 139 size_t TraceEventDispatcher::TraceEvent::findParameter(const char* name) const |
| 140 { | 140 { |
| 141 for (int i = 0; i < m_argumentCount; ++i) { | 141 for (int i = 0; i < m_argumentCount; ++i) { |
| 142 if (!strcmp(name, m_argumentNames[i])) | 142 if (!strcmp(name, m_argumentNames[i])) |
| 143 return i; | 143 return i; |
| 144 } | 144 } |
| 145 return kNotFound; | 145 return kNotFound; |
| 146 } | 146 } |
| 147 | 147 |
| 148 const TraceEvent::TraceValueUnion& TraceEventDispatcher::TraceEvent::parameter(c
onst char* name, unsigned char expectedType) const | 148 const TraceEvent::TraceValueUnion& TraceEventDispatcher::TraceEvent::parameter(c
onst char* name, unsigned char expectedType) const |
| 149 { | 149 { |
| 150 static blink::TraceEvent::TraceValueUnion missingValue; | 150 static blink::TraceEvent::TraceValueUnion missingValue; |
| 151 size_t index = findParameter(name); | 151 size_t index = findParameter(name); |
| 152 ASSERT(isMainThread()); | 152 ASSERT(isMainThread()); |
| 153 if (index == kNotFound || m_argumentTypes[index] != expectedType) { | 153 if (index == kNotFound || m_argumentTypes[index] != expectedType) { |
| 154 ASSERT_NOT_REACHED(); | 154 ASSERT_NOT_REACHED(); |
| 155 return missingValue; | 155 return missingValue; |
| 156 } | 156 } |
| 157 return m_argumentValues[index]; | 157 return m_argumentValues[index]; |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace blink | 160 } // namespace blink |
| 161 | 161 |
| OLD | NEW |