Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <unordered_set> | |
| 10 | |
| 11 #include "base/observer_list.h" | |
| 12 #include "chrome/browser/media/router/media_route.h" | |
| 13 #include "chrome/browser/media/router/media_status.h" | |
| 14 #include "chrome/browser/media/router/mojo/media_controller.mojom.h" | |
| 15 #include "mojo/public/cpp/bindings/binding.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class TimeDelta; | |
| 19 } | |
| 20 | |
| 21 namespace media_router { | |
| 22 | |
| 23 class MediaRouteStatusObserver; | |
| 24 | |
| 25 // A controller for a MediaRoute. Forwards commands for controlling the route to | |
| 26 // an out-of-process controller. Notifies its observers whenever there is a | |
| 27 // change in the route's MediaStatus. Gets destroyed when the route is | |
| 28 // terminated or the last observer of |this| is removed. | |
| 29 class MediaRouteController : public mojom::MediaStatusObserver { | |
|
mark a. foltz
2017/03/13 18:22:31
What would use this class? I thought that the con
| |
| 30 public: | |
| 31 // |this| will forward media commands to |media_controller|. | |
| 32 // |destroyer_callback| will be called when the last observer of |this| is | |
| 33 // removed. |destroyer_callback| must destroy |this|. | |
| 34 MediaRouteController(mojom::MediaControllerPtr media_controller, | |
| 35 base::Closure destroyer_callback); | |
| 36 ~MediaRouteController() override; | |
| 37 | |
| 38 // Media controller methods for forwarding commands to |media_controller_|. | |
| 39 void Play(); | |
| 40 void Pause(); | |
| 41 void Seek(base::TimeDelta time); | |
| 42 void SetMute(bool mute); | |
| 43 void SetVolume(float volume); | |
| 44 | |
| 45 void AddObserver(MediaRouteStatusObserver* observer); | |
| 46 // Calls |destroyer_callback_| if the last observer is removed. | |
| 47 void RemoveObserver(MediaRouteStatusObserver* observer); | |
| 48 | |
| 49 // mojom::MediaStatusObserver: | |
| 50 void OnMediaStatusUpdated(const MediaStatus& status) override; | |
| 51 | |
| 52 // Returns a mojo pointer bound to |this| by |binding_|. If |binding_| is | |
| 53 // already set, then the previous binding gets invalidated. | |
| 54 mojom::MediaStatusObserverPtr GetObserverPtr(); | |
| 55 | |
| 56 private: | |
| 57 // Gets called when |this| should no longer exist. Needs to destroy |this|. | |
| 58 base::Closure destroyer_callback_; | |
| 59 | |
| 60 // The out-of-process controller that |this| forwards commands to. | |
| 61 mojom::MediaControllerPtr media_controller_; | |
| 62 | |
| 63 // The binding to observe the out-of-process provider of status updates. | |
| 64 mojo::Binding<mojom::MediaStatusObserver> binding_; | |
| 65 | |
| 66 // Observers that |this| notifies of status updates. | |
| 67 base::ObserverList<MediaRouteStatusObserver> observers_; | |
| 68 }; | |
| 69 | |
| 70 } // namespace media_router | |
| 71 | |
| 72 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ | |
| OLD | NEW |