Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: chrome/browser/resource_throttle.cc

Issue 289863005: [Mac] Maximise timer slack for background tabs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial review Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014 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 "chrome/browser/resource_throttle.h"
6
7 #include "chrome/browser/media/audio_stream_monitor.h"
8 #include "chrome/common/render_messages.h"
9 #include "content/public/browser/render_frame_host.h"
10
11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceThrottle);
12
13 ResourceThrottle::~ResourceThrottle() {
14 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this);
15 }
16
17 ResourceThrottle::ResourceThrottle(content::WebContents* contents)
18 : timer_coalescing_enabled_(false) {
19 contents_ = contents;
20 Observe(contents);
21 MediaCaptureDevicesDispatcher::GetInstance()->AddObserver(this);
22 }
23
24 void ResourceThrottle::WasShown() {
25 SetTimerCoalescingEnabled(false);
26 }
27
28 void ResourceThrottle::WasHidden() {
29 AudioStreamMonitor* const audio_stream_monitor =
30 AudioStreamMonitor::FromWebContents(contents_);
31 bool was_recently_audible =
32 audio_stream_monitor && audio_stream_monitor->WasRecentlyAudible();
33
34 if (!was_recently_audible)
35 SetTimerCoalescingEnabled(true);
36 }
37
38 void ResourceThrottle::OnCreatingAudioStream(int render_process_id,
aiolos (Not reviewing) 2014/05/20 17:45:23 Were you planning on using OnAudioStreamPlaying/On
39 int render_frame_id) {
40 // Check that the frame in question is the one we're tracking.
41 content::RenderFrameHost* render_frame_host =
42 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
43 content::WebContents* tab =
44 content::WebContents::FromRenderFrameHost(render_frame_host);
45 if (tab != contents_)
46 return;
47
48 SetTimerCoalescingEnabled(false);
49 }
50
51 void ResourceThrottle::SetTimerCoalescingEnabled(bool enabled) {
52 if (timer_coalescing_enabled_ == enabled)
53 return;
54 Send(new ChromeViewMsg_SetCoalesceTimers(enabled));
55 timer_coalescing_enabled_ = enabled;
56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698