OLD | NEW |
(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 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 61 RenderViewId id(render_process_id, render_view_id); |
| 62 if (playing) { |
| 63 audio_streams_[id].insert(stream_id); |
| 64 } else { |
| 65 std::map<RenderViewId, std::set<int> >::iterator it = |
| 66 audio_streams_.find(id); |
| 67 if (it != audio_streams_.end()) |
| 68 return; |
| 69 |
| 70 it->second.erase(stream_id); |
| 71 if (it->second.empty()) |
| 72 audio_streams_.erase(it); |
| 73 } |
| 74 |
| 75 WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id, |
| 76 render_view_id); |
| 77 if (web_contents) |
| 78 web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| 79 } |
OLD | NEW |