Chromium Code Reviews| 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, | |
|
tommi (sloooow) - chröme
2012/12/19 11:47:29
fix indentation throughout.
Bernhard Bauer
2013/02/05 18:45:18
Done.
| |
| 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 std::pair<int, int> id = std::make_pair( | |
| 36 contents->GetRenderProcessHost()->GetID(), | |
| 37 contents->GetRenderViewHost()->GetRoutingID()); | |
| 38 return audio_streams_.find(id) != audio_streams_.end(); | |
| 39 } | |
| 40 | |
| 41 void AudioStreamIndicator::UpdateWebContentsStatusOnUIThread( | |
| 42 int render_process_id, | |
| 43 int render_view_id, | |
| 44 bool playing) { | |
| 45 std::pair<int, int> id = std::make_pair(render_process_id, render_view_id); | |
| 46 if (playing) { | |
| 47 audio_streams_.insert(id); | |
| 48 } else { | |
| 49 std::multiset<std::pair<int, int> >::iterator it = audio_streams_.find(id); | |
| 50 DCHECK(it != audio_streams_.end()); | |
| 51 audio_streams_.erase(it); | |
| 52 } | |
| 53 | |
| 54 WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id, | |
| 55 render_view_id); | |
| 56 if (web_contents) | |
| 57 web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | |
| 58 } | |
| OLD | NEW |