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

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

Issue 1828303003: Modify unit tests for NativeDesktopMediaList to cover aura window capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/native_desktop_media_list.h" 5 #include "chrome/browser/media/native_desktop_media_list.h"
6 6
7 #include "base/hash.h" 7 #include "base/hash.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/threading/sequenced_worker_pool.h" 9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/browser/media/desktop_media_list_observer.h" 10 #include "chrome/browser/media/desktop_media_list_observer.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 std::move(screen_capturer), 242 std::move(screen_capturer),
243 std::move(window_capturer))); 243 std::move(window_capturer)));
244 } 244 }
245 245
246 NativeDesktopMediaList::~NativeDesktopMediaList() { 246 NativeDesktopMediaList::~NativeDesktopMediaList() {
247 capture_task_runner_->DeleteSoon(FROM_HERE, worker_.release()); 247 capture_task_runner_->DeleteSoon(FROM_HERE, worker_.release());
248 } 248 }
249 249
250 void NativeDesktopMediaList::Refresh() { 250 void NativeDesktopMediaList::Refresh() {
251 #if defined(USE_AURA) 251 #if defined(USE_AURA)
252 pending_aura_capture_requests_ = 0; 252 DCHECK_EQ(pending_aura_capture_requests_, 0);
253 DCHECK(!pending_native_thumbnail_capture_);
253 new_aura_thumbnail_hashes_.clear(); 254 new_aura_thumbnail_hashes_.clear();
254 pending_native_thumbnail_capture_ = true;
255 #endif 255 #endif
256 256
257 capture_task_runner_->PostTask( 257 capture_task_runner_->PostTask(
258 FROM_HERE, base::Bind(&Worker::Refresh, base::Unretained(worker_.get()), 258 FROM_HERE, base::Bind(&Worker::Refresh, base::Unretained(worker_.get()),
259 view_dialog_id_.id)); 259 view_dialog_id_.id));
260 } 260 }
261 261
262 void NativeDesktopMediaList::RefreshForAuraWindows( 262 void NativeDesktopMediaList::RefreshForAuraWindows(
263 std::vector<SourceDescription> sources) { 263 std::vector<SourceDescription> sources) {
264 #if defined(USE_AURA) 264 #if defined(USE_AURA)
265 // Associate aura id with native id.
265 for (auto& source : sources) { 266 for (auto& source : sources) {
267 if (source.id.type != DesktopMediaID::TYPE_WINDOW)
268 continue;
269
266 aura::Window* aura_window = NULL; 270 aura::Window* aura_window = NULL;
267 #if defined(OS_WIN) 271 #if defined(OS_WIN)
268 aura_window = views::DesktopWindowTreeHostWin::GetContentWindowForHWND( 272 aura_window = views::DesktopWindowTreeHostWin::GetContentWindowForHWND(
269 reinterpret_cast<HWND>(source.id.id)); 273 reinterpret_cast<HWND>(source.id.id));
270 #elif defined(USE_X11) && !defined(OS_CHROMEOS) 274 #elif defined(USE_X11) && !defined(OS_CHROMEOS)
271 aura_window = 275 aura_window =
272 views::DesktopWindowTreeHostX11::GetContentWindowForXID(source.id.id); 276 views::DesktopWindowTreeHostX11::GetContentWindowForXID(source.id.id);
273 #endif // defined(USE_X11) && !defined(OS_CHROMEOS) 277 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
274 // Associate aura id with native id.
275 if (aura_window) { 278 if (aura_window) {
276 DesktopMediaID aura_id = DesktopMediaID::RegisterAuraWindow( 279 DesktopMediaID aura_id = DesktopMediaID::RegisterAuraWindow(
277 DesktopMediaID::TYPE_WINDOW, aura_window); 280 DesktopMediaID::TYPE_WINDOW, aura_window);
278 source.id.aura_id = aura_id.aura_id; 281 source.id.aura_id = aura_id.aura_id;
279 } 282 }
280 } 283 }
281 #endif // defined(USE_AURA) 284 #endif // defined(USE_AURA)
282 285
283 UpdateSourcesList(sources); 286 UpdateSourcesList(sources);
284 287
288 // OnAuraThumbnailCaptured() and UpdateNativeThumbnailsFinished() are
289 // guaranteed to be excuted after RefreshForAuraWindows() and
290 // CaptureAuraWindowThumbnail() in the browser UI thread.
291 // Therefore pending_aura_capture_requests_ will be set the number of aura
292 // windows to be captured and pending_native_thumbnail_capture_ will be set
293 // true if native thumbnail capture is needed before OnAuraThumbnailCaptured()
294 // or UpdateNativeThumbnailsFinished() are called.
285 std::vector<DesktopMediaID> native_ids; 295 std::vector<DesktopMediaID> native_ids;
286 for (const auto& source : sources) { 296 for (const auto& source : sources) {
287 #if defined(USE_AURA) 297 #if defined(USE_AURA)
288 if (source.id.aura_id > DesktopMediaID::kNullId) { 298 if (source.id.aura_id > DesktopMediaID::kNullId) {
289 CaptureAuraWindowThumbnail(source.id); 299 CaptureAuraWindowThumbnail(source.id);
290 continue; 300 continue;
291 } 301 }
292 #endif // defined(USE_AURA) 302 #endif // defined(USE_AURA)
293 native_ids.push_back(source.id); 303 native_ids.push_back(source.id);
294 } 304 }
295 305
296 capture_task_runner_->PostTask( 306 if (native_ids.size() > 0) {
297 FROM_HERE, 307 #if defined(USE_AURA)
298 base::Bind(&Worker::RefreshThumbnails, base::Unretained(worker_.get()), 308 pending_native_thumbnail_capture_ = true;
299 native_ids, thumbnail_size_)); 309 #endif
310 capture_task_runner_->PostTask(
311 FROM_HERE,
312 base::Bind(&Worker::RefreshThumbnails, base::Unretained(worker_.get()),
313 native_ids, thumbnail_size_));
314 }
300 } 315 }
301 316
302 void NativeDesktopMediaList::UpdateNativeThumbnailsFinished() { 317 void NativeDesktopMediaList::UpdateNativeThumbnailsFinished() {
303 #if defined(USE_AURA) 318 #if defined(USE_AURA)
304 DCHECK(pending_native_thumbnail_capture_); 319 DCHECK(pending_native_thumbnail_capture_);
305 pending_native_thumbnail_capture_ = false; 320 pending_native_thumbnail_capture_ = false;
306 // Schedule next refresh if native thumbnail captures finished after aura 321 // Schedule next refresh if native thumbnail captures finished after aura
307 // thumbnail captures. 322 // thumbnail captures.
308 if (pending_aura_capture_requests_ == 0) 323 if (pending_aura_capture_requests_ == 0)
309 ScheduleNextRefresh(); 324 ScheduleNextRefresh();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 if (pending_aura_capture_requests_ == 0) { 363 if (pending_aura_capture_requests_ == 0) {
349 previous_aura_thumbnail_hashes_ = std::move(new_aura_thumbnail_hashes_); 364 previous_aura_thumbnail_hashes_ = std::move(new_aura_thumbnail_hashes_);
350 // Schedule next refresh if aura thumbnail captures finished after native 365 // Schedule next refresh if aura thumbnail captures finished after native
351 // thumbnail captures. 366 // thumbnail captures.
352 if (!pending_native_thumbnail_capture_) 367 if (!pending_native_thumbnail_capture_)
353 ScheduleNextRefresh(); 368 ScheduleNextRefresh();
354 } 369 }
355 } 370 }
356 371
357 #endif // defined(USE_AURA) 372 #endif // defined(USE_AURA)
OLDNEW
« no previous file with comments | « chrome/browser/media/native_desktop_media_list.h ('k') | chrome/browser/media/native_desktop_media_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698