| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/media/android/media_session.h" | 5 #include "content/browser/media/android/media_session.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "content/browser/media/android/media_session_observer.h" | 9 #include "content/browser/media/android/media_session_observer.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 for (auto it = players_.begin(); it != players_.end();) { | 105 for (auto it = players_.begin(); it != players_.end();) { |
| 106 if (it->observer == observer) | 106 if (it->observer == observer) |
| 107 players_.erase(it++); | 107 players_.erase(it++); |
| 108 else | 108 else |
| 109 ++it; | 109 ++it; |
| 110 } | 110 } |
| 111 | 111 |
| 112 AbandonSystemAudioFocusIfNeeded(); | 112 AbandonSystemAudioFocusIfNeeded(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void MediaSession::OnSuspend(JNIEnv* env, jobject obj, jboolean temporary) { | 115 void MediaSession::OnSuspend(JNIEnv* env, |
| 116 const JavaParamRef<jobject>& obj, |
| 117 jboolean temporary) { |
| 116 // TODO(mlamouri): this check makes it so that if a MediaSession is paused and | 118 // TODO(mlamouri): this check makes it so that if a MediaSession is paused and |
| 117 // then loses audio focus, it will still stay in the Suspended state. | 119 // then loses audio focus, it will still stay in the Suspended state. |
| 118 // See https://crbug.com/539998 | 120 // See https://crbug.com/539998 |
| 119 if (audio_focus_state_ != State::ACTIVE) | 121 if (audio_focus_state_ != State::ACTIVE) |
| 120 return; | 122 return; |
| 121 | 123 |
| 122 OnSuspendInternal(SuspendType::SYSTEM); | 124 OnSuspendInternal(SuspendType::SYSTEM); |
| 123 if (!temporary) | 125 if (!temporary) |
| 124 SetAudioFocusState(State::INACTIVE); | 126 SetAudioFocusState(State::INACTIVE); |
| 125 | 127 |
| 126 uma_helper_.RecordSessionSuspended( | 128 uma_helper_.RecordSessionSuspended( |
| 127 temporary ? MediaSessionSuspendedSource::SystemTransient | 129 temporary ? MediaSessionSuspendedSource::SystemTransient |
| 128 : MediaSessionSuspendedSource::SystemPermanent); | 130 : MediaSessionSuspendedSource::SystemPermanent); |
| 129 UpdateWebContents(); | 131 UpdateWebContents(); |
| 130 } | 132 } |
| 131 | 133 |
| 132 void MediaSession::OnResume(JNIEnv* env, jobject obj) { | 134 void MediaSession::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 133 if (audio_focus_state_ != State::SUSPENDED) | 135 if (audio_focus_state_ != State::SUSPENDED) |
| 134 return; | 136 return; |
| 135 | 137 |
| 136 OnResumeInternal(SuspendType::SYSTEM); | 138 OnResumeInternal(SuspendType::SYSTEM); |
| 137 UpdateWebContents(); | 139 UpdateWebContents(); |
| 138 } | 140 } |
| 139 | 141 |
| 140 void MediaSession::Resume() { | 142 void MediaSession::Resume() { |
| 141 DCHECK(IsSuspended()); | 143 DCHECK(IsSuspended()); |
| 142 | 144 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 case State::SUSPENDED: | 283 case State::SUSPENDED: |
| 282 uma_helper_.OnSessionSuspended(); | 284 uma_helper_.OnSessionSuspended(); |
| 283 break; | 285 break; |
| 284 case State::INACTIVE: | 286 case State::INACTIVE: |
| 285 uma_helper_.OnSessionInactive(); | 287 uma_helper_.OnSessionInactive(); |
| 286 break; | 288 break; |
| 287 } | 289 } |
| 288 } | 290 } |
| 289 | 291 |
| 290 } // namespace content | 292 } // namespace content |
| OLD | NEW |