Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "chromecast/browser/cast_media_blocker.h" | 5 #include "chromecast/browser/cast_media_blocker.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/bind.h" |
| 8 #include "base/threading/thread_checker.h" | 8 #include "base/threading/thread_checker.h" |
| 9 #include "content/public/browser/media_session.h" | |
| 9 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 10 | 11 |
| 11 namespace chromecast { | 12 namespace chromecast { |
| 12 namespace shell { | 13 namespace shell { |
| 13 | 14 |
| 14 CastMediaBlocker::CastMediaBlocker(content::WebContents* web_contents) | 15 CastMediaBlocker::CastMediaBlocker(content::MediaSession* media_session) |
| 15 : CastMediaBlocker::CastMediaBlocker( | 16 : CastMediaBlocker::CastMediaBlocker( |
| 16 web_contents, | 17 media_session, |
|
derekjchow1
2016/10/24 18:50:33
How is a content embedder supposed to obtain a ref
Zhiqiang Zhang (Slow)
2016/10/28 10:36:52
Yes, it is 1-1 mapping.
You can use MediaSession::
| |
| 17 base::Bind(&CastMediaBlocker::Suspend, base::Unretained(this)), | 18 base::Bind(&CastMediaBlocker::Suspend, base::Unretained(this)), |
| 18 base::Bind(&CastMediaBlocker::Resume, base::Unretained(this))) {} | 19 base::Bind(&CastMediaBlocker::Resume, base::Unretained(this))) {} |
|
Zhiqiang Zhang (Slow)
2016/10/24 18:29:32
Are these callbacks used for testing?
After we exp
derekjchow1
2016/10/24 18:50:33
Correct. Your approach SGTM. We can probably remov
Zhiqiang Zhang (Slow)
2016/10/28 10:36:52
Done removing the callbacks. See the tests for det
| |
| 19 | 20 |
| 20 CastMediaBlocker::CastMediaBlocker(content::WebContents* web_contents, | 21 CastMediaBlocker::CastMediaBlocker(content::MediaSession* media_session, |
| 21 const base::Closure& suspend_cb, | 22 const base::Closure& suspend_cb, |
| 22 const base::Closure& resume_cb) | 23 const base::Closure& resume_cb) |
| 23 : content::WebContentsObserver(web_contents), | 24 : content::MediaSessionObserver(media_session), |
| 24 suspend_cb_(suspend_cb), | 25 suspend_cb_(suspend_cb), |
| 25 resume_cb_(resume_cb), | 26 resume_cb_(resume_cb), |
| 26 blocked_(false), | 27 blocked_(false), |
| 27 paused_by_user_(true), | 28 paused_by_user_(true), |
| 28 suspended_(true), | 29 suspended_(true), |
| 29 controllable_(false) {} | 30 controllable_(false) {} |
| 30 | 31 |
| 31 CastMediaBlocker::~CastMediaBlocker() {} | 32 CastMediaBlocker::~CastMediaBlocker() {} |
| 32 | 33 |
| 33 void CastMediaBlocker::BlockMediaLoading(bool blocked) { | 34 void CastMediaBlocker::BlockMediaLoading(bool blocked) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 suspend_cb_.Run(); | 95 suspend_cb_.Run(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 // If not blocking, cache the user's play intent. | 98 // If not blocking, cache the user's play intent. |
| 98 if (!blocked_) | 99 if (!blocked_) |
| 99 paused_by_user_ = suspended_; | 100 paused_by_user_ = suspended_; |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 103 void CastMediaBlocker::Suspend() { | 104 void CastMediaBlocker::Suspend() { |
| 104 if (!web_contents()) | 105 if (!media_session()) |
| 105 return; | 106 return; |
| 106 | 107 |
| 107 LOG(INFO) << "Suspending media session."; | 108 LOG(INFO) << "Suspending media session."; |
| 108 web_contents()->SuspendMediaSession(); | 109 media_session()->Suspend(content::MediaSession::SuspendType::SYSTEM); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void CastMediaBlocker::Resume() { | 112 void CastMediaBlocker::Resume() { |
| 112 if (!web_contents()) | 113 if (!media_session()) |
| 113 return; | 114 return; |
| 114 | 115 |
| 115 LOG(INFO) << "Resuming media session."; | 116 LOG(INFO) << "Resuming media session."; |
| 116 web_contents()->ResumeMediaSession(); | 117 media_session()->Resume(content::MediaSession::SuspendType::SYSTEM); |
| 117 } | 118 } |
| 118 | 119 |
| 119 } // namespace shell | 120 } // namespace shell |
| 120 } // namespace chromecast | 121 } // namespace chromecast |
| OLD | NEW |