Chromium Code Reviews| 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 const CastModesWithMediaSources& other) = default; | |
| 13 CastModesWithMediaSources::~CastModesWithMediaSources() {} | |
| 14 | |
| 15 void CastModesWithMediaSources::AddSource( | |
| 16 MediaCastMode cast_mode, const MediaSource& source) { | |
| 17 cast_modes_[cast_mode].insert(source); | |
| 18 } | |
| 19 | |
| 20 void CastModesWithMediaSources::RemoveSource( | |
| 21 MediaCastMode cast_mode, const MediaSource& source) { | |
| 22 cast_modes_[cast_mode].erase(source); | |
|
mark a. foltz
2016/09/09 22:22:26
I would use .find() here so you don't have to allo
takumif
2016/09/13 03:48:21
Done.
| |
| 23 if (cast_modes_[cast_mode].empty()) | |
| 24 cast_modes_.erase(cast_mode); | |
| 25 } | |
| 26 | |
| 27 bool CastModesWithMediaSources::HasSource( | |
| 28 MediaCastMode cast_mode, const MediaSource& source) const { | |
| 29 return base::ContainsKey(cast_modes_, cast_mode) | |
|
mark a. foltz
2016/09/09 22:22:26
Using .find() would avoid a double lookup in cast_
takumif
2016/09/13 03:48:21
Given the low number of cast modes, I think I pref
mark a. foltz
2016/09/13 17:30:15
There are at most 3, IIUC. It would be just as fas
takumif
2016/09/13 19:20:34
Acknowledged.
| |
| 30 ? base::ContainsKey(cast_modes_.at(cast_mode), source) | |
| 31 : false; | |
| 32 } | |
| 33 | |
| 34 CastModeSet CastModesWithMediaSources::GetCastModes() const { | |
| 35 CastModeSet cast_mode_set; | |
| 36 for (const auto& cast_mode_pair : cast_modes_) | |
| 37 cast_mode_set.insert(cast_mode_pair.first); | |
| 38 return cast_mode_set; | |
| 39 } | |
| 40 | |
| 41 bool CastModesWithMediaSources::IsEmpty() const { | |
| 42 return cast_modes_.empty(); | |
| 43 } | |
| 44 | |
| 45 } // namespace media_router | |
| OLD | NEW |