Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_MEDIA_ROUTER_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "chrome/browser/media/router/media_route_id.h" | |
| 13 #include "chrome/browser/media/router/media_sink.h" | |
| 14 | |
| 15 namespace media_router { | |
| 16 | |
| 17 class MediaRoute; | |
| 18 class MediaRouteResponse; | |
| 19 class MediaRoutesObserver; | |
| 20 class MediaSource; | |
| 21 class MediaSinksObserver; | |
| 22 | |
| 23 using MediaRouteResponseCallback = | |
| 24 base::Callback<void(const MediaRouteResponse&)>; | |
| 25 | |
| 26 // An interface for handling resources related to media routing. | |
| 27 // Responsible for registering observers for receiving sink availability | |
| 28 // updates, handling route requests/responses, and operating on routes (e.g. | |
| 29 // posting messages or closing). | |
| 30 class MediaRouter { | |
| 31 public: | |
| 32 virtual ~MediaRouter() {} | |
| 33 | |
| 34 // Requests a media route from |source| to |sink_id|. | |
| 35 // |callback| is invoked with a response indicating success or failure. | |
| 36 // If it is not possible to request a route, returns kInvalidRouteRequestId. | |
| 37 // Otherwise a valid RouteRequestId (id > kInvalidRouteRequestId) will be | |
| 38 // returned, which can be used with |UnregisterMediaRouteResponseCallback()| | |
| 39 // if the caller no longer wants the callback invoked when a response | |
| 40 // comes back. | |
| 41 virtual RouteRequestId StartRouteRequest( | |
| 42 const MediaSource& source, | |
| 43 const MediaSinkId& sink_id, | |
| 44 const MediaRouteResponseCallback& callback) = 0; | |
|
xhwang
2015/04/08 17:46:24
Instead of a customized callback class, can you ju
imcheng
2015/04/08 19:21:30
IMO it is cleaner to encapsulate the 3 fields (som
xhwang
2015/04/08 20:32:51
hmm, you are actually using 3 fields directly in M
imcheng
2015/04/08 23:28:09
per discussion, removing MediaRouteResponse since
| |
| 45 | |
| 46 // Unregisters a callback registered with a pending media route request, | |
| 47 // e.g., when the user has canceled presentation by closing the media router | |
| 48 // dialog. | |
| 49 // It does NOT cancel the route request, only the callback previously | |
| 50 // registered via |StartRouteRequest|. | |
| 51 // |request_id|: A valid request ID returned by |StartRouteRequest()|. | |
| 52 virtual void UnregisterMediaRouteResponseCallback( | |
| 53 const RouteRequestId& request_id) = 0; | |
| 54 | |
| 55 // Closes the media route specified by |route_id|. | |
| 56 virtual void CloseRoute(const MediaRouteId& route_id) = 0; | |
| 57 | |
| 58 // Registers |observer| with this MediaRouter. |observer| specifies a media | |
| 59 // source and will receive updates with media sinks that are compatible with | |
| 60 // that source. The initial update may happen synchronously. | |
| 61 // NOTE: This class does not assume ownership of |observer|. Callers must | |
| 62 // manage |observer| and make sure |UnregisterObserver()| is called | |
| 63 // before the observer is destroyed. | |
| 64 // Returns true if registration succeeded. | |
| 65 // It is invalid to request the same observer more than once and will result | |
| 66 // in undefined behavior. | |
| 67 // If the MRPM Host is not available, the registration request will fail | |
| 68 // immediately. | |
| 69 virtual bool RegisterMediaSinksObserver(MediaSinksObserver* observer) = 0; | |
| 70 | |
| 71 // Removes a previously added MediaSinksObserver. |observer| will stop | |
| 72 // receiving further updates. | |
| 73 virtual void UnregisterMediaSinksObserver(MediaSinksObserver* observer) = 0; | |
| 74 | |
| 75 // Posts |message| to a MediaSink connected via MediaRoute with |route_id|. | |
| 76 // TODO(imcheng): Support additional data types: Blob, ArrayBuffer, | |
| 77 // ArrayBufferView. | |
| 78 virtual void PostMessage(const MediaRouteId& route_id, | |
| 79 const std::string& message) = 0; | |
| 80 | |
| 81 // Adds a MediaRoutesObserver to listen for updates on MediaRoutes. | |
| 82 // The initial update may happen synchronously. | |
| 83 // MediaRouter does not own |observer|. |RemoveMediaRoutesObserver| should | |
| 84 // be called before |observer| is destroyed. | |
| 85 virtual bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | |
| 86 | |
| 87 // Removes a previously added MediaRoutesObserver. |observer| will stop | |
| 88 // receiving further updates. | |
| 89 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | |
| 90 }; | |
| 91 | |
| 92 } // namespace media_router | |
| 93 | |
| 94 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ | |
| OLD | NEW |