1// Copyright 2013 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#include "content/common/gpu/devtools_gpu_instrumentation.h" 6 7#include "base/logging.h" 8#include "base/time/time.h" 9#include "content/common/gpu/devtools_gpu_agent.h" 10#include "content/common/gpu/gpu_channel.h" 11#include "content/common/gpu/gpu_channel_manager.h" 12 13namespace content { 14 15bool GpuEventsDispatcher::enabled_ = false; 16 17GpuEventsDispatcher::GpuEventsDispatcher() { 18} 19 20GpuEventsDispatcher::~GpuEventsDispatcher() { 21} 22 23void GpuEventsDispatcher::AddProcessor(DevToolsGpuAgent* processor) { 24 DCHECK(CalledOnValidThread()); 25 processors_.push_back(processor); 26 enabled_ = !processors_.empty(); 27} 28 29void GpuEventsDispatcher::RemoveProcessor(DevToolsGpuAgent* processor) { 30 DCHECK(CalledOnValidThread()); 31 processors_.erase( 32 std::remove(processors_.begin(), processors_.end(), processor), 33 processors_.end()); 34 enabled_ = !processors_.empty(); 35} 36 37// static 38void GpuEventsDispatcher::DoFireEvent(EventPhase phase, 39 GpuChannel* channel) { 40 TimeTicks timestamp = base::TimeTicks::NowFromSystemTraceTime(); 41 GpuEventsDispatcher* self = 42 channel->gpu_channel_manager()->gpu_devtools_events_dispatcher(); 43 DCHECK(self->CalledOnValidThread()); 44 std::vector<DevToolsGpuAgent*>::iterator it; 45 for (it = self->processors_.begin(); it != self->processors_.end(); ++it) { 46 (*it)->ProcessEvent(timestamp, phase, channel); 47 } 48} 49 50} // namespace 51