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 "chromecast/browser/cast_media_blocker.h" | |
| 6 | |
| 7 #include "base/threading/thread_checker.h" | |
| 8 #include "content/public/browser/web_contents.h" | |
| 9 | |
| 10 namespace chromecast { | |
| 11 namespace shell { | |
| 12 | |
| 13 CastMediaBlocker::CastMediaBlocker(content::WebContents* web_contents) | |
| 14 : content::WebContentsObserver(web_contents), | |
| 15 controllable_(false), | |
| 16 suspended_(false), | |
| 17 state_(UNBLOCKED) {} | |
| 18 | |
| 19 CastMediaBlocker::~CastMediaBlocker() {} | |
| 20 | |
| 21 void CastMediaBlocker::BlockMediaLoading(bool blocked) { | |
| 22 if (blocked) { | |
| 23 state_ = BLOCKED; | |
| 24 } else { | |
| 25 state_ = (state_ == UNBLOCKED ? UNBLOCKED : UNBLOCKING); | |
|
byungchul
2016/09/14 02:20:17
why not just:
} else if (state_ == BLOCKED) {
s
derekjchow1
2016/09/14 20:33:12
Done.
| |
| 26 } | |
| 27 | |
| 28 UpdateMediaBlockedState(); | |
| 29 } | |
| 30 | |
| 31 void CastMediaBlocker::UpdateMediaBlockedState() { | |
| 32 if (!web_contents()) { | |
| 33 return; | |
| 34 } | |
| 35 | |
| 36 if (!controllable_) { | |
| 37 return; | |
| 38 } | |
| 39 | |
| 40 if (state_ == BLOCKED && !suspended_) { | |
| 41 web_contents()->SuspendMediaSession(); | |
| 42 } | |
| 43 | |
| 44 if (state_ == UNBLOCKING && suspended_) { | |
|
byungchul
2016/09/14 02:20:17
else if?
derekjchow1
2016/09/14 20:33:13
Done.
| |
| 45 web_contents()->ResumeMediaSession(); | |
| 46 state_ = UNBLOCKED; | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 void CastMediaBlocker::MediaSessionStateChanged( | |
| 51 bool is_controllable, | |
| 52 bool is_suspended, | |
| 53 const base::Optional<content::MediaMetadata>& metadata) { | |
| 54 controllable_ = is_controllable; | |
| 55 suspended_ = is_suspended; | |
| 56 UpdateMediaBlockedState(); | |
| 57 } | |
| 58 | |
| 59 } // namespace shell | |
| 60 } // namespace chromecast | |
| OLD | NEW |