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 | |
10 #include <map> | 9 #include <map> |
11 #include <set> | 10 #include <set> |
12 #include <sstream> | 11 #include <sstream> |
| 12 #include <utility> |
13 | 13 |
14 #include "base/hash.h" | 14 #include "base/hash.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
19 #include "chrome/browser/media/desktop_media_list_observer.h" | 19 #include "chrome/browser/media/desktop_media_list_observer.h" |
20 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "media/base/video_util.h" | 22 #include "media/base/video_util.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 ImageHashesMap image_hashes_; | 114 ImageHashesMap image_hashes_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(Worker); | 116 DISALLOW_COPY_AND_ASSIGN(Worker); |
117 }; | 117 }; |
118 | 118 |
119 NativeDesktopMediaList::Worker::Worker( | 119 NativeDesktopMediaList::Worker::Worker( |
120 base::WeakPtr<NativeDesktopMediaList> media_list, | 120 base::WeakPtr<NativeDesktopMediaList> media_list, |
121 scoped_ptr<webrtc::ScreenCapturer> screen_capturer, | 121 scoped_ptr<webrtc::ScreenCapturer> screen_capturer, |
122 scoped_ptr<webrtc::WindowCapturer> window_capturer) | 122 scoped_ptr<webrtc::WindowCapturer> window_capturer) |
123 : media_list_(media_list), | 123 : media_list_(media_list), |
124 screen_capturer_(screen_capturer.Pass()), | 124 screen_capturer_(std::move(screen_capturer)), |
125 window_capturer_(window_capturer.Pass()) { | 125 window_capturer_(std::move(window_capturer)) { |
126 if (screen_capturer_) | 126 if (screen_capturer_) |
127 screen_capturer_->Start(this); | 127 screen_capturer_->Start(this); |
128 if (window_capturer_) | 128 if (window_capturer_) |
129 window_capturer_->Start(this); | 129 window_capturer_->Start(this); |
130 } | 130 } |
131 | 131 |
132 NativeDesktopMediaList::Worker::~Worker() {} | 132 NativeDesktopMediaList::Worker::~Worker() {} |
133 | 133 |
134 void NativeDesktopMediaList::Worker::Refresh( | 134 void NativeDesktopMediaList::Worker::Refresh( |
135 const gfx::Size& thumbnail_size, | 135 const gfx::Size& thumbnail_size, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // |current_frame_| may be NULL if capture failed (e.g. because window has | 202 // |current_frame_| may be NULL if capture failed (e.g. because window has |
203 // been closed). | 203 // been closed). |
204 if (current_frame_) { | 204 if (current_frame_) { |
205 uint32_t frame_hash = GetFrameHash(current_frame_.get()); | 205 uint32_t frame_hash = GetFrameHash(current_frame_.get()); |
206 new_image_hashes[source.id] = frame_hash; | 206 new_image_hashes[source.id] = frame_hash; |
207 | 207 |
208 // Scale the image only if it has changed. | 208 // Scale the image only if it has changed. |
209 ImageHashesMap::iterator it = image_hashes_.find(source.id); | 209 ImageHashesMap::iterator it = image_hashes_.find(source.id); |
210 if (it == image_hashes_.end() || it->second != frame_hash) { | 210 if (it == image_hashes_.end() || it->second != frame_hash) { |
211 gfx::ImageSkia thumbnail = | 211 gfx::ImageSkia thumbnail = |
212 ScaleDesktopFrame(current_frame_.Pass(), thumbnail_size); | 212 ScaleDesktopFrame(std::move(current_frame_), thumbnail_size); |
213 BrowserThread::PostTask( | 213 BrowserThread::PostTask( |
214 BrowserThread::UI, FROM_HERE, | 214 BrowserThread::UI, FROM_HERE, |
215 base::Bind(&NativeDesktopMediaList::OnSourceThumbnail, | 215 base::Bind(&NativeDesktopMediaList::OnSourceThumbnail, |
216 media_list_, i, thumbnail)); | 216 media_list_, i, thumbnail)); |
217 } | 217 } |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 image_hashes_.swap(new_image_hashes); | 221 image_hashes_.swap(new_image_hashes); |
222 | 222 |
223 BrowserThread::PostTask( | 223 BrowserThread::PostTask( |
224 BrowserThread::UI, FROM_HERE, | 224 BrowserThread::UI, FROM_HERE, |
225 base::Bind(&NativeDesktopMediaList::OnRefreshFinished, media_list_)); | 225 base::Bind(&NativeDesktopMediaList::OnRefreshFinished, media_list_)); |
226 } | 226 } |
227 | 227 |
228 webrtc::SharedMemory* NativeDesktopMediaList::Worker::CreateSharedMemory( | 228 webrtc::SharedMemory* NativeDesktopMediaList::Worker::CreateSharedMemory( |
229 size_t size) { | 229 size_t size) { |
230 return NULL; | 230 return NULL; |
231 } | 231 } |
232 | 232 |
233 void NativeDesktopMediaList::Worker::OnCaptureCompleted( | 233 void NativeDesktopMediaList::Worker::OnCaptureCompleted( |
234 webrtc::DesktopFrame* frame) { | 234 webrtc::DesktopFrame* frame) { |
235 current_frame_.reset(frame); | 235 current_frame_.reset(frame); |
236 } | 236 } |
237 | 237 |
238 NativeDesktopMediaList::NativeDesktopMediaList( | 238 NativeDesktopMediaList::NativeDesktopMediaList( |
239 scoped_ptr<webrtc::ScreenCapturer> screen_capturer, | 239 scoped_ptr<webrtc::ScreenCapturer> screen_capturer, |
240 scoped_ptr<webrtc::WindowCapturer> window_capturer) | 240 scoped_ptr<webrtc::WindowCapturer> window_capturer) |
241 : screen_capturer_(screen_capturer.Pass()), | 241 : screen_capturer_(std::move(screen_capturer)), |
242 window_capturer_(window_capturer.Pass()), | 242 window_capturer_(std::move(window_capturer)), |
243 update_period_(base::TimeDelta::FromMilliseconds(kDefaultUpdatePeriod)), | 243 update_period_(base::TimeDelta::FromMilliseconds(kDefaultUpdatePeriod)), |
244 thumbnail_size_(100, 100), | 244 thumbnail_size_(100, 100), |
245 view_dialog_id_(content::DesktopMediaID::TYPE_NONE, -1), | 245 view_dialog_id_(content::DesktopMediaID::TYPE_NONE, -1), |
246 observer_(NULL), | 246 observer_(NULL), |
247 weak_factory_(this) { | 247 weak_factory_(this) { |
248 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); | 248 base::SequencedWorkerPool* worker_pool = BrowserThread::GetBlockingPool(); |
249 capture_task_runner_ = worker_pool->GetSequencedTaskRunner( | 249 capture_task_runner_ = worker_pool->GetSequencedTaskRunner( |
250 worker_pool->GetSequenceToken()); | 250 worker_pool->GetSequenceToken()); |
251 } | 251 } |
252 | 252 |
(...skipping 16 matching lines...) Expand all Loading... |
269 view_dialog_id_ = dialog_id; | 269 view_dialog_id_ = dialog_id; |
270 } | 270 } |
271 | 271 |
272 void NativeDesktopMediaList::StartUpdating(DesktopMediaListObserver* observer) { | 272 void NativeDesktopMediaList::StartUpdating(DesktopMediaListObserver* observer) { |
273 DCHECK(!observer_); | 273 DCHECK(!observer_); |
274 DCHECK(screen_capturer_ || window_capturer_); | 274 DCHECK(screen_capturer_ || window_capturer_); |
275 | 275 |
276 observer_ = observer; | 276 observer_ = observer; |
277 | 277 |
278 worker_.reset(new Worker(weak_factory_.GetWeakPtr(), | 278 worker_.reset(new Worker(weak_factory_.GetWeakPtr(), |
279 screen_capturer_.Pass(), window_capturer_.Pass())); | 279 std::move(screen_capturer_), |
| 280 std::move(window_capturer_))); |
280 Refresh(); | 281 Refresh(); |
281 } | 282 } |
282 | 283 |
283 int NativeDesktopMediaList::GetSourceCount() const { | 284 int NativeDesktopMediaList::GetSourceCount() const { |
284 return sources_.size(); | 285 return sources_.size(); |
285 } | 286 } |
286 | 287 |
287 const DesktopMediaList::Source& NativeDesktopMediaList::GetSource( | 288 const DesktopMediaList::Source& NativeDesktopMediaList::GetSource( |
288 int index) const { | 289 int index) const { |
289 return sources_[index]; | 290 return sources_[index]; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 observer_->OnSourceThumbnailChanged(index); | 366 observer_->OnSourceThumbnailChanged(index); |
366 } | 367 } |
367 | 368 |
368 void NativeDesktopMediaList::OnRefreshFinished() { | 369 void NativeDesktopMediaList::OnRefreshFinished() { |
369 BrowserThread::PostDelayedTask( | 370 BrowserThread::PostDelayedTask( |
370 BrowserThread::UI, FROM_HERE, | 371 BrowserThread::UI, FROM_HERE, |
371 base::Bind(&NativeDesktopMediaList::Refresh, | 372 base::Bind(&NativeDesktopMediaList::Refresh, |
372 weak_factory_.GetWeakPtr()), | 373 weak_factory_.GetWeakPtr()), |
373 update_period_); | 374 update_period_); |
374 } | 375 } |
OLD | NEW |