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