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

Unified 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: fix Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/audio_stream_indicator.cc
diff --git a/chrome/browser/media/audio_stream_indicator.cc b/chrome/browser/media/audio_stream_indicator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f3139f932be84d9f3d18d91b3cd5db177a9e9b8a
--- /dev/null
+++ b/chrome/browser/media/audio_stream_indicator.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/audio_stream_indicator.h"
+
+#include "base/bind.h"
+#include "chrome/browser/tab_contents/tab_util.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/invalidate_type.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+
+using content::BrowserThread;
+using content::WebContents;
+
+AudioStreamIndicator::AudioStreamIndicator() {}
+AudioStreamIndicator::~AudioStreamIndicator() {}
+
+void AudioStreamIndicator::UpdateWebContentsStatus(int render_process_id,
+ 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.
+ bool playing) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&AudioStreamIndicator::UpdateWebContentsStatusOnUIThread,
+ this, render_process_id, render_view_id, playing));
+}
+
+bool AudioStreamIndicator::IsPlayingAudio(WebContents* contents) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ std::pair<int, int> id = std::make_pair(
+ contents->GetRenderProcessHost()->GetID(),
+ contents->GetRenderViewHost()->GetRoutingID());
+ return audio_streams_.find(id) != audio_streams_.end();
+}
+
+void AudioStreamIndicator::UpdateWebContentsStatusOnUIThread(
+ int render_process_id,
+ int render_view_id,
+ bool playing) {
+ std::pair<int, int> id = std::make_pair(render_process_id, render_view_id);
+ if (playing) {
+ audio_streams_.insert(id);
+ } else {
+ std::multiset<std::pair<int, int> >::iterator it = audio_streams_.find(id);
+ DCHECK(it != audio_streams_.end());
+ audio_streams_.erase(it);
+ }
+
+ WebContents* web_contents = tab_util::GetWebContentsByID(render_process_id,
+ render_view_id);
+ if (web_contents)
+ web_contents->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
+}

Powered by Google App Engine
This is Rietveld 408576698