Chromium Code Reviews| 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 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "chrome/browser/media/router/issue.h" | 12 #include "chrome/browser/media/router/issue.h" |
| 13 #include "chrome/browser/media/router/media_route.h" | 13 #include "chrome/browser/media/router/media_route.h" |
| 14 #include "chrome/browser/media/router/media_sink.h" | 14 #include "chrome/browser/media/router/media_sink.h" |
| 15 #include "chrome/browser/media/router/media_source.h" | 15 #include "chrome/browser/media/router/media_source.h" |
| 16 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
| 17 #include "content/public/browser/presentation_session_message.h" | 17 #include "content/public/browser/presentation_session_message.h" |
| 18 | 18 |
| 19 namespace media_router { | 19 namespace media_router { |
| 20 | 20 |
| 21 class IssuesObserver; | 21 class IssuesObserver; |
| 22 class MediaRoutesObserver; | 22 class MediaRoutesObserver; |
| 23 class MediaSinksObserver; | 23 class MediaSinksObserver; |
| 24 class PresentationSessionMessagesObserver; | |
| 24 | 25 |
| 25 // Type of callback used in |CreateRoute()|. Callback is invoked when the | 26 // Type of callback used in |CreateRoute()| and |JoinRoute()|. Callback is |
| 26 // route request either succeeded or failed. | 27 // invoked when the route request either succeeded or failed. |
| 27 // The first argument is the route created. If the route request failed, this | 28 // On success: |
| 28 // will be a nullptr. | 29 // |route|: The route created. |
|
mark a. foltz
2015/08/04 23:47:02
created or joined.
imcheng
2015/08/05 21:38:35
Done.
| |
| 29 // The second argument is the error string, which will be nonempty if the route | 30 // |presentation_id|: |
| 30 // request failed. | 31 // The presentation ID of the route created. In the case of |
|
mark a. foltz
2015/08/04 23:47:02
.. of the route created or joined.
imcheng
2015/08/05 21:38:35
Done.
| |
| 32 // |CreateRoute()|, the ID is generated by MediaRouter and is guaranteed to | |
| 33 // be unique. | |
| 34 // |error|: Empty string. | |
| 35 // On failure: | |
| 36 // |route|: nullptr | |
| 37 // |presentation_id|: Empty string. | |
| 38 // |error|: Non-empty string describing the error. | |
| 31 using MediaRouteResponseCallback = | 39 using MediaRouteResponseCallback = |
| 32 base::Callback<void(const MediaRoute*, const std::string&)>; | 40 base::Callback<void(const MediaRoute* route, |
| 41 const std::string& presentation_id, | |
| 42 const std::string& error)>; | |
| 33 | 43 |
| 34 // Used in cases where a tab ID is not applicable in CreateRoute/JoinRoute. | 44 // Used in cases where a tab ID is not applicable in CreateRoute/JoinRoute. |
| 35 const int kInvalidTabId = -1; | 45 const int kInvalidTabId = -1; |
| 36 | 46 |
| 37 // An interface for handling resources related to media routing. | 47 // An interface for handling resources related to media routing. |
| 38 // Responsible for registering observers for receiving sink availability | 48 // Responsible for registering observers for receiving sink availability |
| 39 // updates, handling route requests/responses, and operating on routes (e.g. | 49 // updates, handling route requests/responses, and operating on routes (e.g. |
| 40 // posting messages or closing). | 50 // posting messages or closing). |
| 41 class MediaRouter : public KeyedService { | 51 class MediaRouter : public KeyedService { |
| 42 public: | 52 public: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 const std::string& message, | 96 const std::string& message, |
| 87 const SendRouteMessageCallback& callback) = 0; | 97 const SendRouteMessageCallback& callback) = 0; |
| 88 | 98 |
| 89 // Sends |data| to a MediaSink connected via MediaRoute with |route_id|. | 99 // Sends |data| to a MediaSink connected via MediaRoute with |route_id|. |
| 90 // This is called for Blob / ArrayBuffer / ArrayBufferView types. | 100 // This is called for Blob / ArrayBuffer / ArrayBufferView types. |
| 91 virtual void SendRouteBinaryMessage( | 101 virtual void SendRouteBinaryMessage( |
| 92 const MediaRoute::Id& route_id, | 102 const MediaRoute::Id& route_id, |
| 93 scoped_ptr<std::vector<uint8>> data, | 103 scoped_ptr<std::vector<uint8>> data, |
| 94 const SendRouteMessageCallback& callback) = 0; | 104 const SendRouteMessageCallback& callback) = 0; |
| 95 | 105 |
| 96 // Gets the next batch of messages from one of the routes in |route_ids|. | |
| 97 // |message_cb|: Invoked with a non-empty list of messages when there are | |
| 98 // messages, an empty list when messaging channel had error. | |
| 99 // It is not invoked until there are messages available or error. | |
| 100 virtual void ListenForRouteMessages( | |
| 101 const std::vector<MediaRoute::Id>& route_ids, | |
| 102 const PresentationSessionMessageCallback& message_cb) = 0; | |
| 103 | |
| 104 // Clears the issue with the id |issue_id|. | 106 // Clears the issue with the id |issue_id|. |
| 105 virtual void ClearIssue(const Issue::Id& issue_id) = 0; | 107 virtual void ClearIssue(const Issue::Id& issue_id) = 0; |
| 106 | 108 |
| 107 private: | 109 private: |
| 108 friend class IssuesObserver; | 110 friend class IssuesObserver; |
| 109 friend class MediaSinksObserver; | 111 friend class MediaSinksObserver; |
| 110 friend class MediaRoutesObserver; | 112 friend class MediaRoutesObserver; |
| 113 friend class PresentationSessionMessagesObserver; | |
| 111 | 114 |
| 112 // The following functions are called by IssuesObserver, MediaSinksObserver, | 115 // The following functions are called by friend Observer classes above. |
| 113 // and MediaRoutesObserver. | |
| 114 | 116 |
| 115 // Registers |observer| with this MediaRouter. |observer| specifies a media | 117 // Registers |observer| with this MediaRouter. |observer| specifies a media |
| 116 // source and will receive updates with media sinks that are compatible with | 118 // source and will receive updates with media sinks that are compatible with |
| 117 // that source. The initial update may happen synchronously. | 119 // that source. The initial update may happen synchronously. |
| 118 // NOTE: This class does not assume ownership of |observer|. Callers must | 120 // NOTE: This class does not assume ownership of |observer|. Callers must |
| 119 // manage |observer| and make sure |UnregisterObserver()| is called | 121 // manage |observer| and make sure |UnregisterObserver()| is called |
| 120 // before the observer is destroyed. | 122 // before the observer is destroyed. |
| 121 // It is invalid to register the same observer more than once and will result | 123 // It is invalid to register the same observer more than once and will result |
| 122 // in undefined behavior. | 124 // in undefined behavior. |
| 123 // If the MRPM Host is not available, the registration request will fail | 125 // If the MRPM Host is not available, the registration request will fail |
| 124 // immediately. | 126 // immediately. |
| 125 virtual void RegisterMediaSinksObserver(MediaSinksObserver* observer) = 0; | 127 virtual void RegisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| 126 | 128 |
| 127 // Removes a previously added MediaSinksObserver. |observer| will stop | 129 // Removes a previously added MediaSinksObserver. |observer| will stop |
| 128 // receiving further updates. | 130 // receiving further updates. |
| 129 virtual void UnregisterMediaSinksObserver(MediaSinksObserver* observer) = 0; | 131 virtual void UnregisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| 130 | 132 |
| 131 // Adds a MediaRoutesObserver to listen for updates on MediaRoutes. | 133 // Adds a MediaRoutesObserver to listen for updates on MediaRoutes. |
| 132 // The initial update may happen synchronously. | 134 // The initial update may happen synchronously. |
| 133 // MediaRouter does not own |observer|. |RemoveMediaRoutesObserver| should | 135 // MediaRouter does not own |observer|. |UnregisterMediaRoutesObserver| should |
| 134 // be called before |observer| is destroyed. | 136 // be called before |observer| is destroyed. |
| 135 // It is invalid to register the same observer more than once and will result | 137 // It is invalid to register the same observer more than once and will result |
| 136 // in undefined behavior. | 138 // in undefined behavior. |
| 137 virtual void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | 139 virtual void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| 138 | 140 |
| 139 // Removes a previously added MediaRoutesObserver. |observer| will stop | 141 // Removes a previously added MediaRoutesObserver. |observer| will stop |
| 140 // receiving further updates. | 142 // receiving further updates. |
| 141 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | 143 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| 142 | 144 |
| 143 // Adds the IssuesObserver |observer|. | 145 // Adds the IssuesObserver |observer|. |
| 144 // It is invalid to register the same observer more than once and will result | 146 // It is invalid to register the same observer more than once and will result |
| 145 // in undefined behavior. | 147 // in undefined behavior. |
| 146 virtual void RegisterIssuesObserver(IssuesObserver* observer) = 0; | 148 virtual void RegisterIssuesObserver(IssuesObserver* observer) = 0; |
| 147 | 149 |
| 148 // Removes the IssuesObserver |observer|. | 150 // Removes the IssuesObserver |observer|. |
| 149 virtual void UnregisterIssuesObserver(IssuesObserver* observer) = 0; | 151 virtual void UnregisterIssuesObserver(IssuesObserver* observer) = 0; |
| 152 | |
| 153 // Registers |observer| with this MediaRouter. |observer| specifies a media | |
| 154 // route corresponding to a presentation and will receive messages from the | |
| 155 // MediaSink connected to the route. Note that MediaRouter does not own | |
| 156 // |observer|. |observer| should be unregistered before it is destroyed. | |
| 157 // Registering the same observer more than once will result in undefined | |
| 158 // behavior. | |
| 159 virtual void RegisterPresentationSessionMessagesObserver( | |
| 160 PresentationSessionMessagesObserver* observer) = 0; | |
| 161 | |
| 162 // Unregisters a previously registered PresentationSessionMessagesObserver. | |
| 163 // |observer| will stop receiving further updates. | |
| 164 virtual void UnregisterPresentationSessionMessagesObserver( | |
| 165 PresentationSessionMessagesObserver* observer) = 0; | |
| 150 }; | 166 }; |
| 151 | 167 |
| 152 } // namespace media_router | 168 } // namespace media_router |
| 153 | 169 |
| 154 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ | 170 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
| OLD | NEW |