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

Side by Side Diff: content/browser/media/session/media_session_impl.cc

Issue 2442303002: Adding new media controls to MediaNotification (Closed)
Patch Set: rebased Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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/session/media_session_impl.h" 5 #include "content/browser/media/session/media_session_impl.h"
6 6
7 #include "content/browser/media/session/audio_focus_delegate.h" 7 #include "content/browser/media/session/audio_focus_delegate.h"
8 #include "content/browser/media/session/media_session_player_observer.h" 8 #include "content/browser/media/session/media_session_player_observer.h"
9 #include "content/browser/media/session/media_session_service_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/public/browser/media_session.h"
12 #include "content/public/browser/media_session_observer.h"
10 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_delegate.h"
12 #include "media/base/media_content_type.h" 14 #include "media/base/media_content_type.h"
13 15
14 #if defined(OS_ANDROID) 16 #if defined(OS_ANDROID)
15 #include "content/browser/media/session/media_session_android.h" 17 #include "content/browser/media/session/media_session_android.h"
16 #endif // defined(OS_ANDROID) 18 #endif // defined(OS_ANDROID)
17 19
18 namespace content { 20 namespace content {
19 21
20 namespace { 22 namespace {
21 23
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 78
77 // TODO(zqzhang): refactor MediaSessionImpl, maybe move the interface used to 79 // TODO(zqzhang): refactor MediaSessionImpl, maybe move the interface used to
78 // talk with AudioFocusManager out to a seperate class. The AudioFocusManager 80 // talk with AudioFocusManager out to a seperate class. The AudioFocusManager
79 // unit tests then could mock the interface and abandon audio focus when 81 // unit tests then could mock the interface and abandon audio focus when
80 // WebContents is destroyed. See https://crbug.com/651069 82 // WebContents is destroyed. See https://crbug.com/651069
81 players_.clear(); 83 players_.clear();
82 pepper_players_.clear(); 84 pepper_players_.clear();
83 AbandonSystemAudioFocusIfNeeded(); 85 AbandonSystemAudioFocusIfNeeded();
84 } 86 }
85 87
88 void MediaSessionImpl::SetMediaSessionService(
89 MediaSessionServiceImpl* service) {
90 service_ = service;
91 }
92
86 void MediaSessionImpl::AddObserver(MediaSessionObserver* observer) { 93 void MediaSessionImpl::AddObserver(MediaSessionObserver* observer) {
87 observers_.AddObserver(observer); 94 observers_.AddObserver(observer);
88 } 95 }
89 96
90 void MediaSessionImpl::RemoveObserver(MediaSessionObserver* observer) { 97 void MediaSessionImpl::RemoveObserver(MediaSessionObserver* observer) {
91 observers_.RemoveObserver(observer); 98 observers_.RemoveObserver(observer);
92 } 99 }
93 100
94 void MediaSessionImpl::SetMetadata( 101 void MediaSessionImpl::SetMetadata(
95 const base::Optional<MediaMetadata>& metadata) { 102 const base::Optional<MediaMetadata>& metadata) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 254
248 if (audio_focus_state_ != State::SUSPENDED) 255 if (audio_focus_state_ != State::SUSPENDED)
249 OnSuspendInternal(suspend_type, State::SUSPENDED); 256 OnSuspendInternal(suspend_type, State::SUSPENDED);
250 257
251 DCHECK(audio_focus_state_ == State::SUSPENDED); 258 DCHECK(audio_focus_state_ == State::SUSPENDED);
252 players_.clear(); 259 players_.clear();
253 260
254 AbandonSystemAudioFocusIfNeeded(); 261 AbandonSystemAudioFocusIfNeeded();
255 } 262 }
256 263
264 void MediaSessionImpl::DidReceiveAction(
265 blink::mojom::MediaSessionAction action) {
266 if (service_)
267 service_->GetClient()->DidReceiveAction(action);
268 }
269
270 void MediaSessionImpl::OnMediaSessionEnabledAction(
271 blink::mojom::MediaSessionAction action) {
272 for (auto& observer : observers_)
273 observer.MediaSessionEnabledAction(action);
274 }
275
276 void MediaSessionImpl::OnMediaSessionDisabledAction(
277 blink::mojom::MediaSessionAction action) {
278 for (auto& observer : observers_)
279 observer.MediaSessionDisabledAction(action);
280 }
281
257 void MediaSessionImpl::StartDucking() { 282 void MediaSessionImpl::StartDucking() {
258 if (is_ducking_) 283 if (is_ducking_)
259 return; 284 return;
260 is_ducking_ = true; 285 is_ducking_ = true;
261 UpdateVolumeMultiplier(); 286 UpdateVolumeMultiplier();
262 } 287 }
263 288
264 void MediaSessionImpl::StopDucking() { 289 void MediaSessionImpl::StopDucking() {
265 if (!is_ducking_) 290 if (!is_ducking_)
266 return; 291 return;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 it.observer->OnSetVolumeMultiplier(it.player_id, GetVolumeMultiplier()); 417 it.observer->OnSetVolumeMultiplier(it.player_id, GetVolumeMultiplier());
393 418
394 UpdateWebContents(); 419 UpdateWebContents();
395 } 420 }
396 421
397 MediaSessionImpl::MediaSessionImpl(WebContents* web_contents) 422 MediaSessionImpl::MediaSessionImpl(WebContents* web_contents)
398 : WebContentsObserver(web_contents), 423 : WebContentsObserver(web_contents),
399 audio_focus_state_(State::INACTIVE), 424 audio_focus_state_(State::INACTIVE),
400 audio_focus_type_( 425 audio_focus_type_(
401 AudioFocusManager::AudioFocusType::GainTransientMayDuck), 426 AudioFocusManager::AudioFocusType::GainTransientMayDuck),
402 is_ducking_(false) { 427 is_ducking_(false),
428 service_(nullptr) {
403 #if defined(OS_ANDROID) 429 #if defined(OS_ANDROID)
404 session_android_.reset(new MediaSessionAndroid(this)); 430 session_android_.reset(new MediaSessionAndroid(this));
405 #endif // defined(OS_ANDROID) 431 #endif // defined(OS_ANDROID)
406 } 432 }
407 433
408 void MediaSessionImpl::Initialize() { 434 void MediaSessionImpl::Initialize() {
409 delegate_ = AudioFocusDelegate::Create(this); 435 delegate_ = AudioFocusDelegate::Create(this);
410 } 436 }
411 437
412 bool MediaSessionImpl::RequestSystemAudioFocus( 438 bool MediaSessionImpl::RequestSystemAudioFocus(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 DCHECK(success); 489 DCHECK(success);
464 490
465 pepper_players_.insert(PlayerIdentifier(observer, player_id)); 491 pepper_players_.insert(PlayerIdentifier(observer, player_id));
466 492
467 observer->OnSetVolumeMultiplier(player_id, GetVolumeMultiplier()); 493 observer->OnSetVolumeMultiplier(player_id, GetVolumeMultiplier());
468 494
469 return true; 495 return true;
470 } 496 }
471 497
472 } // namespace content 498 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/session/media_session_impl.h ('k') | content/browser/media/session/media_session_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698