Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/media/android/media_session_controller.h" | |
| 6 | |
| 7 #include "content/browser/media/android/media_session.h" | |
| 8 #include "content/common/frame_messages.h" | |
| 9 #include "content/public/browser/render_frame_host.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 MediaSessionController::MediaSessionController( | |
| 14 const WebContentsObserver::MediaPlayerId& id, | |
| 15 MediaWebContentsObserver* media_web_contents_observer) | |
| 16 : id_(id), media_web_contents_observer_(media_web_contents_observer) {} | |
| 17 | |
| 18 // Clients must call this after construction and destroy the controller if it | |
| 19 // returns false. | |
| 20 bool MediaSessionController::Initialize(bool has_audio, | |
| 21 bool is_remote, | |
| 22 base::TimeDelta duration) { | |
| 23 // These objects are only created on the UI thread, so this is safe. | |
|
mlamouri (slow - plz ping)
2016/01/22 16:58:31
`DCHECK_CURRENTLY_ON(BrowserThread::UI);` or it's
DaleCurtis
2016/01/23 02:10:59
Done.
| |
| 24 static uint32_t player_id = 0; | |
| 25 player_id_ = static_cast<int>(player_id++); | |
| 26 has_audio_ = has_audio; | |
| 27 | |
| 28 // Don't bother with a MediaSession for remote players or without audio. | |
| 29 if (!has_audio || is_remote) | |
| 30 return true; | |
| 31 | |
| 32 const MediaSession::Type media_session_type = | |
| 33 duration == base::TimeDelta() || | |
| 34 duration > | |
| 35 base::TimeDelta::FromSeconds(kMinimumDurationForContentSecs) | |
| 36 ? MediaSession::Type::Content | |
| 37 : MediaSession::Type::Transient; | |
| 38 | |
| 39 // If a session can't be created, force a pause immediately. | |
| 40 if (!MediaSession::Get(media_web_contents_observer_->web_contents()) | |
| 41 ->AddPlayer(this, player_id_, media_session_type)) { | |
| 42 OnSuspend(player_id_); | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 initialized_ = true; | |
| 47 return true; | |
| 48 } | |
| 49 | |
| 50 MediaSessionController::~MediaSessionController() { | |
|
mlamouri (slow - plz ping)
2016/01/22 16:58:31
style: keep implementations in the same order as t
DaleCurtis
2016/01/23 02:10:59
Done.
| |
| 51 if (initialized_) { | |
|
mlamouri (slow - plz ping)
2016/01/22 16:58:31
nit:
```
if (!initialized_)
return;
// do stuff
DaleCurtis
2016/01/23 02:10:59
Done.
| |
| 52 MediaSession::Get(media_web_contents_observer_->web_contents()) | |
| 53 ->RemovePlayer(this, player_id_); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void MediaSessionController::OnSuspend(int player_id) { | |
| 58 DCHECK_EQ(player_id_, player_id); | |
| 59 media_web_contents_observer_->Send( | |
| 60 new FrameMsg_MediaDelegatePause(id_.first->GetRoutingID(), id_.second)); | |
| 61 } | |
| 62 | |
| 63 void MediaSessionController::OnResume(int player_id) { | |
| 64 DCHECK_EQ(player_id_, player_id); | |
| 65 media_web_contents_observer_->Send( | |
| 66 new FrameMsg_MediaDelegatePlay(id_.first->GetRoutingID(), id_.second)); | |
| 67 } | |
| 68 | |
| 69 void MediaSessionController::OnSetVolumeMultiplier(int player_id, | |
| 70 double volume_multiplier) { | |
| 71 DCHECK_EQ(player_id_, player_id); | |
| 72 media_web_contents_observer_->Send( | |
| 73 new FrameMsg_MediaDelegateVolumeMultiplierUpdate( | |
| 74 id_.first->GetRoutingID(), id_.second, volume_multiplier)); | |
| 75 } | |
| 76 | |
| 77 void MediaSessionController::PausePlayback() { | |
| 78 MediaSession* session = | |
| 79 MediaSession::Get(media_web_contents_observer_->web_contents()); | |
| 80 // We check for suspension here since the renderer may issue its own pause | |
| 81 // in response to or while a pause from the browser is in flight. | |
| 82 if (!session->IsSuspended()) | |
| 83 session->OnPlayerPaused(this, player_id_); | |
| 84 } | |
| 85 | |
| 86 } // namespace content | |
| OLD | NEW |