Chromium Code Reviews| 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 var mediaRouter; | 5 var mediaRouter; |
| 6 | 6 |
| 7 define('media_router_bindings', [ | 7 define('media_router_bindings', [ |
| 8 'mojo/public/js/bindings', | 8 'mojo/public/js/bindings', |
| 9 'mojo/public/js/core', | 9 'mojo/public/js/core', |
| 10 'content/public/renderer/frame_service_registry', | 10 'content/public/renderer/frame_service_registry', |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 /** | 149 /** |
| 150 * Parses the given route request Error object and converts it to the | 150 * Parses the given route request Error object and converts it to the |
| 151 * corresponding result code. | 151 * corresponding result code. |
| 152 * @param {!Error} error | 152 * @param {!Error} error |
| 153 * @return {!mediaRouterMojom.RouteRequestResultCode} | 153 * @return {!mediaRouterMojom.RouteRequestResultCode} |
| 154 */ | 154 */ |
| 155 function getRouteRequestResultCode_(error) { | 155 function getRouteRequestResultCode_(error) { |
| 156 if (error.message.startsWith('timeout')) | 156 return error.errorCode ? error.errorCode : |
| 157 return mediaRouterMojom.RouteRequestResultCode.TIMED_OUT; | 157 mediaRouterMojom.RouteRequestResultCode.UNKNOWN_ERROR; |
| 158 else | |
| 159 return mediaRouterMojom.RouteRequestResultCode.UNKNOWN_ERROR; | |
| 160 } | 158 } |
| 161 | 159 |
| 162 /** | 160 /** |
| 163 * Creates and returns a successful route response from given route. | 161 * Creates and returns a successful route response from given route. |
| 164 * @param {!MediaRoute} route | 162 * @param {!MediaRoute} route |
| 165 * @return {!Object} | 163 * @return {!Object} |
| 166 */ | 164 */ |
| 167 function toSuccessRouteResponse_(route) { | 165 function toSuccessRouteResponse_(route) { |
| 168 return { | 166 return { |
| 169 route: routeToMojo_(route), | 167 route: routeToMojo_(route), |
| 170 result_code: mediaRouterMojom.RouteRequestResultCode.OK | 168 result_code: mediaRouterMojom.RouteRequestResultCode.OK |
| 171 }; | 169 }; |
| 172 } | 170 } |
| 173 | 171 |
| 174 /** | 172 /** |
| 175 * Creates and returns a error route response from given Error object | 173 * Creates and returns a error route response from given Error object. |
| 176 * @param {!Error} error | 174 * @param {!Error} error |
| 177 * @return {!Object} | 175 * @return {!Object} |
| 178 */ | 176 */ |
| 179 function toErrorRouteResponse_(error) { | 177 function toErrorRouteResponse_(error) { |
| 180 return { | 178 return { |
| 181 error_text: 'Error creating route: ' + error.message, | 179 error_text: error.message, |
| 182 result_code: getRouteRequestResultCode_(error) | 180 result_code: getRouteRequestResultCode_(error) |
| 183 }; | 181 }; |
| 184 } | 182 } |
| 185 | 183 |
| 186 /** | 184 /** |
| 187 * Creates a new MediaRouter. | 185 * Creates a new MediaRouter. |
| 188 * Converts a route struct to its Mojo form. | 186 * Converts a route struct to its Mojo form. |
| 189 * @param {!MediaRouterService} service | 187 * @param {!MediaRouterService} service |
| 190 * @constructor | 188 * @constructor |
| 191 */ | 189 */ |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 * @type {function(!string, !string, !string, !string, !number)} | 420 * @type {function(!string, !string, !string, !string, !number)} |
| 423 */ | 421 */ |
| 424 this.createRoute = null; | 422 this.createRoute = null; |
| 425 | 423 |
| 426 /** | 424 /** |
| 427 * @type {function(!string, !string, !string, !number)} | 425 * @type {function(!string, !string, !string, !number)} |
| 428 */ | 426 */ |
| 429 this.joinRoute = null; | 427 this.joinRoute = null; |
| 430 | 428 |
| 431 /** | 429 /** |
| 432 * @type {function(string)} | 430 * @type {function(string): Promise} |
| 433 */ | 431 */ |
| 434 this.terminateRoute = null; | 432 this.terminateRoute = null; |
| 435 | 433 |
| 436 /** | 434 /** |
| 437 * @type {function(string)} | 435 * @type {function(string)} |
| 438 */ | 436 */ |
| 439 this.startObservingMediaSinks = null; | 437 this.startObservingMediaSinks = null; |
| 440 | 438 |
| 441 /** | 439 /** |
| 442 * @type {function(string)} | 440 * @type {function(string)} |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 668 return toSuccessRouteResponse_(route); | 666 return toSuccessRouteResponse_(route); |
| 669 }, | 667 }, |
| 670 function(err) { | 668 function(err) { |
| 671 return toErrorRouteResponse_(err); | 669 return toErrorRouteResponse_(err); |
| 672 }); | 670 }); |
| 673 }; | 671 }; |
| 674 | 672 |
| 675 /** | 673 /** |
| 676 * Terminates the route specified by |routeId|. | 674 * Terminates the route specified by |routeId|. |
| 677 * @param {!string} routeId | 675 * @param {!string} routeId |
| 676 * @return {!Promise<!Object>} A Promise resolving to an object describing | |
| 677 * the result of the terminate operation, or rejecting with an error messag e | |
|
imcheng
2016/07/15 20:40:45
nit: fix line wrap
mark a. foltz
2016/07/15 20:49:04
Done.
| |
| 678 * and code if the operation failed. | |
| 678 */ | 679 */ |
| 679 MediaRouteProvider.prototype.terminateRoute = function(routeId) { | 680 MediaRouteProvider.prototype.terminateRoute = function(routeId) { |
| 680 this.handlers_.terminateRoute(routeId); | 681 // TODO(crbug.com/627967): Remove code path that doesn't expect a Promise |
| 682 // in M56. | |
| 683 var maybePromise = this.handlers_.terminateRoute(routeId); | |
| 684 var successResult = {result_code: RouteRequestResultCode.OK}; | |
| 685 if (maybePromise) { | |
| 686 return maybePromise.then( | |
| 687 function() { return successResult; }, | |
| 688 function(err) { return toErrorRouteResponse_(err); } | |
| 689 ); | |
| 690 } else { | |
| 691 return Promise.resolve(successResult); | |
| 692 } | |
| 681 }; | 693 }; |
| 682 | 694 |
| 683 /** | 695 /** |
| 684 * Posts a message to the route designated by |routeId|. | 696 * Posts a message to the route designated by |routeId|. |
| 685 * @param {!string} routeId | 697 * @param {!string} routeId |
| 686 * @param {!string} message | 698 * @param {!string} message |
| 687 * @return {!Promise.<boolean>} Resolved with true if the message was sent, | 699 * @return {!Promise.<boolean>} Resolved with true if the message was sent, |
| 688 * or false on failure. | 700 * or false on failure. |
| 689 */ | 701 */ |
| 690 MediaRouteProvider.prototype.sendRouteMessage = function( | 702 MediaRouteProvider.prototype.sendRouteMessage = function( |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 810 }; | 822 }; |
| 811 | 823 |
| 812 mediaRouter = new MediaRouter(connector.bindHandleToProxy( | 824 mediaRouter = new MediaRouter(connector.bindHandleToProxy( |
| 813 serviceProvider.connectToService( | 825 serviceProvider.connectToService( |
| 814 mediaRouterMojom.MediaRouter.name), | 826 mediaRouterMojom.MediaRouter.name), |
| 815 mediaRouterMojom.MediaRouter)); | 827 mediaRouterMojom.MediaRouter)); |
| 816 | 828 |
| 817 return mediaRouter; | 829 return mediaRouter; |
| 818 }); | 830 }); |
| 819 | 831 |
| OLD | NEW |