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

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

Issue 2453623003: Decouple MediaSession messages from WebContents (full patch) (Closed)
Patch Set: nit 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
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" 10 #include "content/public/browser/web_contents_observer.h"
11 11
12 namespace content {
13 class WebContents;
14 } // namespace content
15
16 namespace chromecast { 12 namespace chromecast {
17 namespace shell { 13 namespace shell {
18 14
19 // This class implements a blocking mode for web applications and is used in 15 // This class implements a blocking mode for web applications and is used in
20 // Chromecast internal code. Media is unblocked by default. 16 // Chromecast internal code. Media is unblocked by default.
21 class CastMediaBlocker : public content::WebContentsObserver { 17 //
18 // TODO(derekjchow): Remove the inheritance from WebContentsObserver.
19 // See http://crbug.com/660331
20 class CastMediaBlocker : public content::MediaSessionObserver,
21 content::WebContentsObserver {
22 public: 22 public:
23 explicit CastMediaBlocker(content::WebContents* web_contents); 23 CastMediaBlocker(content::MediaSession* media_session,
24 24 content::WebContents* web_contents);
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; 25 ~CastMediaBlocker() override;
32 26
33 // Sets if the web contents is allowed to play media or not. If media is 27 // Sets if the web contents is allowed to play media or not. If media is
34 // unblocked, previously suspended elements should begin playing again. 28 // unblocked, previously suspended elements should begin playing again.
35 void BlockMediaLoading(bool blocked); 29 void BlockMediaLoading(bool blocked);
36 30
37 // content::WebContentsObserver implementation: 31 // content::MediaSessionObserver implementation:
38 void MediaSessionStateChanged(bool is_controllable, 32 void MediaSessionStateChanged(bool is_controllable,
39 bool is_suspended) override; 33 bool is_suspended) override;
40 34
41 protected: 35 protected:
42 bool media_loading_blocked() const { return blocked_; } 36 bool media_loading_blocked() const { return blocked_; }
43 37
44 // Blocks or unblocks the render process from loading new media 38 // Blocks or unblocks the render process from loading new media
45 // according to |media_loading_blocked_|. 39 // according to |media_loading_blocked_|.
46 virtual void UpdateMediaBlockedState() {} 40 virtual void UpdateMediaBlockedState() {}
47 41
48 private: 42 private:
49 // Suspends or resumes the media session for the web contents. 43 // Suspends or resumes the media session for the web contents.
50 void Suspend(); 44 void Suspend();
51 void Resume(); 45 void Resume();
52 46
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 47 // Whether or not media should be blocked. This value cache's the last call to
57 // BlockMediaLoading. Is false by default. 48 // BlockMediaLoading. Is false by default.
58 bool blocked_; 49 bool blocked_;
59 50
60 // Whether or not the user paused media on the page. 51 // Whether or not the user paused media on the page.
61 bool paused_by_user_; 52 bool paused_by_user_;
62 53
63 // Whether or not media in the app can be controlled and if media is currently 54 // Whether or not media in the app can be controlled and if media is currently
64 // suspended. These variables cache arguments from MediaSessionStateChanged(). 55 // suspended. These variables cache arguments from MediaSessionStateChanged().
65 bool suspended_; 56 bool suspended_;
66 bool controllable_; 57 bool controllable_;
67 58
68 DISALLOW_COPY_AND_ASSIGN(CastMediaBlocker); 59 DISALLOW_COPY_AND_ASSIGN(CastMediaBlocker);
69 }; 60 };
70 61
71 } // namespace shell 62 } // namespace shell
72 } // namespace chromecast 63 } // namespace chromecast
73 64
74 #endif // CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_ 65 #endif // CHROMECAST_BROWSER_CAST_MEDIA_BLOCKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698