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

Unified Diff: content/browser/media/android/audio_focus_manager.cc

Issue 1131793004: Migrate AudioFocusChangeListener to browser and always send GAIN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: webview suggestions from boliu Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/media/android/audio_focus_manager.cc
diff --git a/content/browser/media/android/audio_focus_manager.cc b/content/browser/media/android/audio_focus_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a258791f6043cf89f934bf4f3d0c4e102e663ecd
--- /dev/null
+++ b/content/browser/media/android/audio_focus_manager.cc
@@ -0,0 +1,70 @@
+// Copyright 2015 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 "content/browser/media/android/audio_focus_manager.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/bind.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "content/browser/media/android/browser_media_player_manager.h"
+
+#include "jni/AudioFocusManager_jni.h"
+
+using base::android::AttachCurrentThread;
+using base::android::CheckException;
+using base::android::ScopedJavaLocalRef;
+
+namespace content {
+
+AudioFocusManager::AudioFocusManager(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
+ base::WeakPtr<BrowserMediaPlayerManager> manager)
+ : task_runner_(task_runner),
+ manager_(manager) {
+ DCHECK(task_runner_.get());
+ DCHECK(manager_);
+ j_audio_focus_manager_.Reset(
+ Java_AudioFocusManager_getInstance(
+ AttachCurrentThread(),
+ base::android::GetApplicationContext()));
+}
+
+AudioFocusManager::~AudioFocusManager() {}
+
+// static
+bool AudioFocusManager::RegisterAudioFocusManager(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+void AudioFocusManager::RequestAudioFocus(int player_id) {
+ JNIEnv* env = AttachCurrentThread();
+ CHECK(env);
+ if (!j_audio_focus_manager_.is_null()) {
+ Java_AudioFocusManager_requestAudioFocus(
+ env, j_audio_focus_manager_.obj(),
+ reinterpret_cast<intptr_t>(this),
+ player_id);
+ }
+}
+
+void AudioFocusManager::AbandonAudioFocus(int player_id) {
+ JNIEnv* env = AttachCurrentThread();
+ CHECK(env);
+ if (!j_audio_focus_manager_.is_null()) {
+ Java_AudioFocusManager_abandonAudioFocus(
+ env, j_audio_focus_manager_.obj(),
+ reinterpret_cast<intptr_t>(this),
+ player_id);
+ }
+}
+
+void AudioFocusManager::OnMediaInterrupted(JNIEnv*, jobject, jint player_id) {
+ if (manager_.get()) {
+ task_runner_->PostTask(FROM_HERE, base::Bind(
+ &BrowserMediaPlayerManager::OnMediaInterrupted, manager_, player_id));
+ }
+}
+
+} // namespace content
« no previous file with comments | « content/browser/media/android/audio_focus_manager.h ('k') | content/browser/media/android/browser_media_player_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698