Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: extensions/renderer/resources/media_router_bindings.js

Issue 2145983003: [Media Router] Adds return value to mojo MediaRouteProvider::TerminateRoute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo in media_router_bindings.js Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 * @type {function(!string, !string, !string, !string, !number)} 429 * @type {function(!string, !string, !string, !string, !number)}
432 */ 430 */
433 this.createRoute = null; 431 this.createRoute = null;
434 432
435 /** 433 /**
436 * @type {function(!string, !string, !string, !number)} 434 * @type {function(!string, !string, !string, !number)}
437 */ 435 */
438 this.joinRoute = null; 436 this.joinRoute = null;
439 437
440 /** 438 /**
441 * @type {function(string)} 439 * @type {function(string): Promise}
442 */ 440 */
443 this.terminateRoute = null; 441 this.terminateRoute = null;
444 442
445 /** 443 /**
446 * @type {function(string)} 444 * @type {function(string)}
447 */ 445 */
448 this.startObservingMediaSinks = null; 446 this.startObservingMediaSinks = null;
449 447
450 /** 448 /**
451 * @type {function(string)} 449 * @type {function(string)}
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 return toSuccessRouteResponse_(route); 681 return toSuccessRouteResponse_(route);
684 }, 682 },
685 function(err) { 683 function(err) {
686 return toErrorRouteResponse_(err); 684 return toErrorRouteResponse_(err);
687 }); 685 });
688 }; 686 };
689 687
690 /** 688 /**
691 * Terminates the route specified by |routeId|. 689 * Terminates the route specified by |routeId|.
692 * @param {!string} routeId 690 * @param {!string} routeId
691 * @return {!Promise<!Object>} A Promise resolving to an object describing
692 * the result of the terminate operation, or rejecting with an error
693 * message and code if the operation failed.
693 */ 694 */
694 MediaRouteProvider.prototype.terminateRoute = function(routeId) { 695 MediaRouteProvider.prototype.terminateRoute = function(routeId) {
695 this.handlers_.terminateRoute(routeId); 696 // TODO(crbug.com/627967): Remove code path that doesn't expect a Promise
697 // in M56.
698 var maybePromise = this.handlers_.terminateRoute(routeId);
699 var successResult = {
700 result_code: mediaRouterMojom.RouteRequestResultCode.OK
701 };
702 if (maybePromise) {
703 return maybePromise.then(
704 function() { return successResult; },
705 function(err) { return toErrorRouteResponse_(err); }
706 );
707 } else {
708 return Promise.resolve(successResult);
709 }
696 }; 710 };
697 711
698 /** 712 /**
699 * Posts a message to the route designated by |routeId|. 713 * Posts a message to the route designated by |routeId|.
700 * @param {!string} routeId 714 * @param {!string} routeId
701 * @param {!string} message 715 * @param {!string} message
702 * @return {!Promise.<boolean>} Resolved with true if the message was sent, 716 * @return {!Promise.<boolean>} Resolved with true if the message was sent,
703 * or false on failure. 717 * or false on failure.
704 */ 718 */
705 MediaRouteProvider.prototype.sendRouteMessage = function( 719 MediaRouteProvider.prototype.sendRouteMessage = function(
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 }; 857 };
844 858
845 mediaRouter = new MediaRouter(connector.bindHandleToProxy( 859 mediaRouter = new MediaRouter(connector.bindHandleToProxy(
846 serviceProvider.connectToService( 860 serviceProvider.connectToService(
847 mediaRouterMojom.MediaRouter.name), 861 mediaRouterMojom.MediaRouter.name),
848 mediaRouterMojom.MediaRouter)); 862 mediaRouterMojom.MediaRouter));
849 863
850 return mediaRouter; 864 return mediaRouter;
851 }); 865 });
852 866
OLDNEW
« no previous file with comments | « chrome/browser/media/router/route_request_result.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698