Chromium Code Reviews| Index: chrome/browser/media/router/media_router.h |
| diff --git a/chrome/browser/media/router/media_router.h b/chrome/browser/media/router/media_router.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d383ef75ce0b531bf599c89610accfb3c06d5ef3 |
| --- /dev/null |
| +++ b/chrome/browser/media/router/media_router.h |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
| +#define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "chrome/browser/media/router/media_route_id.h" |
| +#include "chrome/browser/media/router/media_sink.h" |
| + |
| +namespace media_router { |
| + |
| +class MediaRoute; |
| +class MediaRouteResponse; |
| +class MediaRoutesObserver; |
| +class MediaSource; |
| +class MediaSinksObserver; |
| + |
| +using MediaRouteResponseCallback = |
| + base::Callback<void(const MediaRouteResponse&)>; |
| + |
| +// An interface for handling resources related to media routing. |
| +// Responsible for registering observers for receiving sink availability |
| +// updates, handling route requests/responses, and operating on routes (e.g. |
| +// posting messages or closing). |
| +class MediaRouter { |
| + public: |
| + virtual ~MediaRouter() {} |
| + |
| + // Requests a media route from |source| to |sink_id|. |
| + // |callback| is invoked with a response indicating success or failure. |
| + // If it is not possible to request a route, returns kInvalidRouteRequestId. |
| + // Otherwise a valid RouteRequestId (id > kInvalidRouteRequestId) will be |
| + // returned, which can be used with |UnregisterMediaRouteResponseCallback()| |
| + // if the caller no longer wants the callback invoked when a response |
| + // comes back. |
| + virtual RouteRequestId StartRouteRequest( |
| + const MediaSource& source, |
| + const MediaSinkId& sink_id, |
| + const MediaRouteResponseCallback& callback) = 0; |
|
xhwang
2015/04/08 17:46:24
Instead of a customized callback class, can you ju
imcheng
2015/04/08 19:21:30
IMO it is cleaner to encapsulate the 3 fields (som
xhwang
2015/04/08 20:32:51
hmm, you are actually using 3 fields directly in M
imcheng
2015/04/08 23:28:09
per discussion, removing MediaRouteResponse since
|
| + |
| + // Unregisters a callback registered with a pending media route request, |
| + // e.g., when the user has canceled presentation by closing the media router |
| + // dialog. |
| + // It does NOT cancel the route request, only the callback previously |
| + // registered via |StartRouteRequest|. |
| + // |request_id|: A valid request ID returned by |StartRouteRequest()|. |
| + virtual void UnregisterMediaRouteResponseCallback( |
| + const RouteRequestId& request_id) = 0; |
| + |
| + // Closes the media route specified by |route_id|. |
| + virtual void CloseRoute(const MediaRouteId& route_id) = 0; |
| + |
| + // Registers |observer| with this MediaRouter. |observer| specifies a media |
| + // source and will receive updates with media sinks that are compatible with |
| + // that source. The initial update may happen synchronously. |
| + // NOTE: This class does not assume ownership of |observer|. Callers must |
| + // manage |observer| and make sure |UnregisterObserver()| is called |
| + // before the observer is destroyed. |
| + // Returns true if registration succeeded. |
| + // It is invalid to request the same observer more than once and will result |
| + // in undefined behavior. |
| + // If the MRPM Host is not available, the registration request will fail |
| + // immediately. |
| + virtual bool RegisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| + |
| + // Removes a previously added MediaSinksObserver. |observer| will stop |
| + // receiving further updates. |
| + virtual void UnregisterMediaSinksObserver(MediaSinksObserver* observer) = 0; |
| + |
| + // Posts |message| to a MediaSink connected via MediaRoute with |route_id|. |
| + // TODO(imcheng): Support additional data types: Blob, ArrayBuffer, |
| + // ArrayBufferView. |
| + virtual void PostMessage(const MediaRouteId& route_id, |
| + const std::string& message) = 0; |
| + |
| + // Adds a MediaRoutesObserver to listen for updates on MediaRoutes. |
| + // The initial update may happen synchronously. |
| + // MediaRouter does not own |observer|. |RemoveMediaRoutesObserver| should |
| + // be called before |observer| is destroyed. |
| + virtual bool RegisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| + |
| + // Removes a previously added MediaRoutesObserver. |observer| will stop |
| + // receiving further updates. |
| + virtual void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) = 0; |
| +}; |
| + |
| +} // namespace media_router |
| + |
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_H_ |