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