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

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

Issue 1554243002: Add CombinedDesktopMediaList. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/media/desktop_media_list_ash.h" 5 #include "chrome/browser/media/desktop_media_list_ash.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 typedef std::set<content::DesktopMediaID> SourceSet; 90 typedef std::set<content::DesktopMediaID> SourceSet;
91 SourceSet new_source_set; 91 SourceSet new_source_set;
92 for (size_t i = 0; i < new_sources.size(); ++i) { 92 for (size_t i = 0; i < new_sources.size(); ++i) {
93 new_source_set.insert(new_sources[i].id); 93 new_source_set.insert(new_sources[i].id);
94 } 94 }
95 // Iterate through the old sources to find the removed sources. 95 // Iterate through the old sources to find the removed sources.
96 for (size_t i = 0; i < sources_.size(); ++i) { 96 for (size_t i = 0; i < sources_.size(); ++i) {
97 if (new_source_set.find(sources_[i].id) == new_source_set.end()) { 97 if (new_source_set.find(sources_[i].id) == new_source_set.end()) {
98 sources_.erase(sources_.begin() + i); 98 sources_.erase(sources_.begin() + i);
99 observer_->OnSourceRemoved(i); 99 observer_->OnSourceRemoved(this, i);
100 --i; 100 --i;
101 } 101 }
102 } 102 }
103 // Iterate through the new sources to find the added sources. 103 // Iterate through the new sources to find the added sources.
104 if (new_sources.size() > sources_.size()) { 104 if (new_sources.size() > sources_.size()) {
105 SourceSet old_source_set; 105 SourceSet old_source_set;
106 for (size_t i = 0; i < sources_.size(); ++i) { 106 for (size_t i = 0; i < sources_.size(); ++i) {
107 old_source_set.insert(sources_[i].id); 107 old_source_set.insert(sources_[i].id);
108 } 108 }
109 109
110 for (size_t i = 0; i < new_sources.size(); ++i) { 110 for (size_t i = 0; i < new_sources.size(); ++i) {
111 if (old_source_set.find(new_sources[i].id) == old_source_set.end()) { 111 if (old_source_set.find(new_sources[i].id) == old_source_set.end()) {
112 sources_.insert(sources_.begin() + i, Source()); 112 sources_.insert(sources_.begin() + i, Source());
113 sources_[i].id = new_sources[i].id; 113 sources_[i].id = new_sources[i].id;
114 sources_[i].name = new_sources[i].name; 114 sources_[i].name = new_sources[i].name;
115 observer_->OnSourceAdded(i); 115 observer_->OnSourceAdded(this, i);
116 } 116 }
117 } 117 }
118 } 118 }
119 DCHECK_EQ(new_sources.size(), sources_.size()); 119 DCHECK_EQ(new_sources.size(), sources_.size());
120 120
121 // Find the moved/changed sources. 121 // Find the moved/changed sources.
122 size_t pos = 0; 122 size_t pos = 0;
123 while (pos < sources_.size()) { 123 while (pos < sources_.size()) {
124 if (!(sources_[pos].id == new_sources[pos].id)) { 124 if (!(sources_[pos].id == new_sources[pos].id)) {
125 // Find the source that should be moved to |pos|, starting from |pos + 1| 125 // Find the source that should be moved to |pos|, starting from |pos + 1|
126 // of |sources_|, because entries before |pos| should have been sorted. 126 // of |sources_|, because entries before |pos| should have been sorted.
127 size_t old_pos = pos + 1; 127 size_t old_pos = pos + 1;
128 for (; old_pos < sources_.size(); ++old_pos) { 128 for (; old_pos < sources_.size(); ++old_pos) {
129 if (sources_[old_pos].id == new_sources[pos].id) 129 if (sources_[old_pos].id == new_sources[pos].id)
130 break; 130 break;
131 } 131 }
132 DCHECK(sources_[old_pos].id == new_sources[pos].id); 132 DCHECK(sources_[old_pos].id == new_sources[pos].id);
133 133
134 // Move the source from |old_pos| to |pos|. 134 // Move the source from |old_pos| to |pos|.
135 Source temp = sources_[old_pos]; 135 Source temp = sources_[old_pos];
136 sources_.erase(sources_.begin() + old_pos); 136 sources_.erase(sources_.begin() + old_pos);
137 sources_.insert(sources_.begin() + pos, temp); 137 sources_.insert(sources_.begin() + pos, temp);
138 138
139 observer_->OnSourceMoved(old_pos, pos); 139 observer_->OnSourceMoved(this, old_pos, pos);
140 } 140 }
141 141
142 if (sources_[pos].name != new_sources[pos].name) { 142 if (sources_[pos].name != new_sources[pos].name) {
143 sources_[pos].name = new_sources[pos].name; 143 sources_[pos].name = new_sources[pos].name;
144 observer_->OnSourceNameChanged(pos); 144 observer_->OnSourceNameChanged(this, pos);
145 } 145 }
146 ++pos; 146 ++pos;
147 } 147 }
148 } 148 }
149 149
150 void DesktopMediaListAsh::EnumerateWindowsForRoot( 150 void DesktopMediaListAsh::EnumerateWindowsForRoot(
151 std::vector<DesktopMediaListAsh::SourceDescription>* sources, 151 std::vector<DesktopMediaListAsh::SourceDescription>* sources,
152 aura::Window* root_window, 152 aura::Window* root_window,
153 int container_id) { 153 int container_id) {
154 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 154 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 base::Bind(&DesktopMediaListAsh::OnThumbnailCaptured, 229 base::Bind(&DesktopMediaListAsh::OnThumbnailCaptured,
230 weak_factory_.GetWeakPtr(), 230 weak_factory_.GetWeakPtr(),
231 id)); 231 id));
232 } 232 }
233 233
234 void DesktopMediaListAsh::OnThumbnailCaptured(content::DesktopMediaID id, 234 void DesktopMediaListAsh::OnThumbnailCaptured(content::DesktopMediaID id,
235 const gfx::Image& image) { 235 const gfx::Image& image) {
236 for (size_t i = 0; i < sources_.size(); ++i) { 236 for (size_t i = 0; i < sources_.size(); ++i) {
237 if (sources_[i].id == id) { 237 if (sources_[i].id == id) {
238 sources_[i].thumbnail = image.AsImageSkia(); 238 sources_[i].thumbnail = image.AsImageSkia();
239 observer_->OnSourceThumbnailChanged(i); 239 observer_->OnSourceThumbnailChanged(this, i);
240 break; 240 break;
241 } 241 }
242 } 242 }
243 243
244 --pending_window_capture_requests_; 244 --pending_window_capture_requests_;
245 DCHECK_GE(pending_window_capture_requests_, 0); 245 DCHECK_GE(pending_window_capture_requests_, 0);
246 246
247 if (!pending_window_capture_requests_) { 247 if (!pending_window_capture_requests_) {
248 // Once we've finished capturing all windows post a task for the next list 248 // Once we've finished capturing all windows post a task for the next list
249 // update. 249 // update.
250 BrowserThread::PostDelayedTask( 250 BrowserThread::PostDelayedTask(
251 BrowserThread::UI, FROM_HERE, 251 BrowserThread::UI, FROM_HERE,
252 base::Bind(&DesktopMediaListAsh::Refresh, 252 base::Bind(&DesktopMediaListAsh::Refresh,
253 weak_factory_.GetWeakPtr()), 253 weak_factory_.GetWeakPtr()),
254 update_period_); 254 update_period_);
255 } 255 }
256 } 256 }
OLDNEW
« no previous file with comments | « chrome/browser/media/combined_desktop_media_list.cc ('k') | chrome/browser/media/desktop_media_list_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698