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

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

Issue 2456783003: Let CastMediaBlocker observe MediaSession instead of WebContents [FOR TRY] (Closed)
Patch Set: fixed Linux build Created 4 years, 1 month 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
« no previous file with comments | « no previous file | chromecast/browser/cast_media_blocker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_ 5 #ifndef CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_
6 #define CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_ 6 #define CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/callback_forward.h" 9 #include "content/public/browser/media_session_observer.h"
10 #include "content/public/browser/web_contents_observer.h"
11
12 namespace content {
13 class WebContents;
14 } // namespace content
15 10
16 namespace chromecast { 11 namespace chromecast {
17 namespace shell { 12 namespace shell {
18 13
19 // This class implements a blocking mode for web applications and is used in 14 // This class implements a blocking mode for web applications and is used in
20 // Chromecast internal code. Media is unblocked by default. 15 // Chromecast internal code. Media is unblocked by default.
21 class CastMediaBlocker : public content::WebContentsObserver { 16 class CastMediaBlocker : public content::MediaSessionObserver {
22 public: 17 public:
23 explicit CastMediaBlocker(content::WebContents* web_contents); 18 explicit CastMediaBlocker(content::MediaSession* media_session);
24
25 // Constructor for test. |suspend_cb| and |resume_cb| will be called when
26 // Suspend() and Resume() are called.
27 CastMediaBlocker(content::WebContents* web_contents,
28 const base::Closure& suspend_cb,
29 const base::Closure& resume_cb);
30
31 ~CastMediaBlocker() override; 19 ~CastMediaBlocker() override;
32 20
33 // Sets if the web contents is allowed to play media or not. If media is 21 // Sets if the web contents is allowed to play media or not. If media is
34 // unblocked, previously suspended elements should begin playing again. 22 // unblocked, previously suspended elements should begin playing again.
35 void BlockMediaLoading(bool blocked); 23 void BlockMediaLoading(bool blocked);
36 24
37 // content::WebContentsObserver implementation: 25 // content::MediaSessionObserver implementation:
38 void MediaSessionStateChanged(bool is_controllable, 26 void MediaSessionStateChanged(bool is_controllable,
39 bool is_suspended) override; 27 bool is_suspended) override;
40 28
41 protected: 29 protected:
42 bool media_loading_blocked() const { return blocked_; } 30 bool media_loading_blocked() const { return blocked_; }
43 31
44 // Blocks or unblocks the render process from loading new media 32 // Blocks or unblocks the render process from loading new media
45 // according to |media_loading_blocked_|. 33 // according to |media_loading_blocked_|.
46 virtual void UpdateMediaBlockedState() {} 34 virtual void UpdateMediaBlockedState() {}
47 35
48 private: 36 private:
49 // Suspends or resumes the media session for the web contents. 37 // Suspends or resumes the media session for the web contents.
50 void Suspend(); 38 void Suspend();
51 void Resume(); 39 void Resume();
52 40
53 base::Closure suspend_cb_;
54 base::Closure resume_cb_;
55
56 // Whether or not media should be blocked. This value cache's the last call to 41 // Whether or not media should be blocked. This value cache's the last call to
57 // BlockMediaLoading. Is false by default. 42 // BlockMediaLoading. Is false by default.
58 bool blocked_; 43 bool blocked_;
59 44
60 // Whether or not the user paused media on the page. 45 // Whether or not the user paused media on the page.
61 bool paused_by_user_; 46 bool paused_by_user_;
62 47
63 // Whether or not media in the app can be controlled and if media is currently 48 // Whether or not media in the app can be controlled and if media is currently
64 // suspended. These variables cache arguments from MediaSessionStateChanged(). 49 // suspended. These variables cache arguments from MediaSessionStateChanged().
65 bool suspended_; 50 bool suspended_;
66 bool controllable_; 51 bool controllable_;
67 52
68 DISALLOW_COPY_AND_ASSIGN(CastMediaBlocker); 53 DISALLOW_COPY_AND_ASSIGN(CastMediaBlocker);
69 }; 54 };
70 55
71 } // namespace shell 56 } // namespace shell
72 } // namespace chromecast 57 } // namespace chromecast
73 58
74 #endif // CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_ 59 #endif // CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_
OLDNEW
« no previous file with comments | « no previous file | chromecast/browser/cast_media_blocker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698