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

Side by Side Diff: chromecast/browser/cast_media_blocker.cc

Issue 2360443002: [Chromecast] Add CastMediaBlocker and BrowserTest (Closed)
Patch Set: use [] for optional query param Created 4 years, 3 months 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
(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 if (state_ == BLOCKED) {
25 state_ = suspended_ ? UNBLOCKING : UNBLOCKED;
26 } else {
27 return;
28 }
29
30 UpdateMediaBlockedState();
31 }
32
33 void CastMediaBlocker::UpdateMediaBlockedState() {
34 if (!web_contents()) {
35 return;
36 }
37
38 if (!controllable_) {
39 return;
40 }
41
42 if (state_ == BLOCKED && !suspended_) {
43 web_contents()->SuspendMediaSession();
44 } else if (state_ == UNBLOCKING && suspended_) {
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
OLDNEW
« no previous file with comments | « chromecast/browser/cast_media_blocker.h ('k') | chromecast/browser/test/chromecast_browser_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698