Home | History | Annotate | Download | only in media
      1 // Copyright (c) 2012 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/renderer/media/render_media_log.h"
      6 
      7 #include "base/bind.h"
      8 #include "base/logging.h"
      9 #include "base/message_loop/message_loop_proxy.h"
     10 #include "content/common/view_messages.h"
     11 #include "content/renderer/render_thread_impl.h"
     12 
     13 using base::Time;
     14 using base::TimeDelta;
     15 
     16 namespace content {
     17 
     18 RenderMediaLog::RenderMediaLog()
     19     : render_loop_(base::MessageLoopProxy::current()),
     20       last_ipc_send_time_(Time::Now()) {
     21   DCHECK(RenderThreadImpl::current()) <<
     22       "RenderMediaLog must be constructed on the render thread";
     23 }
     24 
     25 void RenderMediaLog::AddEvent(scoped_ptr<media::MediaLogEvent> event) {
     26   if (!RenderThreadImpl::current()) {
     27     render_loop_->PostTask(FROM_HERE, base::Bind(
     28         &RenderMediaLog::AddEvent, this, base::Passed(&event)));
     29     return;
     30   }
     31   queued_media_events_.push_back(*event);
     32   // Limit the send rate of high frequency events.
     33   Time curr_time = Time::Now();
     34   if ((curr_time - last_ipc_send_time_) < TimeDelta::FromSeconds(1))
     35     return;
     36   last_ipc_send_time_ = curr_time;
     37   DVLOG(1) << "media log events array size " << queued_media_events_.size();
     38   RenderThreadImpl::current()->Send(
     39       new ViewHostMsg_MediaLogEvents(queued_media_events_));
     40   queued_media_events_.clear();
     41 }
     42 
     43 RenderMediaLog::~RenderMediaLog() {}
     44 
     45 }  // namespace content
     46