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