Chromium Code Reviews| Index: chrome/browser/media/combined_desktop_media_list.cc |
| diff --git a/chrome/browser/media/combined_desktop_media_list.cc b/chrome/browser/media/combined_desktop_media_list.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b0e1385900387730f2c7faf49e443dee1a719d13 |
| --- /dev/null |
| +++ b/chrome/browser/media/combined_desktop_media_list.cc |
| @@ -0,0 +1,121 @@ |
| +// 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 "chrome/browser/media/combined_desktop_media_list.h" |
| + |
| +CombinedDesktopMediaList::CombinedDesktopMediaList( |
| + std::vector<scoped_ptr<DesktopMediaList>>& media_lists) { |
|
Sergey Ulanov
2016/01/26 18:06:54
reference parameters can only be const. In this ca
GeorgeZ
2016/01/27 00:17:38
The reference is to avoid the copy of media_lists
|
| + DCHECK(media_lists.size()); |
| + for (size_t i = 0; i < media_lists.size(); i++) |
| + media_lists_.push_back(std::move(media_lists[i])); |
|
Sergey Ulanov
2016/01/26 18:06:54
Don't need the loop, just move the whole list:
me
GeorgeZ
2016/01/27 00:17:38
Done.
|
| +} |
| + |
| +CombinedDesktopMediaList::~CombinedDesktopMediaList() {} |
| + |
| +void CombinedDesktopMediaList::SetUpdatePeriod(base::TimeDelta period) { |
| + for (size_t i = 0; i < media_lists_.size(); i++) |
| + media_lists_[i]->SetUpdatePeriod(period); |
| +} |
| + |
| +void CombinedDesktopMediaList::SetThumbnailSize( |
| + const gfx::Size& thumbnail_size) { |
| + for (size_t i = 0; i < media_lists_.size(); i++) |
|
Sergey Ulanov
2016/01/26 18:06:54
Here and everywhere in this file use range-based f
GeorgeZ
2016/01/27 00:17:37
Done.
|
| + media_lists_[i]->SetThumbnailSize(thumbnail_size); |
| +} |
| + |
| +void CombinedDesktopMediaList::SetViewDialogWindowId( |
| + content::DesktopMediaID dialog_id) { |
| + for (size_t i = 0; i < media_lists_.size(); i++) |
| + media_lists_[i]->SetViewDialogWindowId(dialog_id); |
| +} |
| + |
| +void CombinedDesktopMediaList::StartUpdating( |
| + DesktopMediaListObserver* observer) { |
| + observer_ = observer; |
| + for (size_t i = 0; i < media_lists_.size(); i++) |
| + media_lists_[i]->StartUpdating(this); |
| +} |
| + |
| +int CombinedDesktopMediaList::GetSourceCount() const { |
| + int count = 0; |
| + for (size_t i = 0; i < media_lists_.size(); i++) |
| + count += media_lists_[i]->GetSourceCount(); |
| + |
| + return count; |
| +} |
| + |
| +const DesktopMediaList::Source& CombinedDesktopMediaList::GetSource( |
| + int index) const { |
| + for (size_t i = 0; i < media_lists_.size(); i++) { |
| + int count = media_lists_[i]->GetSourceCount(); |
| + if (index < count) |
| + return media_lists_[i]->GetSource(index); |
| + |
| + index -= count; |
| + } |
| + |
| + DCHECK(0) << "Index is invalid."; |
|
Sergey Ulanov
2016/01/26 18:06:54
NOTREACHED()
GeorgeZ
2016/01/27 00:17:38
Done.
|
| + return media_lists_[0]->GetSource(0); |
| +} |
| + |
| +void CombinedDesktopMediaList::OnSourceAdded(DesktopMediaList* list, |
| + int index) { |
| + int count = 0; |
| + for (size_t i = 0; i < media_lists_.size(); i++) { |
| + if (media_lists_[i].get() == list) { |
| + observer_->OnSourceAdded(this, count + index); |
| + return; |
| + } |
| + count += media_lists_[i]->GetSourceCount(); |
| + } |
| +} |
|
Sergey Ulanov
2016/01/26 18:06:54
Add NOTREACHED(). Same for methods below.
GeorgeZ
2016/01/27 00:17:38
Done.
|
| + |
| +void CombinedDesktopMediaList::OnSourceRemoved(DesktopMediaList* list, |
| + int index) { |
| + int count = 0; |
| + for (size_t i = 0; i < media_lists_.size(); i++) { |
| + if (media_lists_[i].get() == list) { |
| + observer_->OnSourceRemoved(this, count + index); |
| + return; |
| + } |
| + count += media_lists_[i]->GetSourceCount(); |
| + } |
| +} |
| + |
| +void CombinedDesktopMediaList::OnSourceMoved(DesktopMediaList* list, |
| + int old_index, |
| + int new_index) { |
| + int count = 0; |
| + for (size_t i = 0; i < media_lists_.size(); i++) { |
| + if (media_lists_[i].get() == list) { |
| + observer_->OnSourceMoved(this, count + old_index, count + new_index); |
| + return; |
| + } |
| + count += media_lists_[i]->GetSourceCount(); |
| + } |
| +} |
| + |
| +void CombinedDesktopMediaList::OnSourceNameChanged(DesktopMediaList* list, |
| + int index) { |
| + int count = 0; |
| + for (size_t i = 0; i < media_lists_.size(); i++) { |
| + if (media_lists_[i].get() == list) { |
| + observer_->OnSourceNameChanged(this, count + index); |
| + return; |
| + } |
| + count += media_lists_[i]->GetSourceCount(); |
| + } |
| +} |
| + |
| +void CombinedDesktopMediaList::OnSourceThumbnailChanged(DesktopMediaList* list, |
| + int index) { |
| + int count = 0; |
| + for (size_t i = 0; i < media_lists_.size(); i++) { |
| + if (media_lists_[i].get() == list) { |
| + observer_->OnSourceThumbnailChanged(this, count + index); |
| + return; |
| + } |
| + count += media_lists_[i]->GetSourceCount(); |
| + } |
| +} |