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

Side by Side Diff: content/browser/media/capture/aura_window_capture_machine.cc

Issue 2881143003: Convert //content/browser/media to be clients of WakeLock mojo service. (Closed)
Patch Set: wake lock bindinterface should only be executed once. Created 3 years, 7 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 "content/browser/media/capture/aura_window_capture_machine.h" 5 #include "content/browser/media/capture/aura_window_capture_machine.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "cc/output/copy_output_request.h" 12 #include "cc/output/copy_output_request.h"
13 #include "cc/output/copy_output_result.h" 13 #include "cc/output/copy_output_result.h"
14 #include "components/display_compositor/gl_helper.h" 14 #include "components/display_compositor/gl_helper.h"
15 #include "content/browser/compositor/image_transport_factory.h" 15 #include "content/browser/compositor/image_transport_factory.h"
16 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" 16 #include "content/browser/media/capture/desktop_capture_device_uma_types.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "device/power_save_blocker/power_save_blocker.h" 18 #include "content/public/common/service_manager_connection.h"
19 #include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h"
19 #include "media/base/video_util.h" 20 #include "media/base/video_util.h"
20 #include "media/capture/content/thread_safe_capture_oracle.h" 21 #include "media/capture/content/thread_safe_capture_oracle.h"
21 #include "media/capture/content/video_capture_oracle.h" 22 #include "media/capture/content/video_capture_oracle.h"
22 #include "media/capture/video_capture_types.h" 23 #include "media/capture/video_capture_types.h"
24 #include "services/device/public/interfaces/constants.mojom.h"
25 #include "services/service_manager/public/cpp/connector.h"
23 #include "skia/ext/image_operations.h" 26 #include "skia/ext/image_operations.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 27 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "ui/aura/client/screen_position_client.h" 28 #include "ui/aura/client/screen_position_client.h"
26 #include "ui/aura/env.h" 29 #include "ui/aura/env.h"
27 #include "ui/aura/window.h" 30 #include "ui/aura/window.h"
28 #include "ui/aura/window_observer.h" 31 #include "ui/aura/window_observer.h"
29 #include "ui/aura/window_tree_host.h" 32 #include "ui/aura/window_tree_host.h"
30 #include "ui/base/cursor/cursors_aura.h" 33 #include "ui/base/cursor/cursors_aura.h"
31 #include "ui/compositor/compositor.h" 34 #include "ui/compositor/compositor.h"
32 #include "ui/compositor/dip_util.h" 35 #include "ui/compositor/dip_util.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Update capture size. 82 // Update capture size.
80 UpdateCaptureSize(); 83 UpdateCaptureSize();
81 84
82 // Start observing compositor updates. 85 // Start observing compositor updates.
83 aura::WindowTreeHost* const host = desktop_window_->GetHost(); 86 aura::WindowTreeHost* const host = desktop_window_->GetHost();
84 ui::Compositor* const compositor = host ? host->compositor() : nullptr; 87 ui::Compositor* const compositor = host ? host->compositor() : nullptr;
85 if (!compositor) 88 if (!compositor)
86 return false; 89 return false;
87 compositor->AddAnimationObserver(this); 90 compositor->AddAnimationObserver(this);
88 91
89 power_save_blocker_.reset(new device::PowerSaveBlocker( 92 if (!wake_lock_) {
Sergey Ulanov 2017/05/17 18:47:55 I don't think InternalStart() can be called more t
ke.he 2017/05/18 05:32:58 Done.
90 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, 93 device::mojom::WakeLockServiceRequest request =
91 device::PowerSaveBlocker::kReasonOther, "DesktopCaptureDevice is running", 94 mojo::MakeRequest(&wake_lock_);
92 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), 95 // In some testing contexts, the service manager connection isn't
93 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); 96 // initialized.
97 if (ServiceManagerConnection::GetForProcess()) {
98 service_manager::Connector* connector =
99 ServiceManagerConnection::GetForProcess()->GetConnector();
100 DCHECK(connector);
101 device::mojom::WakeLockProviderPtr wake_lock_provider;
102 connector->BindInterface(device::mojom::kServiceName,
103 mojo::MakeRequest(&wake_lock_provider));
104 wake_lock_provider->GetWakeLockWithoutContext(
105 device::mojom::WakeLockType::PreventDisplaySleep,
106 device::mojom::WakeLockReason::ReasonOther,
107 "Desktop capturer is running", std::move(request));
108 }
109 }
110 wake_lock_->RequestWakeLock();
94 111
95 return true; 112 return true;
96 } 113 }
97 114
98 void AuraWindowCaptureMachine::Suspend() { 115 void AuraWindowCaptureMachine::Suspend() {
99 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 116 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
100 base::Bind(&AuraWindowCaptureMachine::InternalSuspend, 117 base::Bind(&AuraWindowCaptureMachine::InternalSuspend,
101 base::Unretained(this))); 118 base::Unretained(this)));
102 } 119 }
103 120
(...skipping 26 matching lines...) Expand all
130 base::Unretained(this), 147 base::Unretained(this),
131 callback)); 148 callback));
132 } 149 }
133 150
134 void AuraWindowCaptureMachine::InternalStop(const base::Closure& callback) { 151 void AuraWindowCaptureMachine::InternalStop(const base::Closure& callback) {
135 DCHECK_CURRENTLY_ON(BrowserThread::UI); 152 DCHECK_CURRENTLY_ON(BrowserThread::UI);
136 153
137 // Cancel any and all outstanding callbacks owned by external modules. 154 // Cancel any and all outstanding callbacks owned by external modules.
138 weak_factory_.InvalidateWeakPtrs(); 155 weak_factory_.InvalidateWeakPtrs();
139 156
140 power_save_blocker_.reset(); 157 if (wake_lock_)
141 158 wake_lock_->CancelWakeLock();
142 // Stop observing compositor and window events. 159 // Stop observing compositor and window events.
143 if (desktop_window_) { 160 if (desktop_window_) {
144 if (aura::WindowTreeHost* host = desktop_window_->GetHost()) { 161 if (aura::WindowTreeHost* host = desktop_window_->GetHost()) {
145 if (ui::Compositor* compositor = host->compositor()) 162 if (ui::Compositor* compositor = host->compositor())
146 compositor->RemoveAnimationObserver(this); 163 compositor->RemoveAnimationObserver(this);
147 } 164 }
148 desktop_window_->RemoveObserver(this); 165 desktop_window_->RemoveObserver(this);
149 desktop_window_ = NULL; 166 desktop_window_ = NULL;
150 cursor_renderer_.reset(); 167 cursor_renderer_.reset();
151 } 168 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 Capture(timestamp); 457 Capture(timestamp);
441 } 458 }
442 459
443 void AuraWindowCaptureMachine::OnCompositingShuttingDown( 460 void AuraWindowCaptureMachine::OnCompositingShuttingDown(
444 ui::Compositor* compositor) { 461 ui::Compositor* compositor) {
445 DCHECK_CURRENTLY_ON(BrowserThread::UI); 462 DCHECK_CURRENTLY_ON(BrowserThread::UI);
446 compositor->RemoveAnimationObserver(this); 463 compositor->RemoveAnimationObserver(this);
447 } 464 }
448 465
449 } // namespace content 466 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698