Index: chrome/browser/media/router/mojo/media_route_controller.h |
diff --git a/chrome/browser/media/router/mojo/media_route_controller.h b/chrome/browser/media/router/mojo/media_route_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b45318bfeae0bbaed9446ea28d8db92a2edc3b4c |
--- /dev/null |
+++ b/chrome/browser/media/router/mojo/media_route_controller.h |
@@ -0,0 +1,79 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ |
+#define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ |
+ |
+#include <memory> |
+#include <unordered_set> |
+ |
+#include "chrome/browser/media/router/media_route.h" |
+#include "chrome/browser/media/router/media_status.h" |
+#include "chrome/browser/media/router/mojo/media_controller.mojom.h" |
+#include "mojo/public/cpp/bindings/binding.h" |
+ |
+namespace media_router { |
+ |
+namespace mojom { |
+class MediaRouteProvider; |
+} |
+ |
+class MediaRouteStatusObserver; |
+ |
+// A controller for a MediaRoute. Forwards commands for controlling the route to |
mark a. foltz
2017/03/06 20:06:19
This only controls media routes that are owned out
imcheng
2017/03/06 23:11:41
I think MediaRouteController is fine. The only par
takumif
2017/03/08 04:24:03
We can move the initialization to MRMojoImpl, and
mark a. foltz
2017/03/08 22:16:12
If the responsibility of the class is to implement
takumif
2017/03/09 19:45:30
I'm not sure if there is a need for this class to
|
+// the component-extension-side controller. Notifies its observers whenever |
+// there is a change in the route's MediaStatus. Gets destroyed when its |
+// connection to the extension-side controller is invalidated, the route is |
mark a. foltz
2017/03/06 20:06:19
Will this prevent the controller from persisting a
imcheng
2017/03/06 23:11:41
The event page does not suspend when there is at l
|
+// terminated, or the last observer of |this| is removed. |
mark a. foltz
2017/03/06 20:06:19
I still find the lifetime dependency between the c
imcheng
2017/03/06 23:11:41
This is a bit tricky because the controller can be
takumif
2017/03/08 04:24:02
The current design is that the event page is awake
mark a. foltz
2017/03/08 22:16:12
Okay, whichever design is settled upon, please upd
takumif
2017/03/09 19:45:30
Would it be better if we made the step to call the
mark a. foltz
2017/03/13 18:22:31
The API I was thinking of would always destroy the
|
+class MediaRouteController : public mojom::MediaStatusObserver { |
mark a. foltz
2017/03/06 20:06:19
Shouldn't this implement mojo::MediaController?
W
imcheng
2017/03/06 23:11:41
The extension side implements mojo::MediaControlle
takumif
2017/03/08 04:24:02
Given that this only receives commands from within
|
+ public: |
+ // Attempts to establish a mojo connection with the extension-side controller |
mark a. foltz
2017/03/06 20:06:19
s/extension-side controller/Media Route Provider/
takumif
2017/03/08 04:24:03
Removing mentions of extension/MRP.
|
+ // for |route_id|. |destroyer_callback| will be called if it fails. |
+ // |destroyer_callback| must destroy |this|. |
+ MediaRouteController(MediaRoute::Id route_id, |
+ mojom::MediaRouteProvider* provider, |
dcheng
2017/03/08 01:08:20
It's a bit unusual to pass around raw pointers to
takumif
2017/03/08 04:24:02
Removing this in the new patch.
|
+ base::Closure destroyer_callback); |
+ ~MediaRouteController() override; |
+ |
+ // Called when |media_controller_| gets bound. Calls |destroyer_callback_| if |
+ // |success| is false. |
+ void OnControllerSet(bool success); |
+ |
+ // Media controller methods for forwarding commands to the extension-side |
mark a. foltz
2017/03/06 20:06:19
...to the Media Route Provider.
takumif
2017/03/08 04:24:03
Removing mentions of extension/MRP.
|
+ // controller. |
+ void Play(); |
+ void Pause(); |
+ void Seek(uint32_t time); |
+ void SetMute(bool mute); |
+ void SetVolume(float volume); |
+ |
+ void AddObserver(MediaRouteStatusObserver* observer); |
mark a. foltz
2017/03/06 20:06:19
Please document which of the API override/implemen
takumif
2017/03/08 04:24:02
OnMediaStatusUpdated() is the only method.
|
+ // Calls |destroyer_callback_| if the last observer is removed. |
+ void RemoveObserver(MediaRouteStatusObserver* observer); |
+ |
+ // mojom::MediaStatusObserver: |
+ void OnMediaStatusUpdated(const MediaStatus& status) override; |
+ |
+ private: |
+ // Gets called when |this| should no longer exist. Needs to destroy |this|. |
+ base::Closure destroyer_callback_; |
dcheng
2017/03/08 01:08:19
This is pretty unusual. Where's the code that actu
takumif
2017/03/08 04:24:02
This is used by MediaRouterMojoImpl which will own
dcheng
2017/03/17 06:15:14
Unless we need to use a base::Callback for flexibi
takumif
2017/03/20 22:10:45
Okay, passing MediaRouterBase* (superclass of MRMo
|
+ |
+ // The extension-side controller that |this| forwards commands to. |
mark a. foltz
2017/03/06 20:06:19
Media Route Provider
takumif
2017/03/08 04:24:02
Removing mentions of extension/MRP.
|
+ mojom::MediaControllerPtr media_controller_; |
+ |
+ // The binding to observe the extension-side provider of status updates. |
mark a. foltz
2017/03/06 20:06:19
observe status updates from the Media Route Provid
takumif
2017/03/08 04:24:02
Removing mentions of extension/MRP.
|
+ std::unique_ptr<mojo::Binding<mojom::MediaStatusObserver>> binding_; |
dcheng
2017/03/08 01:08:20
unique_ptr is unnecessary here. In the initializer
takumif
2017/03/08 04:24:03
Done.
|
+ |
+ // Observers that |this| notifies of status updates. |
+ std::unordered_set<MediaRouteStatusObserver*> observers_; |
mark a. foltz
2017/03/06 20:06:19
base::ObserverList
takumif
2017/03/08 04:24:03
Done.
|
+ |
+ mojom::MediaRouteProvider* const provider_; |
mark a. foltz
2017/03/06 20:06:19
Who owns this? Please document
takumif
2017/03/08 04:24:02
Removed the reference.
|
+ |
+ // The ID of the Media Route that |this| controls. |
+ const MediaRoute::Id route_id_; |
+}; |
+ |
+} // namespace media_router |
+ |
+#endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTE_CONTROLLER_H_ |