Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/browser/media/combined_desktop_media_list.cc

Issue 1622733002: Add CombinedDesktopMediaList class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed for android build Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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<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
9 DCHECK(media_lists.size());
10 for (size_t i = 0; i < media_lists.size(); i++)
11 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.
12 }
13
14 CombinedDesktopMediaList::~CombinedDesktopMediaList() {}
15
16 void CombinedDesktopMediaList::SetUpdatePeriod(base::TimeDelta period) {
17 for (size_t i = 0; i < media_lists_.size(); i++)
18 media_lists_[i]->SetUpdatePeriod(period);
19 }
20
21 void CombinedDesktopMediaList::SetThumbnailSize(
22 const gfx::Size& thumbnail_size) {
23 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.
24 media_lists_[i]->SetThumbnailSize(thumbnail_size);
25 }
26
27 void CombinedDesktopMediaList::SetViewDialogWindowId(
28 content::DesktopMediaID dialog_id) {
29 for (size_t i = 0; i < media_lists_.size(); i++)
30 media_lists_[i]->SetViewDialogWindowId(dialog_id);
31 }
32
33 void CombinedDesktopMediaList::StartUpdating(
34 DesktopMediaListObserver* observer) {
35 observer_ = observer;
36 for (size_t i = 0; i < media_lists_.size(); i++)
37 media_lists_[i]->StartUpdating(this);
38 }
39
40 int CombinedDesktopMediaList::GetSourceCount() const {
41 int count = 0;
42 for (size_t i = 0; i < media_lists_.size(); i++)
43 count += media_lists_[i]->GetSourceCount();
44
45 return count;
46 }
47
48 const DesktopMediaList::Source& CombinedDesktopMediaList::GetSource(
49 int index) const {
50 for (size_t i = 0; i < media_lists_.size(); i++) {
51 int count = media_lists_[i]->GetSourceCount();
52 if (index < count)
53 return media_lists_[i]->GetSource(index);
54
55 index -= count;
56 }
57
58 DCHECK(0) << "Index is invalid.";
Sergey Ulanov 2016/01/26 18:06:54 NOTREACHED()
GeorgeZ 2016/01/27 00:17:38 Done.
59 return media_lists_[0]->GetSource(0);
60 }
61
62 void CombinedDesktopMediaList::OnSourceAdded(DesktopMediaList* list,
63 int index) {
64 int count = 0;
65 for (size_t i = 0; i < media_lists_.size(); i++) {
66 if (media_lists_[i].get() == list) {
67 observer_->OnSourceAdded(this, count + index);
68 return;
69 }
70 count += media_lists_[i]->GetSourceCount();
71 }
72 }
Sergey Ulanov 2016/01/26 18:06:54 Add NOTREACHED(). Same for methods below.
GeorgeZ 2016/01/27 00:17:38 Done.
73
74 void CombinedDesktopMediaList::OnSourceRemoved(DesktopMediaList* list,
75 int index) {
76 int count = 0;
77 for (size_t i = 0; i < media_lists_.size(); i++) {
78 if (media_lists_[i].get() == list) {
79 observer_->OnSourceRemoved(this, count + index);
80 return;
81 }
82 count += media_lists_[i]->GetSourceCount();
83 }
84 }
85
86 void CombinedDesktopMediaList::OnSourceMoved(DesktopMediaList* list,
87 int old_index,
88 int new_index) {
89 int count = 0;
90 for (size_t i = 0; i < media_lists_.size(); i++) {
91 if (media_lists_[i].get() == list) {
92 observer_->OnSourceMoved(this, count + old_index, count + new_index);
93 return;
94 }
95 count += media_lists_[i]->GetSourceCount();
96 }
97 }
98
99 void CombinedDesktopMediaList::OnSourceNameChanged(DesktopMediaList* list,
100 int index) {
101 int count = 0;
102 for (size_t i = 0; i < media_lists_.size(); i++) {
103 if (media_lists_[i].get() == list) {
104 observer_->OnSourceNameChanged(this, count + index);
105 return;
106 }
107 count += media_lists_[i]->GetSourceCount();
108 }
109 }
110
111 void CombinedDesktopMediaList::OnSourceThumbnailChanged(DesktopMediaList* list,
112 int index) {
113 int count = 0;
114 for (size_t i = 0; i < media_lists_.size(); i++) {
115 if (media_lists_[i].get() == list) {
116 observer_->OnSourceThumbnailChanged(this, count + index);
117 return;
118 }
119 count += media_lists_[i]->GetSourceCount();
120 }
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698