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; | |
imcheng (use chromium acct)
2015/05/14 21:30:13
The name Issue::IssueId is inconsistent with the o
Kevin M
2015/05/14 22:46:35
Making the type alias a child of Issue was suggest
| |
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 // Adds the IssuesObserver |observer|. |
imcheng (use chromium acct)
2015/05/14 21:30:13
These two functions should go into private.
Kevin M
2015/05/14 22:46:34
Done.
| |
70 virtual void AddIssuesObserver(IssuesObserver* observer) = 0; | |
71 | |
72 // Removes the IssuesObserver |observer|. | |
73 virtual void RemoveIssuesObserver(IssuesObserver* observer) = 0; | |
74 | |
75 private: | |
76 friend class IssuesObserver; | |
65 friend class MediaSinksObserver; | 77 friend class MediaSinksObserver; |
66 friend class MediaRoutesObserver; | 78 friend class MediaRoutesObserver; |
67 | 79 |
68 // The following APIs are called by MediaSinksObserver/MediaRoutesObserver | 80 // The following functions are called by IssuesObserver, MediaSinksObserver, |
69 // and implementations of MediaRouter only. | 81 // and MediaRoutesObserver. |
70 | 82 |
71 // Registers |observer| with this MediaRouter. |observer| specifies a media | 83 // Registers |observer| with this MediaRouter. |observer| specifies a media |
72 // source and will receive updates with media sinks that are compatible with | 84 // source and will receive updates with media sinks that are compatible with |
73 // that source. The initial update may happen synchronously. | 85 // that source. The initial update may happen synchronously. |
74 // NOTE: This class does not assume ownership of |observer|. Callers must | 86 // NOTE: This class does not assume ownership of |observer|. Callers must |
75 // manage |observer| and make sure |UnregisterObserver()| is called | 87 // manage |observer| and make sure |UnregisterObserver()| is called |
76 // before the observer is destroyed. | 88 // before the observer is destroyed. |
77 // Returns true if registration succeeded. | 89 // Returns true if registration succeeded. |
78 // It is invalid to request the same observer more than once and will result | 90 // It is invalid to request the same observer more than once and will result |
79 // in undefined behavior. | 91 // in undefined behavior. |
(...skipping 12 matching lines...) Expand all Loading... | |
92 virtual bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | 104 virtual bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
93 | 105 |
94 // Removes a previously added MediaRoutesObserver. |observer| will stop | 106 // Removes a previously added MediaRoutesObserver. |observer| will stop |
95 // receiving further updates. | 107 // receiving further updates. |
96 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; | 108 virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
97 }; | 109 }; |
98 | 110 |
99 } // namespace media_router | 111 } // namespace media_router |
100 | 112 |
101 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ | 113 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
OLD | NEW |