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

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: Respond to apacible@ comments 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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 .then(function(route) { 665 .then(function(route) {
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
imcheng 2016/07/15 20:18:45 I think this should return a Promise - see createR
mark a. foltz 2016/07/15 20:36:49 Done.
678 */ 676 */
679 MediaRouteProvider.prototype.terminateRoute = function(routeId) { 677 MediaRouteProvider.prototype.terminateRoute = function(routeId) {
680 this.handlers_.terminateRoute(routeId); 678 // TODO(crbug.com/627967): Remove code path that doesn't expect a Promise
679 // in M56.
680 var maybePromise = this.handlers_.terminateRoute(routeId);
681 var successResult = {result_code: RouteRequestResultCode.OK};
682 if (maybePromise) {
683 maybePromise.then(
imcheng 2016/07/15 20:18:45 return maybePromise.then(...
mark a. foltz 2016/07/15 20:36:49 Good catch. Done.
684 function() { return successResult; },
685 function(err) { return toErrorRouteResponse_(err); }
686 );
687 } else {
688 return successResult;
imcheng 2016/07/15 20:18:45 return Promise.resolve(successResult);
mark a. foltz 2016/07/15 20:36:49 Done.
689 }
681 }; 690 };
682 691
683 /** 692 /**
684 * Posts a message to the route designated by |routeId|. 693 * Posts a message to the route designated by |routeId|.
685 * @param {!string} routeId 694 * @param {!string} routeId
686 * @param {!string} message 695 * @param {!string} message
687 * @return {!Promise.<boolean>} Resolved with true if the message was sent, 696 * @return {!Promise.<boolean>} Resolved with true if the message was sent,
688 * or false on failure. 697 * or false on failure.
689 */ 698 */
690 MediaRouteProvider.prototype.sendRouteMessage = function( 699 MediaRouteProvider.prototype.sendRouteMessage = function(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 }; 819 };
811 820
812 mediaRouter = new MediaRouter(connector.bindHandleToProxy( 821 mediaRouter = new MediaRouter(connector.bindHandleToProxy(
813 serviceProvider.connectToService( 822 serviceProvider.connectToService(
814 mediaRouterMojom.MediaRouter.name), 823 mediaRouterMojom.MediaRouter.name),
815 mediaRouterMojom.MediaRouter)); 824 mediaRouterMojom.MediaRouter));
816 825
817 return mediaRouter; 826 return mediaRouter;
818 }); 827 });
819 828
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698