| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/stl_util.h" |
| 6 #include "chrome/browser/ui/webui/media_router/cast_modes_with_media_sources.h" |
| 7 |
| 8 namespace media_router { |
| 9 |
| 10 CastModesWithMediaSources::CastModesWithMediaSources() {} |
| 11 CastModesWithMediaSources::CastModesWithMediaSources( |
| 12 CastModesWithMediaSources&& other) = default; |
| 13 CastModesWithMediaSources::~CastModesWithMediaSources() {} |
| 14 |
| 15 void CastModesWithMediaSources::AddSource(MediaCastMode cast_mode, |
| 16 const MediaSource& source) { |
| 17 cast_modes_[cast_mode].insert(source); |
| 18 } |
| 19 |
| 20 void CastModesWithMediaSources::RemoveSource(MediaCastMode cast_mode, |
| 21 const MediaSource& source) { |
| 22 const auto& cast_mode_it = cast_modes_.find(cast_mode); |
| 23 if (cast_mode_it != cast_modes_.end()) { |
| 24 auto& sources_for_cast_mode = cast_mode_it->second; |
| 25 sources_for_cast_mode.erase(source); |
| 26 if (sources_for_cast_mode.empty()) |
| 27 cast_modes_.erase(cast_mode); |
| 28 } |
| 29 } |
| 30 |
| 31 bool CastModesWithMediaSources::HasSource(MediaCastMode cast_mode, |
| 32 const MediaSource& source) const { |
| 33 return base::ContainsKey(cast_modes_, cast_mode) |
| 34 ? base::ContainsKey(cast_modes_.at(cast_mode), source) |
| 35 : false; |
| 36 } |
| 37 |
| 38 CastModeSet CastModesWithMediaSources::GetCastModes() const { |
| 39 CastModeSet cast_mode_set; |
| 40 for (const auto& cast_mode_pair : cast_modes_) |
| 41 cast_mode_set.insert(cast_mode_pair.first); |
| 42 return cast_mode_set; |
| 43 } |
| 44 |
| 45 bool CastModesWithMediaSources::IsEmpty() const { |
| 46 return cast_modes_.empty(); |
| 47 } |
| 48 |
| 49 } // namespace media_router |
| OLD | NEW |