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

Unified Diff: chrome/browser/resources/media_router/elements/media_router_container/media_router_container.js

Issue 1805813002: [Media Router] Wiring for searching route providers for new sinks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Android stub Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
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 f22eb6060b7c1917e965499945928b544fe1b7b3..1ac7e8e8f61567f60fab21d96b38aab0ac15f824 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
@@ -298,6 +298,25 @@ Polymer({
},
/**
+ * Pseudo sinks from MRPs that represent their ability to accept sink search
+ * requests.
+ * @private {!Array<!media_router.Sink>}
+ */
+ pseudoSinks_: {
+ type: Array,
+ value: [],
+ },
+
+ /**
+ * Helps manage the state of creating a sink and a route from a pseudo sink.
+ * @private {PseudoSinkSearchState}
+ */
+ pseudoSinkSearchState_: {
+ type: Object,
+ value: null,
+ },
+
+ /**
* Whether the next character input should cause a filter action metric to
* be sent.
* @type {boolean}
@@ -806,6 +825,7 @@ Polymer({
*/
computeIssueBannerShown_: function(view, issue) {
return !!issue && (view == media_router.MediaRouterView.SINK_LIST ||
+ view == media_router.MediaRouterView.FILTER ||
view == media_router.MediaRouterView.ISSUE);
},
@@ -1135,6 +1155,20 @@ Polymer({
substrings: matchSubstrings});
}
searchResultsToShow.sort(this.compareSearchMatches_);
+ // Now we need to put any pseudo sinks that should not be overridden by real
+ // sinks at the top of the filter results. First we find the pseudo sinks
+ // that should not be hidden, then we convert them to the match object
+ // format, and then we append the rest of the search matches.
+ searchResultsToShow = this.pseudoSinks_.filter(function(pseudoSink) {
+ return !searchResultsToShow.find(function(searchResult) {
+ return searchResult.sinkItem.name == searchInputText &&
+ searchResult.sinkItem.iconType == pseudoSink.iconType;
+ });
+ }).map(function(pseudoSink) {
+ pseudoSink.name = searchInputText;
+ return {sinkItem: pseudoSink,
+ substrings: [[0, searchInputText.length - 1]]};
+ }).concat(searchResultsToShow);
this.searchResultsToShow_ = searchResultsToShow;
},
@@ -1329,6 +1363,10 @@ Polymer({
return;
}
+ if (this.pseudoSinkSearchState_) {
+ sinkId = this.pseudoSinkSearchState_.mapRouteSinkId(sinkId);
+ }
+
// Check that |sinkId| exists and corresponds to |currentLaunchingSinkId_|.
if (!this.sinkMap_[sinkId] || this.currentLaunchingSinkId_ != sinkId) {
this.fire('report-resolved-route', {
@@ -1421,6 +1459,20 @@ Polymer({
},
/**
+ * Called when a search has completed up to route creation. |sinkId|
+ * identifies the sink that should be in |allSinks|, if a sink was found.
+ *
+ * @param {string} sinkId The ID of the sink that is the result of the
+ * currently pending search.
+ */
+ onReceiveSearchResult: function(sinkId) {
+ this.pseudoSinkSearchState_.receiveSinkResponse(sinkId);
+ this.pseudoSinkSearchState_.checkForRealSink(this.allSinks);
+ this.currentLaunchingSinkId_ =
+ this.pseudoSinkSearchState_.getCurrentLaunchingSinkId();
+ },
+
+ /**
* Called when a sink is clicked.
*
* @param {!Event} event The event object.
@@ -1430,7 +1482,24 @@ Polymer({
var clickedSink = (this.isUserSearching_) ?
this.$$('#searchResults').itemForElement(event.target).sinkItem :
this.$.sinkList.itemForElement(event.target);
- this.showOrCreateRoute_(clickedSink);
+ if (clickedSink.isPseudoSink) {
+ if (this.currentLaunchingSinkId_ == '') {
+ this.pseudoSinkSearchState_ = new PseudoSinkSearchState(clickedSink);
+ this.fire('search-sinks-and-create-route', {
+ id: clickedSink.id,
+ name: clickedSink.name,
+ domain: clickedSink.domain,
+ selectedCastMode:
+ this.shownCastModeValue_ == media_router.CastModeType.AUTO ?
+ clickedSink.castModes & -clickedSink.castModes :
+ this.shownCastModeValue_
+ });
+ this.currentLaunchingSinkId_ =
+ this.pseudoSinkSearchState_.getCurrentLaunchingSinkId();
apacible 2016/04/08 21:02:12 There's some metrics we keep track of under showOr
btolsch 2016/04/08 21:55:04 Are you saying I should add maybeReportUserFirstAc
apacible 2016/04/08 22:07:47 Oh, I didn't finish my thought here. :) Yes, add
btolsch 2016/04/11 08:19:35 Done.
+ }
+ } else {
+ this.showOrCreateRoute_(clickedSink);
+ }
this.fire('sink-click', {index: event['model'].index});
},
@@ -1488,11 +1557,13 @@ Polymer({
* name.
*/
rebuildSinksToShow_: function() {
- var sinksToShow = [];
+ var sinksToShow = this.allSinks.filter(function(sink) {
apacible 2016/04/08 21:02:12 We previously discussed the scenario: 1. Go to sea
btolsch 2016/04/08 21:55:04 Showing a sink in the sink list does not depend on
apacible 2016/04/08 22:07:47 I'm not following -- elaborate?
btolsch 2016/04/08 22:19:17 The typo probably didn't help. What I meant is tha
apacible 2016/04/08 22:48:40 Is the real sink always shown in the sink list aft
btolsch 2016/04/11 08:19:35 Done.
+ return !sink.isPseudoSink;
+ }, this);
if (this.userHasSelectedCastMode_) {
// If user explicitly selected a cast mode, then we show only sinks that
// are compatible with current cast mode or sinks that are active.
- sinksToShow = this.allSinks.filter(function(element) {
+ sinksToShow = sinksToShow.filter(function(element) {
return (element.castModes & this.shownCastModeValue_) ||
this.sinkToRouteMap_[element.id];
}, this);
@@ -1503,7 +1574,6 @@ Polymer({
// - Otherwise, the cast mode becomes auto mode.
// Either way, all sinks will be shown.
this.setShownCastMode_(this.computeCastMode_());
- sinksToShow = this.allSinks;
}
this.sinksToShow_ = sinksToShow;
@@ -1518,9 +1588,18 @@ Polymer({
this.sinkMap_ = {};
this.allSinks.forEach(function(sink) {
- this.sinkMap_[sink.id] = sink;
+ if (!sink.isPseudoSink) {
+ this.sinkMap_[sink.id] = sink;
+ }
}, this);
+ if (this.pseudoSinkSearchState_) {
+ this.pseudoSinkSearchState_.checkForRealSink(this.allSinks);
+ this.currentLaunchingSinkId_ =
+ this.pseudoSinkSearchState_.getCurrentLaunchingSinkId();
+ }
+ this.pseudoSinks_ =
+ this.allSinks.filter(function(sink) { return sink.isPseudoSink; });
this.rebuildSinksToShow_();
if (this.isUserSearching_) {
this.filterSinks_(this.searchInputText_);
@@ -1536,6 +1615,7 @@ Polymer({
* @private
*/
resetRouteCreationProperties_: function(creationSuccess) {
+ this.pseudoSinkSearchState_ = null;
this.currentLaunchingSinkId_ = '';
this.pendingCreatedRouteId_ = '';

Powered by Google App Engine
This is Rietveld 408576698