Index: chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js |
diff --git a/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js b/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js |
index 79b8d77e62ccf532732c0d5c8989e5bc1bdb6564..886a53e77e0d3cf412f3058c41134c4c8d9af4a8 100644 |
--- a/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js |
+++ b/chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js |
@@ -190,6 +190,17 @@ Polymer({ |
}, |
/** |
+ * The ID of the route that is currently being created. This is set when |
+ * route creation is resolved but not ready for its controls to be |
+ * displayed. |
+ * @private {string} |
+ */ |
+ pendingCreatedRouteId_: { |
+ type: String, |
+ value: '', |
+ }, |
+ |
+ /** |
* The time the sink list was shown and populated with at least one sink. |
* This is reset whenever the user switches views or there are no sinks |
* available for display. |
@@ -851,26 +862,21 @@ Polymer({ |
* |
* @param {string} sinkId The ID of the sink to which the Media Route was |
* creating a route. |
- * @param {?media_router.Route} route The newly created route to the sink |
- * if succeeded; null otherwise. |
+ * @param {string} routeId The ID of the newly created route for the sink if |
+ * succeeded; empty otherwise. |
*/ |
- onCreateRouteResponseReceived: function(sinkId, route) { |
- this.currentLaunchingSinkId_ = ''; |
- // The provider will handle sending an issue for a failed route request. |
- if (!route) |
+ onCreateRouteResponseReceived: function(sinkId, routeId) { |
+ // Check that |sinkId| exists and corresponds to |currentLaunchingSinkId_|. |
+ if (!this.sinkMap_[sinkId] || this.currentLaunchingSinkId_ != sinkId) |
return; |
- // Check that |sinkId| exists. |
- if (!this.sinkMap_[sinkId]) |
+ // The provider will handle sending an issue for a failed route request. |
+ if (this.isEmptyOrWhitespace_(routeId)) { |
+ this.resetRouteCreationProperties_(false); |
return; |
+ } |
- // If there is an existing route associated with the same sink, its |
- // |sinkToRouteMap_| entry will be overwritten with that of the new route, |
- // which results in the correct sink to route mapping. |
- this.routeList.push(route); |
- this.showRouteDetails_(route); |
- |
- this.startTapTimer_(); |
+ this.pendingCreatedRouteId_ = routeId; |
}, |
/** |
@@ -892,12 +898,10 @@ Polymer({ |
}, |
/** |
- * Handles timeout of previous create route attempt. Clearing |
- * |currentLaunchingSinkId_| hides the spinner indicating there is a route |
- * creation in progress and show the device icon instead. |
+ * Handles timeout of previous create route attempt. |
*/ |
onNotifyRouteCreationTimeout: function() { |
- this.currentLaunchingSinkId_ = ''; |
+ this.resetRouteCreationProperties_(false); |
}, |
/** |
@@ -930,6 +934,19 @@ Polymer({ |
tempSinkToRouteMap[route.sinkId] = route; |
}, this); |
+ // If there is route creation in progress, check if any of the route ids |
+ // correspond to |pendingCreatedRouteId_|. If so, the newly created route |
+ // is ready to be displayed; switch to route details view. |
+ if (this.currentLaunchingSinkId_ != '' && |
+ this.pendingCreatedRouteId_ != '') { |
+ var route = tempSinkToRouteMap[this.currentLaunchingSinkId_]; |
+ if (route && this.pendingCreatedRouteId_ == route.id) { |
+ this.showRouteDetails_(route); |
+ this.startTapTimer_(); |
+ this.resetRouteCreationProperties_(true); |
+ } |
+ } |
+ |
// If |currentRoute_| is no longer active, clear |currentRoute_|. Also |
// switch back to the SINK_PICKER view if the user is currently in the |
// ROUTE_DETAILS view. |
@@ -996,6 +1013,21 @@ Polymer({ |
}, |
/** |
+ * Resets the properties relevant to creating a new route. Fires an event |
+ * indicating whether or not route creation was successful. |
+ * Clearing |currentLaunchingSinkId_| hides the spinner indicating there is |
+ * a route creation in progress and show the device icon instead. |
+ * |
+ * @private |
+ */ |
+ resetRouteCreationProperties_: function(creationSuccess) { |
+ this.currentLaunchingSinkId_ = ''; |
+ this.pendingCreatedRouteId_ = ''; |
+ |
+ this.fire('report-route-creation', {success: creationSuccess}); |
+ }, |
+ |
+ /** |
* Updates the shown cast mode, and updates the header text fields |
* according to the cast mode. If |castMode| type is AUTO, then set |
* |userHasSelectedCastMode_| to false. |