summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorimcheng <imcheng@chromium.org>2016-02-04 17:37:05 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-05 01:38:08 +0000
commit20f3f90216886832c2e22e8446c1e8025a81de6a (patch)
tree305fc7966610dcb0dcfff4952240ba19627ebf07 /extensions
parent600b32e3aab92b65e375af32cf1406e454f28f04 (diff)
downloadchromium_src-20f3f90216886832c2e22e8446c1e8025a81de6a.zip
chromium_src-20f3f90216886832c2e22e8446c1e8025a81de6a.tar.gz
chromium_src-20f3f90216886832c2e22e8446c1e8025a81de6a.tar.bz2
[Media Router] Support custom timeout for route requests.
Add base::TimeDelta parameter to CreateRoute/JoinRoute/ ConnectRouteByRouteId APIs. This allows us to specify different timeout amounts depending on the source used in the route creation. This timeout will be provided to MRPM to be enforced. Note that if timeout is not provided, the MRPM will still use a default timeout in the interest of not keeping the extension alive indefinitely. In addition, a result code is added to the route response. Currently we have a TIMED_OUT code for timed out requests. In the future we can add more codes to differentiate error conditions in order to surface to pages that use Presentation API. Refactored the data of a route response into RouteRequestResult class. Modified the desktop UI code to pass in timeout amounts to CreateRoute and ConnectRouteByRouteId depending on source / cast mode. Also modified / simplified route request timeout logic in UI. BUG=581818,567368 Review URL: https://codereview.chromium.org/1639053003 Cr-Commit-Position: refs/heads/master@{#373708}
Diffstat (limited to 'extensions')
-rw-r--r--extensions/renderer/resources/media_router_bindings.js81
1 files changed, 65 insertions, 16 deletions
diff --git a/extensions/renderer/resources/media_router_bindings.js b/extensions/renderer/resources/media_router_bindings.js
index 7d793b6..0ad0ae8 100644
--- a/extensions/renderer/resources/media_router_bindings.js
+++ b/extensions/renderer/resources/media_router_bindings.js
@@ -123,6 +123,43 @@ define('media_router_bindings', [
}
/**
+ * Parses the given route request Error object and converts it to the
+ * corresponding result code.
+ * @param {!Error} error
+ * @return {!mediaRouterMojom.RouteRequestResultCode}
+ */
+ function getRouteRequestResultCode_(error) {
+ if (error.message.startsWith('timeout'))
+ return mediaRouterMojom.RouteRequestResultCode.TIMED_OUT;
+ else
+ return mediaRouterMojom.RouteRequestResultCode.UNKNOWN_ERROR;
+ }
+
+ /**
+ * Creates and returns a successful route response from given route.
+ * @param {!MediaRoute} route
+ * @return {!Object}
+ */
+ function toSuccessRouteResponse_(route) {
+ return {
+ route: routeToMojo_(route),
+ result_code: mediaRouterMojom.RouteRequestResultCode.OK
+ };
+ }
+
+ /**
+ * Creates and returns a error route response from given Error object
+ * @param {!Error} error
+ * @return {!Object}
+ */
+ function toErrorRouteResponse_(error) {
+ return {
+ error_text: 'Error creating route: ' + error.message,
+ result_code: getRouteRequestResultCode_(error)
+ };
+ }
+
+ /**
* Creates a new MediaRouter.
* Converts a route struct to its Mojo form.
* @param {!MediaRouterService} service
@@ -481,19 +518,23 @@ define('media_router_bindings', [
* requesting presentation. TODO(mfoltz): Remove.
* @param {!string} origin Origin of site requesting presentation.
* @param {!number} tabId ID of tab requesting presentation.
+ * @param {!number} timeoutMillis If positive, the timeout duration for the
+ * request, measured in seconds. Otherwise, the default duration will be
+ * used.
* @return {!Promise.<!Object>} A Promise resolving to an object describing
* the newly created media route, or rejecting with an error message on
* failure.
*/
MediaRouteProvider.prototype.createRoute =
- function(sourceUrn, sinkId, presentationId, origin, tabId) {
+ function(sourceUrn, sinkId, presentationId, origin, tabId,
+ timeoutMillis) {
return this.handlers_.createRoute(
- sourceUrn, sinkId, presentationId, origin, tabId)
+ sourceUrn, sinkId, presentationId, origin, tabId, timeoutMillis)
.then(function(route) {
- return {route: routeToMojo_(route)};
- }.bind(this))
- .catch(function(err) {
- return {error_text: 'Error creating route: ' + err.message};
+ return toSuccessRouteResponse_(route);
+ },
+ function(err) {
+ return toErrorRouteResponse_(err);
});
};
@@ -505,18 +546,22 @@ define('media_router_bindings', [
* @param {!string} presentationId Presentation ID to join.
* @param {!string} origin Origin of site requesting join.
* @param {!number} tabId ID of tab requesting join.
+ * @param {!number} timeoutMillis If positive, the timeout duration for the
+ * request, measured in seconds. Otherwise, the default duration will be
+ * used.
* @return {!Promise.<!Object>} A Promise resolving to an object describing
* the newly created media route, or rejecting with an error message on
* failure.
*/
MediaRouteProvider.prototype.joinRoute =
- function(sourceUrn, presentationId, origin, tabId) {
- return this.handlers_.joinRoute(sourceUrn, presentationId, origin, tabId)
- .then(function(newRoute) {
- return {route: routeToMojo_(newRoute)};
+ function(sourceUrn, presentationId, origin, tabId, timeoutMillis) {
+ return this.handlers_.joinRoute(
+ sourceUrn, presentationId, origin, tabId, timeoutMillis)
+ .then(function(route) {
+ return toSuccessRouteResponse_(route);
},
function(err) {
- return {error_text: 'Error joining route: ' + err.message};
+ return toErrorRouteResponse_(err);
});
};
@@ -529,19 +574,23 @@ define('media_router_bindings', [
* @param {!string} presentationId Presentation ID to join.
* @param {!string} origin Origin of site requesting join.
* @param {!number} tabId ID of tab requesting join.
+ * @param {!number} timeoutMillis If positive, the timeout duration for the
+ * request, measured in seconds. Otherwise, the default duration will be
+ * used.
* @return {!Promise.<!Object>} A Promise resolving to an object describing
* the newly created media route, or rejecting with an error message on
* failure.
*/
MediaRouteProvider.prototype.connectRouteByRouteId =
- function(sourceUrn, routeId, presentationId, origin, tabId) {
+ function(sourceUrn, routeId, presentationId, origin, tabId,
+ timeoutMillis) {
return this.handlers_.connectRouteByRouteId(
- sourceUrn, routeId, presentationId, origin, tabId)
- .then(function(newRoute) {
- return {route: routeToMojo_(newRoute)};
+ sourceUrn, routeId, presentationId, origin, tabId, timeoutMillis)
+ .then(function(route) {
+ return toSuccessRouteResponse_(route);
},
function(err) {
- return {error_text: 'Error joining route: ' + err.message};
+ return toErrorRouteResponse_(err);
});
};