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

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 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 int stream_id,
24 bool playing) {
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
26
27 BrowserThread::PostTask(
28 BrowserThread::UI, FROM_HERE,
29 base::Bind(&AudioStreamIndicator::UpdateWebContentsStatusOnUIThread,
30 this, render_process_id, render_view_id, stream_id, playing));
31 }
32
33 bool AudioStreamIndicator::IsPlayingAudio(WebContents* contents) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35
36 RenderViewId id(contents->GetRenderProcessHost()->GetID(),
37 contents->GetRenderViewHost()->GetRoutingID());
38 return audio_streams_.find(id) != audio_streams_.end();
39 }
40
41 AudioStreamIndicator::RenderViewId::RenderViewId(int render_process_id,
42 int render_view_id)
43 : render_process_id(render_process_id),
44 render_view_id(render_view_id) {
45 }
46
47 bool AudioStreamIndicator::RenderViewId::operator<(
48 const RenderViewId& other) const {
49 if (render_process_id != other.render_process_id)
50 return render_process_id < other.render_process_id;
51
52 return render_view_id < other.render_view_id;
53 }
54
55 void AudioStreamIndicator::UpdateWebContentsStatusOnUIThread(
56 int render_process_id,
57 int render_view_id,
58 int stream_id,
59 bool playing) {
60 RenderViewId id(render_process_id, render_view_id);
miu 2013/02/11 20:51:47 nit: Can you add the following to the top of this
Bernhard Bauer 2013/02/12 18:06:27 Done.
61 if (playing) {
62 audio_streams_[id].insert(stream_id);
63 } else {
64 std::map<RenderViewId, std::set<int> >::iterator it =
65 audio_streams_.find(id);
66 if (it != audio_streams_.end())
67 return;
68
69 it->second.erase(stream_id);
70 if (it->second.empty())
71 audio_streams_.erase(it);
72 }
73
74 WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id,
75 render_view_id);
76 if (web_contents)
77 web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
78 }
OLDNEW
« no previous file with comments | « chrome/browser/media/audio_stream_indicator.h ('k') | chrome/browser/media/media_capture_devices_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698