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

Side by Side Diff: chrome/browser/media/router/mojo/media_route_controller.h

Issue 2728543009: [Media Router] Custom Controls 2 - add MediaRouter::GetRouteController() (Closed)
Patch Set: Address Mark's comments Created 3 years, 8 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "chrome/browser/media/router/media_route.h" 12 #include "chrome/browser/media/router/media_route.h"
13 #include "chrome/browser/media/router/mojo/media_controller.mojom.h" 13 #include "chrome/browser/media/router/mojo/media_controller.mojom.h"
14 #include "mojo/public/cpp/bindings/binding.h" 14 #include "mojo/public/cpp/bindings/binding.h"
15 15
16 namespace media_router { 16 namespace media_router {
17 17
18 class MediaRouter;
19
18 // A controller for a MediaRoute. Forwards commands for controlling the route to 20 // A controller for a MediaRoute. Forwards commands for controlling the route to
19 // an out-of-process controller. Notifies its observers whenever there is a 21 // an out-of-process controller. Notifies its observers whenever there is a
20 // change in the route's MediaStatus. 22 // change in the route's MediaStatus.
21 // 23 //
22 // It is owned by its observers, each of which holds a scoped_refptr to it. All 24 // It is owned by its observers, each of which holds a scoped_refptr to it. All
23 // the classes that hold a scoped_refptr must inherit from the Observer class. 25 // the classes that hold a scoped_refptr must inherit from the Observer class.
24 // An observer should be instantiated with a scoped_refptr obtained through 26 // An observer should be instantiated with a scoped_refptr obtained through
25 // MediaRouter::GetRouteController(). 27 // MediaRouter::GetRouteController().
26 // 28 //
27 // A MediaRouteController instance is destroyed when all its observers dispose 29 // A MediaRouteController instance is destroyed when all its observers dispose
(...skipping 30 matching lines...) Expand all
58 60
59 // Called by InvalidateController() after the reference to the controller is 61 // Called by InvalidateController() after the reference to the controller is
60 // disposed. Overridden by subclasses to do custom cleanup. 62 // disposed. Overridden by subclasses to do custom cleanup.
61 virtual void OnControllerInvalidated(); 63 virtual void OnControllerInvalidated();
62 64
63 scoped_refptr<MediaRouteController> controller_; 65 scoped_refptr<MediaRouteController> controller_;
64 66
65 DISALLOW_COPY_AND_ASSIGN(Observer); 67 DISALLOW_COPY_AND_ASSIGN(Observer);
66 }; 68 };
67 69
68 // Constructs a MediaRouteController that forwards media commands to 70 // |media_router| will be notified when the MediaRouteController is destroyed.
69 // |media_controller|. |media_controller| must be bound to a message pipe.
70 MediaRouteController(const MediaRoute::Id& route_id, 71 MediaRouteController(const MediaRoute::Id& route_id,
71 mojom::MediaControllerPtr media_controller); 72 MediaRouter* media_router);
72 73
73 // Media controller methods for forwarding commands to a 74 // Media controller methods for forwarding commands to a
74 // mojom::MediaControllerPtr held in |media_controller_|. 75 // mojom::MediaControllerPtr held in |mojo_media_controller_|.
75 void Play(); 76 void Play();
76 void Pause(); 77 void Pause();
77 void Seek(base::TimeDelta time); 78 void Seek(base::TimeDelta time);
78 void SetMute(bool mute); 79 void SetMute(bool mute);
79 void SetVolume(float volume); 80 void SetVolume(float volume);
80 81
81 // mojom::MediaStatusObserver: 82 // mojom::MediaStatusObserver:
82 // Notifies |observers_| of a status update. 83 // Notifies |observers_| of a status update.
83 void OnMediaStatusUpdated(const MediaStatus& status) override; 84 void OnMediaStatusUpdated(const MediaStatus& status) override;
84 85
85 // Called when the connection between |this| and |media_controller_| is no 86 // Called when the connection between |this| and |mojo_media_controller_| is
86 // longer valid. Notifies |observers_| to dispose their references to |this|. 87 // no longer valid. Notifies |media_router_| and |observers_| to dispose their
87 // |this| gets destroyed when all the references are disposed. 88 // references to |this|. |this| gets destroyed when all the references are
89 // disposed.
88 void Invalidate(); 90 void Invalidate();
89 91
92 // Called when the media route that |this| controls is invalidated. Notifies
93 // |observers_| (but not |media_router_| to dispose their references to
94 // |this|. |this| gets destroyed when all the references are disposed.
95 void OnRouteInvalid();
96
97 // Returns a mojo pointer bound to |this| by |binding_|. This must only be
98 // called at most once in the lifetime of |this|.
imcheng 2017/04/06 21:14:04 Did you mean to revert the "must only be called on
takumif 2017/04/12 23:11:36 No, putting it back.
99 mojom::MediaStatusObserverPtr BindObserverPtr();
100
101 // Gets a Mojo request bound to |mojo_media_controller_|. This must only be
102 // called at most once in the lifetime of |this|.
103 mojom::MediaControllerRequest GetMediaControllerRequest();
104
90 MediaRoute::Id route_id() const { return route_id_; } 105 MediaRoute::Id route_id() const { return route_id_; }
91 106
92 private: 107 private:
93 friend class base::RefCounted<MediaRouteController>; 108 friend class base::RefCounted<MediaRouteController>;
94 109
95 ~MediaRouteController() override; 110 ~MediaRouteController() override;
96 111
97 void AddObserver(Observer* observer); 112 void AddObserver(Observer* observer);
98 void RemoveObserver(Observer* observer); 113 void RemoveObserver(Observer* observer);
99 114
100 // The ID of the Media Route that |this| controls. 115 // The ID of the Media Route that |this| controls.
101 const MediaRoute::Id route_id_; 116 const MediaRoute::Id route_id_;
102 117
103 // Handle to the mojom::MediaController that receives media commands. 118 // Handle to the mojom::MediaController that receives media commands.
104 mojom::MediaControllerPtr media_controller_; 119 mojom::MediaControllerPtr mojo_media_controller_;
120
121 // |media_router_| will be notified when |this| is destroyed.
122 MediaRouter* const media_router_;
123
124 // The binding to observe the out-of-process provider of status updates.
125 mojo::Binding<mojom::MediaStatusObserver> binding_;
105 126
106 // Observers that |this| notifies of status updates. The observers share the 127 // Observers that |this| notifies of status updates. The observers share the
107 // ownership of |this| through scoped_refptr. 128 // ownership of |this| through scoped_refptr.
108 base::ObserverList<Observer> observers_; 129 base::ObserverList<Observer> observers_;
109 130
131 // This becomes false when |this| is invalidated.
132 bool is_valid_ = true;
133
110 DISALLOW_COPY_AND_ASSIGN(MediaRouteController); 134 DISALLOW_COPY_AND_ASSIGN(MediaRouteController);
111 }; 135 };
112 136
113 } // namespace media_router 137 } // namespace media_router
114 138
115 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ 139 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698