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; |
| 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 or the |observer| already exists. |
| 65 // If the MRPM Host is not available, the registration request will fail |
| 66 // immediately. |
| 67 virtual bool RegisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| 68 |
| 69 // Removes a previously added MediaSinksObserver. |observer| will stop |
| 70 // receiving further updates. |
| 71 virtual void UnregisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| 72 |
| 73 // Posts |message| to a MediaSink connected via MediaRoute with |route_id|. |
| 74 // TODO(imcheng): Support additional data types: Blob, ArrayBuffer, |
| 75 // ArrayBufferView. |
| 76 virtual void PostMessage(const MediaRouteId& route_id, |
| 77 const std::string& message) = 0; |
| 78 |
| 79 // Adds a MediaRoutesObserver to listen for updates on MediaRoutes. |
| 80 // The initial update may happen synchronously. |
| 81 // MediaRouter does not own |observer|. |RemoveMediaRoutesObserver| should |
| 82 // be called before |observer| is destroyed. |
| 83 virtual bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| 84 |
| 85 // Removes a previously added MediaRoutesObserver. |observer| will stop |
| 86 // receiving further updates. |
| 87 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| 88 }; |
| 89 |
| 90 } // namespace media_router |
| 91 |
| 92 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
OLD | NEW |