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