| OLD | NEW |
| 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 #include "chrome/browser/ui/webui/media_router/query_result_manager.h" | 5 #include "chrome/browser/ui/webui/media_router/query_result_manager.h" |
| 6 | 6 |
| 7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/media/router/media_router.h" | 9 #include "chrome/browser/media/router/media_router.h" |
| 10 #include "chrome/browser/media/router/media_sinks_observer.h" | 10 #include "chrome/browser/media/router/media_sinks_observer.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void QueryResultManager::UpdateWithSinksQueryResult( | 124 void QueryResultManager::UpdateWithSinksQueryResult( |
| 125 MediaCastMode cast_mode, | 125 MediaCastMode cast_mode, |
| 126 const std::vector<MediaSink>& result) { | 126 const std::vector<MediaSink>& result) { |
| 127 base::hash_set<MediaSink::Id> result_sink_ids; | 127 base::hash_set<MediaSink::Id> result_sink_ids; |
| 128 for (const MediaSink& sink : result) | 128 for (const MediaSink& sink : result) |
| 129 result_sink_ids.insert(sink.id()); | 129 result_sink_ids.insert(sink.id()); |
| 130 | 130 |
| 131 // (1) Iterate through current sink set, remove cast mode from those that | 131 // (1) Iterate through current sink set, remove cast mode from those that |
| 132 // do not appear in latest result. | 132 // do not appear in latest result. |
| 133 for (auto it = all_sinks_.begin(); it != all_sinks_.end(); /*no-op*/) { | 133 for (auto it = all_sinks_.begin(); it != all_sinks_.end(); /*no-op*/) { |
| 134 if (!ContainsKey(result_sink_ids, it->first)) { | 134 if (!base::ContainsKey(result_sink_ids, it->first)) { |
| 135 it->second.cast_modes.erase(cast_mode); | 135 it->second.cast_modes.erase(cast_mode); |
| 136 } | 136 } |
| 137 if (!IsValid(it->second)) { | 137 if (!IsValid(it->second)) { |
| 138 all_sinks_.erase(it++); | 138 all_sinks_.erase(it++); |
| 139 } else { | 139 } else { |
| 140 ++it; | 140 ++it; |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 // (2) Add / update sinks with latest result. | 144 // (2) Add / update sinks with latest result. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 170 void QueryResultManager::NotifyOnResultsUpdated() { | 170 void QueryResultManager::NotifyOnResultsUpdated() { |
| 171 std::vector<MediaSinkWithCastModes> sinks; | 171 std::vector<MediaSinkWithCastModes> sinks; |
| 172 for (const auto& sink_pair : all_sinks_) { | 172 for (const auto& sink_pair : all_sinks_) { |
| 173 sinks.push_back(sink_pair.second); | 173 sinks.push_back(sink_pair.second); |
| 174 } | 174 } |
| 175 FOR_EACH_OBSERVER(QueryResultManager::Observer, observers_, | 175 FOR_EACH_OBSERVER(QueryResultManager::Observer, observers_, |
| 176 OnResultsUpdated(sinks)); | 176 OnResultsUpdated(sinks)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace media_router | 179 } // namespace media_router |
| OLD | NEW |