| OLD | NEW |
| 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/native_desktop_media_list.h" | 5 #include "chrome/browser/media/native_desktop_media_list.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 const std::vector<SourceDescription>& new_sources) { | 300 const std::vector<SourceDescription>& new_sources) { |
| 301 typedef std::set<content::DesktopMediaID> SourceSet; | 301 typedef std::set<content::DesktopMediaID> SourceSet; |
| 302 SourceSet new_source_set; | 302 SourceSet new_source_set; |
| 303 for (size_t i = 0; i < new_sources.size(); ++i) { | 303 for (size_t i = 0; i < new_sources.size(); ++i) { |
| 304 new_source_set.insert(new_sources[i].id); | 304 new_source_set.insert(new_sources[i].id); |
| 305 } | 305 } |
| 306 // Iterate through the old sources to find the removed sources. | 306 // Iterate through the old sources to find the removed sources. |
| 307 for (size_t i = 0; i < sources_.size(); ++i) { | 307 for (size_t i = 0; i < sources_.size(); ++i) { |
| 308 if (new_source_set.find(sources_[i].id) == new_source_set.end()) { | 308 if (new_source_set.find(sources_[i].id) == new_source_set.end()) { |
| 309 sources_.erase(sources_.begin() + i); | 309 sources_.erase(sources_.begin() + i); |
| 310 observer_->OnSourceRemoved(i); | 310 observer_->OnSourceRemoved(this, i); |
| 311 --i; | 311 --i; |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 // Iterate through the new sources to find the added sources. | 314 // Iterate through the new sources to find the added sources. |
| 315 if (new_sources.size() > sources_.size()) { | 315 if (new_sources.size() > sources_.size()) { |
| 316 SourceSet old_source_set; | 316 SourceSet old_source_set; |
| 317 for (size_t i = 0; i < sources_.size(); ++i) { | 317 for (size_t i = 0; i < sources_.size(); ++i) { |
| 318 old_source_set.insert(sources_[i].id); | 318 old_source_set.insert(sources_[i].id); |
| 319 } | 319 } |
| 320 | 320 |
| 321 for (size_t i = 0; i < new_sources.size(); ++i) { | 321 for (size_t i = 0; i < new_sources.size(); ++i) { |
| 322 if (old_source_set.find(new_sources[i].id) == old_source_set.end()) { | 322 if (old_source_set.find(new_sources[i].id) == old_source_set.end()) { |
| 323 sources_.insert(sources_.begin() + i, Source()); | 323 sources_.insert(sources_.begin() + i, Source()); |
| 324 sources_[i].id = new_sources[i].id; | 324 sources_[i].id = new_sources[i].id; |
| 325 sources_[i].name = new_sources[i].name; | 325 sources_[i].name = new_sources[i].name; |
| 326 observer_->OnSourceAdded(i); | 326 observer_->OnSourceAdded(this, i); |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 DCHECK_EQ(new_sources.size(), sources_.size()); | 330 DCHECK_EQ(new_sources.size(), sources_.size()); |
| 331 | 331 |
| 332 // Find the moved/changed sources. | 332 // Find the moved/changed sources. |
| 333 size_t pos = 0; | 333 size_t pos = 0; |
| 334 while (pos < sources_.size()) { | 334 while (pos < sources_.size()) { |
| 335 if (!(sources_[pos].id == new_sources[pos].id)) { | 335 if (!(sources_[pos].id == new_sources[pos].id)) { |
| 336 // Find the source that should be moved to |pos|, starting from |pos + 1| | 336 // Find the source that should be moved to |pos|, starting from |pos + 1| |
| 337 // of |sources_|, because entries before |pos| should have been sorted. | 337 // of |sources_|, because entries before |pos| should have been sorted. |
| 338 size_t old_pos = pos + 1; | 338 size_t old_pos = pos + 1; |
| 339 for (; old_pos < sources_.size(); ++old_pos) { | 339 for (; old_pos < sources_.size(); ++old_pos) { |
| 340 if (sources_[old_pos].id == new_sources[pos].id) | 340 if (sources_[old_pos].id == new_sources[pos].id) |
| 341 break; | 341 break; |
| 342 } | 342 } |
| 343 DCHECK(sources_[old_pos].id == new_sources[pos].id); | 343 DCHECK(sources_[old_pos].id == new_sources[pos].id); |
| 344 | 344 |
| 345 // Move the source from |old_pos| to |pos|. | 345 // Move the source from |old_pos| to |pos|. |
| 346 Source temp = sources_[old_pos]; | 346 Source temp = sources_[old_pos]; |
| 347 sources_.erase(sources_.begin() + old_pos); | 347 sources_.erase(sources_.begin() + old_pos); |
| 348 sources_.insert(sources_.begin() + pos, temp); | 348 sources_.insert(sources_.begin() + pos, temp); |
| 349 | 349 |
| 350 observer_->OnSourceMoved(old_pos, pos); | 350 observer_->OnSourceMoved(this, old_pos, pos); |
| 351 } | 351 } |
| 352 | 352 |
| 353 if (sources_[pos].name != new_sources[pos].name) { | 353 if (sources_[pos].name != new_sources[pos].name) { |
| 354 sources_[pos].name = new_sources[pos].name; | 354 sources_[pos].name = new_sources[pos].name; |
| 355 observer_->OnSourceNameChanged(pos); | 355 observer_->OnSourceNameChanged(this, pos); |
| 356 } | 356 } |
| 357 ++pos; | 357 ++pos; |
| 358 } | 358 } |
| 359 } | 359 } |
| 360 | 360 |
| 361 void NativeDesktopMediaList::OnSourceThumbnail( | 361 void NativeDesktopMediaList::OnSourceThumbnail( |
| 362 int index, | 362 int index, |
| 363 const gfx::ImageSkia& image) { | 363 const gfx::ImageSkia& image) { |
| 364 DCHECK_LT(index, static_cast<int>(sources_.size())); | 364 DCHECK_LT(index, static_cast<int>(sources_.size())); |
| 365 sources_[index].thumbnail = image; | 365 sources_[index].thumbnail = image; |
| 366 observer_->OnSourceThumbnailChanged(index); | 366 observer_->OnSourceThumbnailChanged(this, index); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void NativeDesktopMediaList::OnRefreshFinished() { | 369 void NativeDesktopMediaList::OnRefreshFinished() { |
| 370 BrowserThread::PostDelayedTask( | 370 BrowserThread::PostDelayedTask( |
| 371 BrowserThread::UI, FROM_HERE, | 371 BrowserThread::UI, FROM_HERE, |
| 372 base::Bind(&NativeDesktopMediaList::Refresh, | 372 base::Bind(&NativeDesktopMediaList::Refresh, |
| 373 weak_factory_.GetWeakPtr()), | 373 weak_factory_.GetWeakPtr()), |
| 374 update_period_); | 374 update_period_); |
| 375 } | 375 } |
| OLD | NEW |