| 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 "chrome/browser/media/combined_desktop_media_list.h" | |
| 6 | |
| 7 CombinedDesktopMediaList::CombinedDesktopMediaList( | |
| 8 std::vector<std::unique_ptr<DesktopMediaList>>& media_lists) | |
| 9 : media_lists_(std::move(media_lists)) { | |
| 10 DCHECK(media_lists_.size()); | |
| 11 } | |
| 12 | |
| 13 CombinedDesktopMediaList::~CombinedDesktopMediaList() {} | |
| 14 | |
| 15 void CombinedDesktopMediaList::SetUpdatePeriod(base::TimeDelta period) { | |
| 16 for (const auto& list : media_lists_) | |
| 17 list->SetUpdatePeriod(period); | |
| 18 } | |
| 19 | |
| 20 void CombinedDesktopMediaList::SetThumbnailSize( | |
| 21 const gfx::Size& thumbnail_size) { | |
| 22 for (const auto& list : media_lists_) | |
| 23 list->SetThumbnailSize(thumbnail_size); | |
| 24 } | |
| 25 | |
| 26 void CombinedDesktopMediaList::SetViewDialogWindowId( | |
| 27 content::DesktopMediaID dialog_id) { | |
| 28 for (const auto& list : media_lists_) | |
| 29 list->SetViewDialogWindowId(dialog_id); | |
| 30 } | |
| 31 | |
| 32 void CombinedDesktopMediaList::StartUpdating( | |
| 33 DesktopMediaListObserver* observer) { | |
| 34 observer_ = observer; | |
| 35 for (const auto& list : media_lists_) | |
| 36 list->StartUpdating(this); | |
| 37 } | |
| 38 | |
| 39 int CombinedDesktopMediaList::GetSourceCount() const { | |
| 40 int count = 0; | |
| 41 for (const auto& list : media_lists_) | |
| 42 count += list->GetSourceCount(); | |
| 43 | |
| 44 return count; | |
| 45 } | |
| 46 | |
| 47 const DesktopMediaList::Source& CombinedDesktopMediaList::GetSource( | |
| 48 int index) const { | |
| 49 for (const auto& list : media_lists_) { | |
| 50 int count = list->GetSourceCount(); | |
| 51 if (index < count) | |
| 52 return list->GetSource(index); | |
| 53 | |
| 54 index -= count; | |
| 55 } | |
| 56 | |
| 57 NOTREACHED(); | |
| 58 return media_lists_[0]->GetSource(0); | |
| 59 } | |
| 60 | |
| 61 void CombinedDesktopMediaList::OnSourceAdded(DesktopMediaList* list, | |
| 62 int index) { | |
| 63 int count = 0; | |
| 64 for (const auto& cur_list : media_lists_) { | |
| 65 if (cur_list.get() == list) { | |
| 66 observer_->OnSourceAdded(this, count + index); | |
| 67 return; | |
| 68 } | |
| 69 count += cur_list->GetSourceCount(); | |
| 70 } | |
| 71 | |
| 72 NOTREACHED(); | |
| 73 } | |
| 74 | |
| 75 void CombinedDesktopMediaList::OnSourceRemoved(DesktopMediaList* list, | |
| 76 int index) { | |
| 77 int count = 0; | |
| 78 for (const auto& cur_list : media_lists_) { | |
| 79 if (cur_list.get() == list) { | |
| 80 observer_->OnSourceRemoved(this, count + index); | |
| 81 return; | |
| 82 } | |
| 83 count += cur_list->GetSourceCount(); | |
| 84 } | |
| 85 | |
| 86 NOTREACHED(); | |
| 87 } | |
| 88 | |
| 89 void CombinedDesktopMediaList::OnSourceMoved(DesktopMediaList* list, | |
| 90 int old_index, | |
| 91 int new_index) { | |
| 92 int count = 0; | |
| 93 for (const auto& cur_list : media_lists_) { | |
| 94 if (cur_list.get() == list) { | |
| 95 observer_->OnSourceMoved(this, count + old_index, count + new_index); | |
| 96 return; | |
| 97 } | |
| 98 count += cur_list->GetSourceCount(); | |
| 99 } | |
| 100 | |
| 101 NOTREACHED(); | |
| 102 } | |
| 103 | |
| 104 void CombinedDesktopMediaList::OnSourceNameChanged(DesktopMediaList* list, | |
| 105 int index) { | |
| 106 int count = 0; | |
| 107 for (const auto& cur_list : media_lists_) { | |
| 108 if (cur_list.get() == list) { | |
| 109 observer_->OnSourceNameChanged(this, count + index); | |
| 110 return; | |
| 111 } | |
| 112 count += cur_list->GetSourceCount(); | |
| 113 } | |
| 114 | |
| 115 NOTREACHED(); | |
| 116 } | |
| 117 | |
| 118 void CombinedDesktopMediaList::OnSourceThumbnailChanged(DesktopMediaList* list, | |
| 119 int index) { | |
| 120 int count = 0; | |
| 121 for (const auto& cur_list : media_lists_) { | |
| 122 if (cur_list.get() == list) { | |
| 123 observer_->OnSourceThumbnailChanged(this, count + index); | |
| 124 return; | |
| 125 } | |
| 126 count += cur_list->GetSourceCount(); | |
| 127 } | |
| 128 | |
| 129 NOTREACHED(); | |
| 130 } | |
| OLD | NEW |