OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/web_contents_tracker.h" | 5 #include "content/browser/media/capture/web_contents_tracker.h" |
6 | 6 |
7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/thread_task_runner_handle.h" |
8 #include "content/browser/frame_host/render_frame_host_impl.h" | 8 #include "content/browser/frame_host/render_frame_host_impl.h" |
9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/render_widget_host_view.h" | 12 #include "content/public/browser/render_widget_host_view.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 WebContentsTracker::WebContentsTracker(bool track_fullscreen_rwh) | 17 WebContentsTracker::WebContentsTracker(bool track_fullscreen_rwh) |
18 : track_fullscreen_rwh_(track_fullscreen_rwh), | 18 : track_fullscreen_rwh_(track_fullscreen_rwh), |
19 last_target_(NULL) {} | 19 last_target_(NULL) {} |
20 | 20 |
21 WebContentsTracker::~WebContentsTracker() { | 21 WebContentsTracker::~WebContentsTracker() { |
22 DCHECK(!web_contents()) << "BUG: Still observering!"; | 22 DCHECK(!web_contents()) << "BUG: Still observering!"; |
23 } | 23 } |
24 | 24 |
25 void WebContentsTracker::Start(int render_process_id, int main_render_frame_id, | 25 void WebContentsTracker::Start(int render_process_id, int main_render_frame_id, |
26 const ChangeCallback& callback) { | 26 const ChangeCallback& callback) { |
27 DCHECK(!message_loop_.get() || message_loop_->BelongsToCurrentThread()); | 27 DCHECK(!task_runner_.get() || task_runner_->BelongsToCurrentThread()); |
28 | 28 |
29 message_loop_ = base::MessageLoopProxy::current(); | 29 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
30 DCHECK(message_loop_.get()); | 30 DCHECK(task_runner_.get()); |
31 callback_ = callback; | 31 callback_ = callback; |
32 | 32 |
33 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 33 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
34 StartObservingWebContents(render_process_id, main_render_frame_id); | 34 StartObservingWebContents(render_process_id, main_render_frame_id); |
35 } else { | 35 } else { |
36 BrowserThread::PostTask( | 36 BrowserThread::PostTask( |
37 BrowserThread::UI, FROM_HERE, | 37 BrowserThread::UI, FROM_HERE, |
38 base::Bind(&WebContentsTracker::StartObservingWebContents, this, | 38 base::Bind(&WebContentsTracker::StartObservingWebContents, this, |
39 render_process_id, main_render_frame_id)); | 39 render_process_id, main_render_frame_id)); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 void WebContentsTracker::Stop() { | 43 void WebContentsTracker::Stop() { |
44 DCHECK(message_loop_->BelongsToCurrentThread()); | 44 DCHECK(task_runner_->BelongsToCurrentThread()); |
45 | 45 |
46 callback_.Reset(); | 46 callback_.Reset(); |
47 | 47 |
48 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 48 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
49 WebContentsObserver::Observe(NULL); | 49 WebContentsObserver::Observe(NULL); |
50 } else { | 50 } else { |
51 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
52 BrowserThread::UI, FROM_HERE, | 52 BrowserThread::UI, FROM_HERE, |
53 base::Bind(&WebContentsTracker::Observe, this, | 53 base::Bind(&WebContentsTracker::Observe, this, |
54 static_cast<WebContents*>(NULL))); | 54 static_cast<WebContents*>(NULL))); |
(...skipping 26 matching lines...) Expand all Loading... |
81 void WebContentsTracker::OnPossibleTargetChange(bool force_callback_run) { | 81 void WebContentsTracker::OnPossibleTargetChange(bool force_callback_run) { |
82 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 82 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
83 | 83 |
84 RenderWidgetHost* const rwh = GetTargetRenderWidgetHost(); | 84 RenderWidgetHost* const rwh = GetTargetRenderWidgetHost(); |
85 if (rwh == last_target_ && !force_callback_run) | 85 if (rwh == last_target_ && !force_callback_run) |
86 return; | 86 return; |
87 DVLOG(1) << "Will report target change from RenderWidgetHost@" << last_target_ | 87 DVLOG(1) << "Will report target change from RenderWidgetHost@" << last_target_ |
88 << " to RenderWidgetHost@" << rwh; | 88 << " to RenderWidgetHost@" << rwh; |
89 last_target_ = rwh; | 89 last_target_ = rwh; |
90 | 90 |
91 if (message_loop_->BelongsToCurrentThread()) { | 91 if (task_runner_->BelongsToCurrentThread()) { |
92 MaybeDoCallback(rwh); | 92 MaybeDoCallback(rwh); |
93 } else { | 93 } else { |
94 message_loop_->PostTask( | 94 task_runner_->PostTask( |
95 FROM_HERE, | 95 FROM_HERE, |
96 base::Bind(&WebContentsTracker::MaybeDoCallback, this, rwh)); | 96 base::Bind(&WebContentsTracker::MaybeDoCallback, this, rwh)); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 void WebContentsTracker::MaybeDoCallback(RenderWidgetHost* rwh) { | 100 void WebContentsTracker::MaybeDoCallback(RenderWidgetHost* rwh) { |
101 DCHECK(message_loop_->BelongsToCurrentThread()); | 101 DCHECK(task_runner_->BelongsToCurrentThread()); |
102 | 102 |
103 if (!callback_.is_null()) | 103 if (!callback_.is_null()) |
104 callback_.Run(rwh); | 104 callback_.Run(rwh); |
105 } | 105 } |
106 | 106 |
107 void WebContentsTracker::StartObservingWebContents(int render_process_id, | 107 void WebContentsTracker::StartObservingWebContents(int render_process_id, |
108 int main_render_frame_id) { | 108 int main_render_frame_id) { |
109 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 109 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
110 | 110 |
111 Observe(WebContents::FromRenderFrameHost(RenderFrameHost::FromID( | 111 Observe(WebContents::FromRenderFrameHost(RenderFrameHost::FromID( |
(...skipping 23 matching lines...) Expand all Loading... |
135 | 135 |
136 void WebContentsTracker::DidShowFullscreenWidget(int routing_id) { | 136 void WebContentsTracker::DidShowFullscreenWidget(int routing_id) { |
137 OnPossibleTargetChange(false); | 137 OnPossibleTargetChange(false); |
138 } | 138 } |
139 | 139 |
140 void WebContentsTracker::DidDestroyFullscreenWidget(int routing_id) { | 140 void WebContentsTracker::DidDestroyFullscreenWidget(int routing_id) { |
141 OnPossibleTargetChange(false); | 141 OnPossibleTargetChange(false); |
142 } | 142 } |
143 | 143 |
144 } // namespace content | 144 } // namespace content |
OLD | NEW |