Chromium Code Reviews| Index: chrome/browser/ui/webui/media_router/cast_modes_with_media_sources.cc |
| diff --git a/chrome/browser/ui/webui/media_router/cast_modes_with_media_sources.cc b/chrome/browser/ui/webui/media_router/cast_modes_with_media_sources.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1f3582a9fb3aac8f4ea232a5cb4127ee9cfa9b16 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/media_router/cast_modes_with_media_sources.cc |
| @@ -0,0 +1,45 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/stl_util.h" |
| +#include "chrome/browser/ui/webui/media_router/cast_modes_with_media_sources.h" |
| + |
| +namespace media_router { |
| + |
| +CastModesWithMediaSources::CastModesWithMediaSources() {} |
| +CastModesWithMediaSources::CastModesWithMediaSources( |
| + const CastModesWithMediaSources& other) = default; |
| +CastModesWithMediaSources::~CastModesWithMediaSources() {} |
| + |
| +void CastModesWithMediaSources::AddSource( |
| + MediaCastMode cast_mode, const MediaSource& source) { |
| + cast_modes_[cast_mode].insert(source); |
| +} |
| + |
| +void CastModesWithMediaSources::RemoveSource( |
| + MediaCastMode cast_mode, const MediaSource& source) { |
| + 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.
|
| + if (cast_modes_[cast_mode].empty()) |
| + cast_modes_.erase(cast_mode); |
| +} |
| + |
| +bool CastModesWithMediaSources::HasSource( |
| + MediaCastMode cast_mode, const MediaSource& source) const { |
| + 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.
|
| + ? base::ContainsKey(cast_modes_.at(cast_mode), source) |
| + : false; |
| +} |
| + |
| +CastModeSet CastModesWithMediaSources::GetCastModes() const { |
| + CastModeSet cast_mode_set; |
| + for (const auto& cast_mode_pair : cast_modes_) |
| + cast_mode_set.insert(cast_mode_pair.first); |
| + return cast_mode_set; |
| +} |
| + |
| +bool CastModesWithMediaSources::IsEmpty() const { |
| + return cast_modes_.empty(); |
| +} |
| + |
| +} // namespace media_router |