Chromium Code Reviews| Index: content/browser/media/capture/web_contents_tracker.cc |
| diff --git a/content/browser/media/capture/web_contents_tracker.cc b/content/browser/media/capture/web_contents_tracker.cc |
| index a9e161f1ce3fcf2ce299734fb103d805ea574eb5..c529b2233256eb92d56ee952c4852256bd16d7f0 100644 |
| --- a/content/browser/media/capture/web_contents_tracker.cc |
| +++ b/content/browser/media/capture/web_contents_tracker.cc |
| @@ -44,6 +44,7 @@ void WebContentsTracker::Stop() { |
| DCHECK(task_runner_->BelongsToCurrentThread()); |
| callback_.Reset(); |
| + resize_callback_.Reset(); |
| if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| WebContentsObserver::Observe(NULL); |
| @@ -78,6 +79,12 @@ RenderWidgetHost* WebContentsTracker::GetTargetRenderWidgetHost() const { |
| return rwh; |
| } |
| +void WebContentsTracker::SetResizeChangeCallback( |
| + const ChangeCallback& callback) { |
| + DCHECK(!task_runner_.get() || task_runner_->BelongsToCurrentThread()); |
| + resize_callback_ = callback; |
| +} |
| + |
| void WebContentsTracker::OnPossibleTargetChange(bool force_callback_run) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| @@ -102,6 +109,15 @@ void WebContentsTracker::MaybeDoCallback(RenderWidgetHost* rwh) { |
| if (!callback_.is_null()) |
| callback_.Run(rwh); |
| + if (rwh) |
| + MaybeDoResizeCallback(rwh); |
| +} |
| + |
| +void WebContentsTracker::MaybeDoResizeCallback(RenderWidgetHost* rwh) { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + |
| + if (!resize_callback_.is_null()) |
| + resize_callback_.Run(rwh); |
| } |
| void WebContentsTracker::StartObservingWebContents(int render_process_id, |
| @@ -128,6 +144,23 @@ void WebContentsTracker::RenderFrameHostChanged(RenderFrameHost* old_host, |
| OnPossibleTargetChange(false); |
| } |
| +void WebContentsTracker::MainFrameWasResized(bool width_changed) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + RenderWidgetHost* const rwh = GetTargetRenderWidgetHost(); |
| + if (!rwh) |
| + return; |
| + |
| + if (task_runner_->BelongsToCurrentThread()) { |
|
Wez
2015/05/13 19:05:09
So the task runner is sometimes UI thread and some
miu
2015/05/14 01:21:33
tl;dr: This is the pattern decided upon, based on
Wez
2015/05/14 01:44:55
Understood. The BelongsToCurrentThread() test and
Wez
2015/05/14 01:44:55
Also, is there any way that MainFrameWasResized()
miu
2015/05/14 21:12:26
This seems like a matter of preference. I like th
miu
2015/05/14 21:12:26
No. It is set exactly once, when Start() is calle
Wez
2015/05/15 00:55:42
I prefer early-exit because you could in principle
miu
2015/05/15 21:14:00
Done. Feels like we're bike shedding here. ;-)
|
| + MaybeDoResizeCallback(rwh); |
| + } else { |
| + task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&WebContentsTracker::MaybeDoResizeCallback, this, rwh)); |
|
Wez
2015/05/14 01:44:55
What guarantees that the |rwh| will remain valid b
miu
2015/05/14 21:12:26
Excellent point. I looked again at the other code
Wez
2015/05/15 00:55:42
Given the usage by the two consumers, could we ins
miu
2015/05/15 21:14:00
Done, but I got rid of the pointer altogether. I
Wez
2015/05/15 23:31:31
Nice!
|
| + } |
| + |
| +} |
| + |
| void WebContentsTracker::WebContentsDestroyed() { |
| Observe(NULL); |
| OnPossibleTargetChange(false); |