| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // Type of callback used in |CreateRoute()|. Callback is invoked when the | 23 // Type of callback used in |CreateRoute()|. Callback is invoked when the |
| 24 // route request either succeeded or failed. | 24 // route request either succeeded or failed. |
| 25 // The first argument is the route created. If the route request failed, this | 25 // The first argument is the route created. If the route request failed, this |
| 26 // will be a nullptr. | 26 // will be a nullptr. |
| 27 // The second argument is the error string, which will be nonempty if the route | 27 // The second argument is the error string, which will be nonempty if the route |
| 28 // request failed. | 28 // request failed. |
| 29 using MediaRouteResponseCallback = | 29 using MediaRouteResponseCallback = |
| 30 base::Callback<void(scoped_ptr<MediaRoute>, const std::string&)>; | 30 base::Callback<void(scoped_ptr<MediaRoute>, const std::string&)>; |
| 31 | 31 |
| 32 // Used in cases where a tab ID is not applicable in CreateRoute/JoinRoute. |
| 33 const int kInvalidTabId = -1; |
| 34 |
| 32 // An interface for handling resources related to media routing. | 35 // An interface for handling resources related to media routing. |
| 33 // Responsible for registering observers for receiving sink availability | 36 // Responsible for registering observers for receiving sink availability |
| 34 // updates, handling route requests/responses, and operating on routes (e.g. | 37 // updates, handling route requests/responses, and operating on routes (e.g. |
| 35 // posting messages or closing). | 38 // posting messages or closing). |
| 36 class MediaRouter { | 39 class MediaRouter { |
| 37 public: | 40 public: |
| 38 using SendRouteMessageCallback = base::Callback<void(bool sent)>; | 41 using SendRouteMessageCallback = base::Callback<void(bool sent)>; |
| 39 | 42 |
| 40 virtual ~MediaRouter() {} | 43 virtual ~MediaRouter() {} |
| 41 | 44 |
| 42 // Creates a media route from |source_id| to |sink_id|. | 45 // Creates a media route from |source_id| to |sink_id|. |
| 46 // |origin| is the URL of requestor's page. |
| 47 // |tab_id| is the ID of the tab in which the request was made. |
| 48 // |origin| and |tab_id| are used for enforcing same-origin and/or same-tab |
| 49 // scope for JoinRoute() requests. (e.g., if enforced, the page |
| 50 // requesting JoinRoute() must have the same origin as the page that requested |
| 51 // CreateRoute()). |
| 52 // The caller may pass in|kInvalidTabId| if tab is not applicable. |
| 43 // |callback| is invoked with a response indicating success or failure. | 53 // |callback| is invoked with a response indicating success or failure. |
| 44 virtual void CreateRoute(const MediaSource::Id& source_id, | 54 virtual void CreateRoute(const MediaSource::Id& source_id, |
| 45 const MediaSink::Id& sink_id, | 55 const MediaSink::Id& sink_id, |
| 56 const GURL& origin, |
| 57 int tab_id, |
| 46 const MediaRouteResponseCallback& callback) = 0; | 58 const MediaRouteResponseCallback& callback) = 0; |
| 47 | 59 |
| 60 // Joins an existing route identified by |presentation_id|. |
| 61 // |source|: The source to route to the existing route. |
| 62 // |presentation_id|: Presentation ID of the existing route. |
| 63 // |origin|, |tab_id|: Origin and tab of the join route request. Used for |
| 64 // validation when enforcing same-origin and/or same-tab scope. |
| 65 // (See CreateRoute documentation). |
| 66 // |callback| is invoked with a response indicating success or failure. |
| 67 virtual void JoinRoute(const MediaSource::Id& source, |
| 68 const std::string& presentation_id, |
| 69 const GURL& origin, |
| 70 int tab_id, |
| 71 const MediaRouteResponseCallback& callback) = 0; |
| 72 |
| 48 // Closes the media route specified by |route_id|. | 73 // Closes the media route specified by |route_id|. |
| 49 virtual void CloseRoute(const MediaRoute::Id& route_id) = 0; | 74 virtual void CloseRoute(const MediaRoute::Id& route_id) = 0; |
| 50 | 75 |
| 51 // Posts |message| to a MediaSink connected via MediaRoute with |route_id|. | 76 // Posts |message| to a MediaSink connected via MediaRoute with |route_id|. |
| 52 // TODO(imcheng): Support additional data types: Blob, ArrayBuffer, | 77 // TODO(imcheng): Support additional data types: Blob, ArrayBuffer, |
| 53 // ArrayBufferView. | 78 // ArrayBufferView. |
| 54 virtual void SendRouteMessage(const MediaRoute::Id& route_id, | 79 virtual void SendRouteMessage(const MediaRoute::Id& route_id, |
| 55 const std::string& message, | 80 const std::string& message, |
| 56 const SendRouteMessageCallback& callback) = 0; | 81 const SendRouteMessageCallback& callback) = 0; |
| 57 | 82 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // in undefined behavior. | 134 // in undefined behavior. |
| 110 virtual void AddIssuesObserver(IssuesObserver* observer) = 0; | 135 virtual void AddIssuesObserver(IssuesObserver* observer) = 0; |
| 111 | 136 |
| 112 // Removes the IssuesObserver |observer|. | 137 // Removes the IssuesObserver |observer|. |
| 113 virtual void RemoveIssuesObserver(IssuesObserver* observer) = 0; | 138 virtual void RemoveIssuesObserver(IssuesObserver* observer) = 0; |
| 114 }; | 139 }; |
| 115 | 140 |
| 116 } // namespace media_router | 141 } // namespace media_router |
| 117 | 142 |
| 118 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ | 143 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
| OLD | NEW |