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

Unified Diff: chromecast/browser/cast_media_blocker.cc

Issue 2330243002: Add CastMediaBlocker and BrowserTest (Closed)
Patch Set: Use if-else 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/browser/cast_media_blocker.cc
diff --git a/chromecast/browser/cast_media_blocker.cc b/chromecast/browser/cast_media_blocker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e0cf795514fe9e957147df4a2cf633eb43785d55
--- /dev/null
+++ b/chromecast/browser/cast_media_blocker.cc
@@ -0,0 +1,58 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromecast/browser/cast_media_blocker.h"
+
+#include "base/threading/thread_checker.h"
+#include "content/public/browser/web_contents.h"
+
+namespace chromecast {
+namespace shell {
+
+CastMediaBlocker::CastMediaBlocker(content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents),
+ controllable_(false),
+ suspended_(false),
+ state_(UNBLOCKED) {}
+
+CastMediaBlocker::~CastMediaBlocker() {}
+
+void CastMediaBlocker::BlockMediaLoading(bool blocked) {
+ if (blocked) {
+ state_ = BLOCKED;
+ } else if (state_ == BLOCKED) {
+ state_ = UNBLOCKING;
+ }
+
+ UpdateMediaBlockedState();
+}
+
+void CastMediaBlocker::UpdateMediaBlockedState() {
+ if (!web_contents()) {
+ return;
+ }
+
+ if (!controllable_) {
+ return;
+ }
+
+ if (state_ == BLOCKED && !suspended_) {
+ web_contents()->SuspendMediaSession();
+ } else if (state_ == UNBLOCKING && suspended_) {
+ web_contents()->ResumeMediaSession();
+ state_ = UNBLOCKED;
+ }
+}
+
+void CastMediaBlocker::MediaSessionStateChanged(
+ bool is_controllable,
+ bool is_suspended,
+ const base::Optional<content::MediaMetadata>& metadata) {
+ controllable_ = is_controllable;
+ suspended_ = is_suspended;
+ UpdateMediaBlockedState();
+}
+
+} // namespace shell
+} // namespace chromecast
« 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