Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 28 // their references to it. When the Mojo connection with the out-of-process | 30 // their references to it. When the Mojo connection with the out-of-process |
| 29 // controller is terminated or has an error, OnControllerInvalidated() will be | 31 // controller is terminated or has an error, OnControllerInvalidated() will be |
|
imcheng
2017/04/06 21:14:04
s/OnControllerInvalidated/Invalidate
takumif
2017/04/07 21:07:55
Done.
| |
| 30 // called by the MediaRouter or a Mojo error handler to make observers dispose | 32 // called by the MediaRouter or a Mojo error handler to make observers dispose |
|
imcheng
2017/04/06 21:14:04
s/a Mojo error handler/OnMojoConnectionError()
takumif
2017/04/07 21:07:55
Done.
| |
| 31 // their refptrs. | 33 // their refptrs. |
| 32 class MediaRouteController : public mojom::MediaStatusObserver, | 34 class MediaRouteController : public mojom::MediaStatusObserver, |
| 33 public base::RefCounted<MediaRouteController> { | 35 public base::RefCounted<MediaRouteController> { |
| 34 public: | 36 public: |
| 35 // Observes MediaRouteController for MediaStatus updates. The ownership of a | 37 // Observes MediaRouteController for MediaStatus updates. The ownership of a |
| 36 // MediaRouteController is shared by its observers. | 38 // MediaRouteController is shared by its observers. |
| 37 class Observer { | 39 class Observer { |
| 38 public: | 40 public: |
| 39 // Adds itself as an observer to |controller|. | 41 // Adds itself as an observer to |controller|. |
| 40 explicit Observer(scoped_refptr<MediaRouteController> controller); | 42 explicit Observer(scoped_refptr<MediaRouteController> controller); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 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 // Constructs a MediaRouteController that forwards media commands to |
| 69 // |media_controller|. |media_controller| must be bound to a message pipe. | 71 // |mojo_media_controller|. |mojo_media_controller| must be bound to a message |
| 72 // pipe. |media_router| will be notified when the MediaRouteController is | |
| 73 // destroyed. | |
| 70 MediaRouteController(const MediaRoute::Id& route_id, | 74 MediaRouteController(const MediaRoute::Id& route_id, |
| 71 mojom::MediaControllerPtr media_controller); | 75 mojom::MediaControllerPtr mojo_media_controller, |
| 76 MediaRouter* media_router); | |
| 72 | 77 |
| 73 // Media controller methods for forwarding commands to a | 78 // Media controller methods for forwarding commands to a |
| 74 // mojom::MediaControllerPtr held in |media_controller_|. | 79 // mojom::MediaControllerPtr held in |mojo_media_controller_|. |
| 75 void Play(); | 80 void Play(); |
| 76 void Pause(); | 81 void Pause(); |
| 77 void Seek(base::TimeDelta time); | 82 void Seek(base::TimeDelta time); |
| 78 void SetMute(bool mute); | 83 void SetMute(bool mute); |
| 79 void SetVolume(float volume); | 84 void SetVolume(float volume); |
| 80 | 85 |
| 81 // mojom::MediaStatusObserver: | 86 // mojom::MediaStatusObserver: |
| 82 // Notifies |observers_| of a status update. | 87 // Notifies |observers_| of a status update. |
| 83 void OnMediaStatusUpdated(const MediaStatus& status) override; | 88 void OnMediaStatusUpdated(const MediaStatus& status) override; |
| 84 | 89 |
| 85 // Called when the connection between |this| and |media_controller_| is no | 90 // Notifies |observers_| to dispose their references to |this|. |this| gets |
| 86 // longer valid. Notifies |observers_| to dispose their references to |this|. | 91 // destroyed when all the references are disposed. |
| 87 // |this| gets destroyed when all the references are disposed. | |
| 88 void Invalidate(); | 92 void Invalidate(); |
| 89 | 93 |
| 94 // Returns a mojo pointer bound to |this| by |binding_|. If |binding_| is | |
| 95 // already set, then the previous binding gets invalidated. | |
| 96 mojom::MediaStatusObserverPtr BindObserverPtr(); | |
| 97 | |
| 90 MediaRoute::Id route_id() const { return route_id_; } | 98 MediaRoute::Id route_id() const { return route_id_; } |
| 91 | 99 |
| 92 private: | 100 private: |
| 93 friend class base::RefCounted<MediaRouteController>; | 101 friend class base::RefCounted<MediaRouteController>; |
| 94 | 102 |
| 95 ~MediaRouteController() override; | 103 ~MediaRouteController() override; |
| 96 | 104 |
| 97 void AddObserver(Observer* observer); | 105 void AddObserver(Observer* observer); |
| 98 void RemoveObserver(Observer* observer); | 106 void RemoveObserver(Observer* observer); |
| 99 | 107 |
| 108 // Called when the connection between |this| and the mojo MediaController or | |
| 109 // the mojo MediaStatus provider is no longer valid. Notifies |media_router_| | |
| 110 // and |observers_| to dispose their references to |this|. |this| gets | |
|
imcheng
2017/04/06 21:14:04
I don't think you need the last sentence. It's alr
takumif
2017/04/07 21:07:55
Removed.
| |
| 111 // destroyed when all the references are disposed. | |
| 112 void OnMojoConnectionError(); | |
| 113 | |
| 100 // The ID of the Media Route that |this| controls. | 114 // The ID of the Media Route that |this| controls. |
| 101 const MediaRoute::Id route_id_; | 115 const MediaRoute::Id route_id_; |
| 102 | 116 |
| 103 // Handle to the mojom::MediaController that receives media commands. | 117 // Handle to the mojom::MediaController that receives media commands. |
| 104 mojom::MediaControllerPtr media_controller_; | 118 mojom::MediaControllerPtr mojo_media_controller_; |
| 119 | |
| 120 // |media_router_| will be notified when |this| is destroyed. | |
| 121 MediaRouter* const media_router_; | |
| 122 | |
| 123 // The binding to observe the out-of-process provider of status updates. | |
| 124 mojo::Binding<mojom::MediaStatusObserver> binding_; | |
| 105 | 125 |
| 106 // Observers that |this| notifies of status updates. The observers share the | 126 // Observers that |this| notifies of status updates. The observers share the |
| 107 // ownership of |this| through scoped_refptr. | 127 // ownership of |this| through scoped_refptr. |
| 108 base::ObserverList<Observer> observers_; | 128 base::ObserverList<Observer> observers_; |
| 109 | 129 |
| 130 // This becomes false when |this| is invalidated. | |
| 131 bool is_valid_ = true; | |
| 132 | |
| 110 DISALLOW_COPY_AND_ASSIGN(MediaRouteController); | 133 DISALLOW_COPY_AND_ASSIGN(MediaRouteController); |
| 111 }; | 134 }; |
| 112 | 135 |
| 113 } // namespace media_router | 136 } // namespace media_router |
| 114 | 137 |
| 115 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ | 138 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ |
| OLD | NEW |