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()|. Callback is invoked when the |
| 26 // route request either succeeded or failed. | 27 // route request either succeeded or failed. |
| 27 // The first argument is the route created. If the route request failed, this | 28 // |route|: The route created. If the route request failed, this |
| 28 // will be a nullptr. | 29 // will be a nullptr. |
| 29 // The second argument is the error string, which will be nonempty if the route | 30 // |presentation_id|: The presentation ID of the route created, or empty string |
|
haibinlu
2015/07/30 23:59:11
make it clear that this is MR generated unique ID.
imcheng
2015/08/03 18:56:33
Done.
| |
| 30 // request failed. | 31 // if request failed. |
| 32 // |error|: nonempty if the route request failed. | |
| 31 using MediaRouteResponseCallback = | 33 using MediaRouteResponseCallback = |
| 32 base::Callback<void(const MediaRoute*, const std::string&)>; | 34 base::Callback<void(const MediaRoute* route, |
| 35 const std::string& presentation_id, | |
| 36 const std::string& error)>; | |
| 33 | 37 |
| 34 // Used in cases where a tab ID is not applicable in CreateRoute/JoinRoute. | 38 // Used in cases where a tab ID is not applicable in CreateRoute/JoinRoute. |
| 35 const int kInvalidTabId = -1; | 39 const int kInvalidTabId = -1; |
| 36 | 40 |
| 37 // An interface for handling resources related to media routing. | 41 // An interface for handling resources related to media routing. |
| 38 // Responsible for registering observers for receiving sink availability | 42 // Responsible for registering observers for receiving sink availability |
| 39 // updates, handling route requests/responses, and operating on routes (e.g. | 43 // updates, handling route requests/responses, and operating on routes (e.g. |
| 40 // posting messages or closing). | 44 // posting messages or closing). |
| 41 class MediaRouter : public KeyedService { | 45 class MediaRouter : public KeyedService { |
| 42 public: | 46 public: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 // Closes the media route specified by |route_id|. | 85 // Closes the media route specified by |route_id|. |
| 82 virtual void CloseRoute(const MediaRoute::Id& route_id) = 0; | 86 virtual void CloseRoute(const MediaRoute::Id& route_id) = 0; |
| 83 | 87 |
| 84 // Posts |message| to a MediaSink connected via MediaRoute with |route_id|. | 88 // Posts |message| to a MediaSink connected via MediaRoute with |route_id|. |
| 85 // TODO(imcheng): Support additional data types: Blob, ArrayBuffer, | 89 // TODO(imcheng): Support additional data types: Blob, ArrayBuffer, |
| 86 // ArrayBufferView. | 90 // ArrayBufferView. |
| 87 virtual void SendRouteMessage(const MediaRoute::Id& route_id, | 91 virtual void SendRouteMessage(const MediaRoute::Id& route_id, |
| 88 const std::string& message, | 92 const std::string& message, |
| 89 const SendRouteMessageCallback& callback) = 0; | 93 const SendRouteMessageCallback& callback) = 0; |
| 90 | 94 |
| 91 // Gets the next batch of messages from one of the routes in |route_ids|. | |
| 92 // |message_cb|: Invoked with a non-empty list of messages when there are | |
| 93 // messages, an empty list when messaging channel had error. | |
| 94 // It is not invoked until there are messages available or error. | |
| 95 virtual void ListenForRouteMessages( | |
| 96 const std::vector<MediaRoute::Id>& route_ids, | |
| 97 const PresentationSessionMessageCallback& message_cb) = 0; | |
| 98 | |
| 99 // Clears the issue with the id |issue_id|. | 95 // Clears the issue with the id |issue_id|. |
| 100 virtual void ClearIssue(const Issue::Id& issue_id) = 0; | 96 virtual void ClearIssue(const Issue::Id& issue_id) = 0; |
| 101 | 97 |
| 102 private: | 98 private: |
| 103 friend class IssuesObserver; | 99 friend class IssuesObserver; |
| 104 friend class MediaSinksObserver; | 100 friend class MediaSinksObserver; |
| 105 friend class MediaRoutesObserver; | 101 friend class MediaRoutesObserver; |
| 102 friend class PresentationSessionMessagesObserver; | |
| 106 | 103 |
| 107 // The following functions are called by IssuesObserver, MediaSinksObserver, | 104 // The following functions are called by friend Observer classes above. |
| 108 // and MediaRoutesObserver. | |
| 109 | 105 |
| 110 // Registers |observer| with this MediaRouter. |observer| specifies a media | 106 // Registers |observer| with this MediaRouter. |observer| specifies a media |
| 111 // source and will receive updates with media sinks that are compatible with | 107 // source and will receive updates with media sinks that are compatible with |
| 112 // that source. The initial update may happen synchronously. | 108 // that source. The initial update may happen synchronously. |
| 113 // NOTE: This class does not assume ownership of |observer|. Callers must | 109 // NOTE: This class does not assume ownership of |observer|. Callers must |
| 114 // manage |observer| and make sure |UnregisterObserver()| is called | 110 // manage |observer| and make sure |UnregisterObserver()| is called |
| 115 // before the observer is destroyed. | 111 // before the observer is destroyed. |
| 116 // It is invalid to register the same observer more than once and will result | 112 // It is invalid to register the same observer more than once and will result |
| 117 // in undefined behavior. | 113 // in undefined behavior. |
| 118 // If the MRPM Host is not available, the registration request will fail | 114 // If the MRPM Host is not available, the registration request will fail |
| 119 // immediately. | 115 // immediately. |
| 120 virtual void RegisterMediaSinksObserver(MediaSinksObserver* observer) = 0; | 116 virtual void RegisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| 121 | 117 |
| 122 // Removes a previously added MediaSinksObserver. |observer| will stop | 118 // Removes a previously added MediaSinksObserver. |observer| will stop |
| 123 // receiving further updates. | 119 // receiving further updates. |
| 124 virtual void UnregisterMediaSinksObserver(MediaSinksObserver* observer) = 0; | 120 virtual void UnregisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| 125 | 121 |
| 126 // Adds a MediaRoutesObserver to listen for updates on MediaRoutes. | 122 // Adds a MediaRoutesObserver to listen for updates on MediaRoutes. |
| 127 // The initial update may happen synchronously. | 123 // The initial update may happen synchronously. |
| 128 // MediaRouter does not own |observer|. |RemoveMediaRoutesObserver| should | 124 // MediaRouter does not own |observer|. |UnregisterMediaRoutesObserver| should |
| 129 // be called before |observer| is destroyed. | 125 // be called before |observer| is destroyed. |
| 130 // It is invalid to register the same observer more than once and will result | 126 // It is invalid to register the same observer more than once and will result |
| 131 // in undefined behavior. | 127 // in undefined behavior. |
| 132 virtual void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | 128 virtual void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| 133 | 129 |
| 134 // Removes a previously added MediaRoutesObserver. |observer| will stop | 130 // Removes a previously added MediaRoutesObserver. |observer| will stop |
| 135 // receiving further updates. | 131 // receiving further updates. |
| 136 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | 132 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| 137 | 133 |
| 138 // Adds the IssuesObserver |observer|. | 134 // Adds the IssuesObserver |observer|. |
| 139 // It is invalid to register the same observer more than once and will result | 135 // It is invalid to register the same observer more than once and will result |
| 140 // in undefined behavior. | 136 // in undefined behavior. |
| 141 virtual void RegisterIssuesObserver(IssuesObserver* observer) = 0; | 137 virtual void RegisterIssuesObserver(IssuesObserver* observer) = 0; |
| 142 | 138 |
| 143 // Removes the IssuesObserver |observer|. | 139 // Removes the IssuesObserver |observer|. |
| 144 virtual void UnregisterIssuesObserver(IssuesObserver* observer) = 0; | 140 virtual void UnregisterIssuesObserver(IssuesObserver* observer) = 0; |
| 141 | |
| 142 // Registers |observer| with this MediaRouter. |observer| specifies a media | |
| 143 // route corresponding to a presentation and will receive messages from the | |
| 144 // MediaSink connected to the route. Note that MediaRouter does not own | |
| 145 // |observer|. |observer| should be unregistered before it is destroyed. | |
| 146 // Registering the same observer more than once will result in undefined | |
| 147 // behavior. | |
| 148 virtual void RegisterPresentationSessionMessagesObserver( | |
| 149 PresentationSessionMessagesObserver* observer) = 0; | |
| 150 | |
| 151 // Unregisters a previously registered PresentationSessionMessagesObserver. | |
| 152 // |observer| will stop receiving further updates. | |
| 153 virtual void UnregisterPresentationSessionMessagesObserver( | |
| 154 PresentationSessionMessagesObserver* observer) = 0; | |
| 145 }; | 155 }; |
| 146 | 156 |
| 147 } // namespace media_router | 157 } // namespace media_router |
| 148 | 158 |
| 149 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ | 159 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
| OLD | NEW |