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 "content/browser/media/capture/aura_window_capture_machine.h" | 5 #include "content/browser/media/capture/aura_window_capture_machine.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "cc/output/copy_output_request.h" | 10 #include "cc/output/copy_output_request.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 110 |
111 } // namespace | 111 } // namespace |
112 | 112 |
113 AuraWindowCaptureMachine::AuraWindowCaptureMachine() | 113 AuraWindowCaptureMachine::AuraWindowCaptureMachine() |
114 : desktop_window_(NULL), | 114 : desktop_window_(NULL), |
115 timer_(true, true), | 115 timer_(true, true), |
116 screen_capture_(false) {} | 116 screen_capture_(false) {} |
117 | 117 |
118 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} | 118 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} |
119 | 119 |
120 bool AuraWindowCaptureMachine::Start( | 120 void AuraWindowCaptureMachine::Start( |
121 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | |
122 const media::VideoCaptureParams& params, | |
123 const base::Callback<void(bool)> callback) { | |
124 // Starts the capture machine asynchronously. | |
125 BrowserThread::PostTaskAndReplyWithResult( | |
126 BrowserThread::UI, | |
127 FROM_HERE, | |
128 base::Bind(&AuraWindowCaptureMachine::InternalStart, | |
129 base::Unretained(this), | |
130 oracle_proxy, | |
131 params), | |
132 callback); | |
133 } | |
134 | |
135 bool AuraWindowCaptureMachine::InternalStart( | |
121 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 136 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
122 const media::VideoCaptureParams& params) { | 137 const media::VideoCaptureParams& params) { |
123 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 138 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
124 | |
125 // The window might be destroyed between SetWindow() and Start(). | 139 // The window might be destroyed between SetWindow() and Start(). |
126 if (!desktop_window_) | 140 if (!desktop_window_) |
127 return false; | 141 return false; |
128 | 142 |
129 // If the associated layer is already destroyed then return failure. | 143 // If the associated layer is already destroyed then return failure. |
130 ui::Layer* layer = desktop_window_->layer(); | 144 ui::Layer* layer = desktop_window_->layer(); |
131 if (!layer) | 145 if (!layer) |
132 return false; | 146 return false; |
133 | 147 |
134 DCHECK(oracle_proxy.get()); | 148 DCHECK(oracle_proxy.get()); |
(...skipping 15 matching lines...) Expand all Loading... | |
150 | 164 |
151 // Starts timer. | 165 // Starts timer. |
152 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), | 166 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), |
153 base::Bind(&AuraWindowCaptureMachine::Capture, AsWeakPtr(), | 167 base::Bind(&AuraWindowCaptureMachine::Capture, AsWeakPtr(), |
154 false)); | 168 false)); |
155 | 169 |
156 return true; | 170 return true; |
157 } | 171 } |
158 | 172 |
159 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { | 173 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { |
174 // Stops the capture machine asynchronously. | |
175 BrowserThread::PostTask( | |
whywhat
2015/08/17 13:58:46
This refactoring (changing a sync method to async)
| |
176 BrowserThread::UI, FROM_HERE, base::Bind( | |
177 &AuraWindowCaptureMachine::InternalStop, | |
178 base::Unretained(this), | |
179 callback)); | |
180 } | |
181 | |
182 void AuraWindowCaptureMachine::InternalStop(const base::Closure& callback) { | |
160 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 183 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
161 power_save_blocker_.reset(); | 184 power_save_blocker_.reset(); |
162 | 185 |
163 // Stop observing compositor and window events. | 186 // Stop observing compositor and window events. |
164 if (desktop_window_) { | 187 if (desktop_window_) { |
165 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); | 188 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); |
166 // In the host destructor the compositor is destroyed before the window. | 189 // In the host destructor the compositor is destroyed before the window. |
167 if (window_host && window_host->compositor()) | 190 if (window_host && window_host->compositor()) |
168 window_host->compositor()->RemoveObserver(this); | 191 window_host->compositor()->RemoveObserver(this); |
169 desktop_window_->RemoveObserver(this); | 192 desktop_window_->RemoveObserver(this); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 window->GetHost()->compositor()->RemoveObserver(this); | 463 window->GetHost()->compositor()->RemoveObserver(this); |
441 } | 464 } |
442 | 465 |
443 void AuraWindowCaptureMachine::OnCompositingEnded( | 466 void AuraWindowCaptureMachine::OnCompositingEnded( |
444 ui::Compositor* compositor) { | 467 ui::Compositor* compositor) { |
445 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 468 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
446 &AuraWindowCaptureMachine::Capture, AsWeakPtr(), true)); | 469 &AuraWindowCaptureMachine::Capture, AsWeakPtr(), true)); |
447 } | 470 } |
448 | 471 |
449 } // namespace content | 472 } // namespace content |
OLD | NEW |