| 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/media_route.h" | 13 #include "chrome/browser/media/router/media_route.h" |
| 13 #include "chrome/browser/media/router/media_route_id.h" | 14 #include "chrome/browser/media/router/media_route_id.h" |
| 14 #include "chrome/browser/media/router/media_sink.h" | 15 #include "chrome/browser/media/router/media_sink.h" |
| 15 #include "chrome/browser/media/router/media_source.h" | 16 #include "chrome/browser/media/router/media_source.h" |
| 16 | 17 |
| 17 namespace media_router { | 18 namespace media_router { |
| 18 | 19 |
| 20 class IssuesObserver; |
| 19 class MediaRoutesObserver; | 21 class MediaRoutesObserver; |
| 20 class MediaSinksObserver; | 22 class MediaSinksObserver; |
| 21 | 23 |
| 22 // Type of callback used in |RequestRoute()|. Callback is invoked when the | 24 // Type of callback used in |CreateRoute()|. Callback is invoked when the |
| 23 // route request either succeeded or failed. | 25 // route request either succeeded or failed. |
| 24 // 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 |
| 25 // will be a nullptr. | 27 // will be a nullptr. |
| 26 // 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 |
| 27 // request failed. | 29 // request failed. |
| 28 using MediaRouteResponseCallback = | 30 using MediaRouteResponseCallback = |
| 29 base::Callback<void(scoped_ptr<MediaRoute>, const std::string&)>; | 31 base::Callback<void(scoped_ptr<MediaRoute>, const std::string&)>; |
| 30 | 32 |
| 31 // An interface for handling resources related to media routing. | 33 // An interface for handling resources related to media routing. |
| 32 // Responsible for registering observers for receiving sink availability | 34 // Responsible for registering observers for receiving sink availability |
| 33 // updates, handling route requests/responses, and operating on routes (e.g. | 35 // updates, handling route requests/responses, and operating on routes (e.g. |
| 34 // posting messages or closing). | 36 // posting messages or closing). |
| 35 class MediaRouter { | 37 class MediaRouter { |
| 36 public: | 38 public: |
| 37 virtual ~MediaRouter() {} | 39 virtual ~MediaRouter() {} |
| 38 | 40 |
| 39 // Requests a media route from |source| to |sink_id|. | 41 // Requests a media route from |source| to |sink_id|. |
| 40 // |callback| is invoked with a response indicating success or failure. | 42 // |callback| is invoked with a response indicating success or failure. |
| 41 virtual void RequestRoute(const MediaSourceId& source, | 43 virtual void CreateRoute(const MediaSourceId& source, |
| 42 const MediaSinkId& sink_id, | 44 const MediaSinkId& sink_id, |
| 43 const MediaRouteResponseCallback& callback) = 0; | 45 const MediaRouteResponseCallback& callback) = 0; |
| 44 | 46 |
| 45 // Closes the media route specified by |route_id|. | 47 // Closes the media route specified by |route_id|. |
| 46 virtual void CloseRoute(const MediaRouteId& route_id) = 0; | 48 virtual void CloseRoute(const MediaRouteId& route_id) = 0; |
| 47 | 49 |
| 48 // Posts |message| to a MediaSink connected via MediaRoute with |route_id|. | 50 // Posts |message| to a MediaSink connected via MediaRoute with |route_id|. |
| 49 // TODO(imcheng): Support additional data types: Blob, ArrayBuffer, | 51 // TODO(imcheng): Support additional data types: Blob, ArrayBuffer, |
| 50 // ArrayBufferView. | 52 // ArrayBufferView. |
| 51 virtual void PostMessage(const MediaRouteId& route_id, | 53 virtual void PostMessage(const MediaRouteId& route_id, |
| 52 const std::string& message) = 0; | 54 const std::string& message) = 0; |
| 53 | 55 |
| 56 // Clears the issue with the id |issue_id|. |
| 57 virtual void ClearIssue(const Issue::IssueId& issue_id) = 0; |
| 58 |
| 54 // Receives updates from a MediaRouter instance. | 59 // Receives updates from a MediaRouter instance. |
| 55 class Delegate { | 60 class Delegate { |
| 56 public: | 61 public: |
| 57 // Called when there is a message from a route. | 62 // Called when there is a message from a route. |
| 58 // |route_id|: The route ID. | 63 // |route_id|: The route ID. |
| 59 // |message|: The message. | 64 // |message|: The message. |
| 60 virtual void OnMessage(const MediaRouteId& route_id, | 65 virtual void OnMessage(const MediaRouteId& route_id, |
| 61 const std::string& message) = 0; | 66 const std::string& message) = 0; |
| 62 }; | 67 }; |
| 63 | 68 |
| 64 protected: | 69 private: |
| 70 friend class IssuesObserver; |
| 65 friend class MediaSinksObserver; | 71 friend class MediaSinksObserver; |
| 66 friend class MediaRoutesObserver; | 72 friend class MediaRoutesObserver; |
| 67 | 73 |
| 68 // The following APIs are called by MediaSinksObserver/MediaRoutesObserver | 74 // The following functions are called by IssuesObserver, MediaSinksObserver, |
| 69 // and implementations of MediaRouter only. | 75 // and MediaRoutesObserver. |
| 70 | 76 |
| 71 // Registers |observer| with this MediaRouter. |observer| specifies a media | 77 // Registers |observer| with this MediaRouter. |observer| specifies a media |
| 72 // source and will receive updates with media sinks that are compatible with | 78 // source and will receive updates with media sinks that are compatible with |
| 73 // that source. The initial update may happen synchronously. | 79 // that source. The initial update may happen synchronously. |
| 74 // NOTE: This class does not assume ownership of |observer|. Callers must | 80 // NOTE: This class does not assume ownership of |observer|. Callers must |
| 75 // manage |observer| and make sure |UnregisterObserver()| is called | 81 // manage |observer| and make sure |UnregisterObserver()| is called |
| 76 // before the observer is destroyed. | 82 // before the observer is destroyed. |
| 77 // Returns true if registration succeeded. | 83 // Returns true if registration succeeded. |
| 78 // It is invalid to request the same observer more than once and will result | 84 // It is invalid to request the same observer more than once and will result |
| 79 // in undefined behavior. | 85 // in undefined behavior. |
| 80 // If the MRPM Host is not available, the registration request will fail | 86 // If the MRPM Host is not available, the registration request will fail |
| 81 // immediately. | 87 // immediately. |
| 82 virtual bool RegisterMediaSinksObserver(MediaSinksObserver* observer) = 0; | 88 virtual bool RegisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| 83 | 89 |
| 84 // Removes a previously added MediaSinksObserver. |observer| will stop | 90 // Removes a previously added MediaSinksObserver. |observer| will stop |
| 85 // receiving further updates. | 91 // receiving further updates. |
| 86 virtual void UnregisterMediaSinksObserver(MediaSinksObserver* observer) = 0; | 92 virtual void UnregisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| 87 | 93 |
| 88 // Adds a MediaRoutesObserver to listen for updates on MediaRoutes. | 94 // Adds a MediaRoutesObserver to listen for updates on MediaRoutes. |
| 89 // The initial update may happen synchronously. | 95 // The initial update may happen synchronously. |
| 90 // MediaRouter does not own |observer|. |RemoveMediaRoutesObserver| should | 96 // MediaRouter does not own |observer|. |RemoveMediaRoutesObserver| should |
| 91 // be called before |observer| is destroyed. | 97 // be called before |observer| is destroyed. |
| 92 virtual bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | 98 virtual bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| 93 | 99 |
| 94 // Removes a previously added MediaRoutesObserver. |observer| will stop | 100 // Removes a previously added MediaRoutesObserver. |observer| will stop |
| 95 // receiving further updates. | 101 // receiving further updates. |
| 96 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | 102 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| 103 |
| 104 // Adds the IssuesObserver |observer|. |
| 105 virtual void AddIssuesObserver(IssuesObserver* observer) = 0; |
| 106 |
| 107 // Removes the IssuesObserver |observer|. |
| 108 virtual void RemoveIssuesObserver(IssuesObserver* observer) = 0; |
| 109 |
| 97 }; | 110 }; |
| 98 | 111 |
| 99 } // namespace media_router | 112 } // namespace media_router |
| 100 | 113 |
| 101 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ | 114 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
| OLD | NEW |