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

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

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