Chromium Code Reviews| Index: chrome/browser/resource_throttle.cc |
| diff --git a/chrome/browser/resource_throttle.cc b/chrome/browser/resource_throttle.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..60b630be62082b22f95d4937d256d0f2e4c9b4f6 |
| --- /dev/null |
| +++ b/chrome/browser/resource_throttle.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/resource_throttle.h" |
| + |
| +#include "chrome/browser/media/audio_stream_monitor.h" |
| +#include "chrome/common/render_messages.h" |
| +#include "content/public/browser/render_frame_host.h" |
| + |
| +DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceThrottle); |
| + |
| +ResourceThrottle::~ResourceThrottle() { |
| + MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); |
| +} |
| + |
| +ResourceThrottle::ResourceThrottle(content::WebContents* contents) |
| + : timer_coalescing_enabled_(false) { |
| + contents_ = contents; |
| + Observe(contents); |
| + MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this); |
| +} |
| + |
| +void ResourceThrottle::WasShown() { |
| + SetTimerCoalescingEnabled(false); |
| +} |
| + |
| +void ResourceThrottle::WasHidden() { |
| + AudioStreamMonitor* const audio_stream_monitor = |
| + AudioStreamMonitor::FromWebContents(contents_); |
| + bool was_recently_audible = |
| + audio_stream_monitor && audio_stream_monitor->WasRecentlyAudible(); |
| + |
| + if (!was_recently_audible) |
| + SetTimerCoalescingEnabled(true); |
| +} |
| + |
| +void ResourceThrottle::OnCreatingAudioStream(int render_process_id, |
|
aiolos (Not reviewing)
2014/05/20 17:45:23
Were you planning on using OnAudioStreamPlaying/On
|
| + int render_frame_id) { |
| + // Check that the frame in question is the one we're tracking. |
| + content::RenderFrameHost* render_frame_host = |
| + content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| + content::WebContents* tab = |
| + content::WebContents::FromRenderFrameHost(render_frame_host); |
| + if (tab != contents_) |
| + return; |
| + |
| + SetTimerCoalescingEnabled(false); |
| +} |
| + |
| +void ResourceThrottle::SetTimerCoalescingEnabled(bool enabled) { |
| + if (timer_coalescing_enabled_ == enabled) |
| + return; |
| + Send(new ChromeViewMsg_SetCoalesceTimers(enabled)); |
| + timer_coalescing_enabled_ = enabled; |
| +} |