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

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

Issue 2221933003: [Media Router WebUI] Append new sinks to the end of the list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes per imcheng@'s comments. Created 4 years, 4 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
« no previous file with comments | « no previous file | chrome/test/data/webui/media_router/media_router_container_sink_list_tests.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ecd5810bfda626b3c608c9a2d5f20ea75b5d282f..25ef3c8f7f6d15ce8227cab33f7acb4f29f252ca 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
@@ -1989,7 +1989,7 @@ Polymer({
* name.
*/
rebuildSinksToShow_: function() {
- var sinksToShow = this.allSinks.filter(function(sink) {
+ var updatedSinkList = this.allSinks.filter(function(sink) {
return !sink.isPseudoSink;
}, this);
if (this.pseudoSinkSearchState_) {
@@ -2000,13 +2000,13 @@ Polymer({
// list but |currentLaunchingSinkId_| is non-empty (thereby preventing any
// other sink from launching).
if (pendingPseudoSink.id == this.currentLaunchingSinkId_) {
- sinksToShow.unshift(pendingPseudoSink);
+ updatedSinkList.unshift(pendingPseudoSink);
}
}
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 = sinksToShow.filter(function(element) {
+ updatedSinkList = updatedSinkList.filter(function(element) {
return (element.castModes & this.shownCastModeValue_) ||
this.sinkToRouteMap_[element.id];
}, this);
@@ -2019,7 +2019,27 @@ Polymer({
this.setShownCastMode_(this.computeCastMode_());
}
- this.sinksToShow_ = sinksToShow;
+ // When there's an updated list of sinks, append any new sinks to the end
+ // of the existing list. This prevents sinks randomly jumping around the
+ // dialog, which can surprise users / lead to inadvertently casting to the
+ // wrong sink.
+ if (this.sinksToShow_) {
+ for (var i = this.sinksToShow_.length - 1; i >= 0; i--) {
+ var index = updatedSinkList.findIndex(function(updatedSink) {
+ return this.sinksToShow_[i].id == updatedSink.id; }.bind(this));
+ if (index < 0) {
+ // Remove any sinks that are no longer discovered.
+ this.sinksToShow_.splice(i, 1);
+ } else {
+ // If the sink exists, remove it from |updatedSinkList| as it is
+ // already in |sinksToShow_|.
+ updatedSinkList.splice(index, 1);
+ }
+ }
+
+ updatedSinkList = this.sinksToShow_.concat(updatedSinkList);
+ }
+ this.sinksToShow_ = updatedSinkList;
},
/**
« no previous file with comments | « no previous file | chrome/test/data/webui/media_router/media_router_container_sink_list_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698