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

Side by Side Diff: chrome/browser/media/audio_stream_indicator.cc

Issue 11573066: Add a method to tab_utils.h to find out whether a tab is playing audio. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review/rewrite Created 7 years, 10 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) 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 "chrome/browser/media/audio_stream_indicator.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/tab_contents/tab_util.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/invalidate_type.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/web_contents.h"
14
15 using content::BrowserThread;
16 using content::WebContents;
17
18 AudioStreamIndicator::AudioStreamIndicator() {}
19 AudioStreamIndicator::~AudioStreamIndicator() {}
20
21 void AudioStreamIndicator::UpdateWebContentsStatus(int render_process_id,
22 int render_view_id,
23 bool playing) {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
25
26 BrowserThread::PostTask(
27 BrowserThread::UI, FROM_HERE,
28 base::Bind(&AudioStreamIndicator::UpdateWebContentsStatusOnUIThread,
29 this, render_process_id, render_view_id, playing));
30 }
31
32 bool AudioStreamIndicator::IsPlayingAudio(WebContents* contents) {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
34
35 RenderViewId id(contents->GetRenderProcessHost()->GetID(),
36 contents->GetRenderViewHost()->GetRoutingID());
37 return audio_streams_.find(id) != audio_streams_.end();
38 }
39
40 AudioStreamIndicator::RenderViewId::RenderViewId(int render_process_id,
41 int render_view_id)
42 : render_process_id(render_process_id),
43 render_view_id(render_view_id) {
44 }
45
46 bool AudioStreamIndicator::RenderViewId::operator<(
47 const RenderViewId& other) const {
48 if (render_process_id != other.render_process_id)
49 return render_process_id < other.render_process_id;
50
51 return render_view_id < other.render_view_id;
52 }
53
54 void AudioStreamIndicator::UpdateWebContentsStatusOnUIThread(
55 int render_process_id,
56 int render_view_id,
57 bool playing) {
58 RenderViewId id(render_process_id, render_view_id);
59 if (playing) {
60 audio_streams_.insert(id);
61 } else {
62 std::multiset<RenderViewId>::iterator it = audio_streams_.find(id);
63 DCHECK(it != audio_streams_.end());
64 audio_streams_.erase(it);
65 }
66
67 WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id,
68 render_view_id);
69 if (web_contents)
70 web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698