OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer_host/render_widget_helper.h" | 5 #include "content/browser/renderer_host/render_widget_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | |
8 #include "base/eintr_wrapper.h" | 9 #include "base/eintr_wrapper.h" |
9 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
10 #include "content/browser/renderer_host/render_process_host_impl.h" | 11 #include "content/browser/renderer_host/render_process_host_impl.h" |
11 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
12 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 13 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
13 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 | 16 |
16 using content::BrowserThread; | 17 using content::BrowserThread; |
17 | 18 |
18 // A Task used with InvokeLater that we hold a pointer to in pending_paints_. | 19 // A helper used with DidReceiveUpdateMsg that we hold a pointer to in |
19 // Instances are deleted by MessageLoop after it calls their Run method. | 20 // pending_paints_. |
20 class RenderWidgetHelper::UpdateMsgProxy : public Task { | 21 class RenderWidgetHelper::UpdateMsgProxy { |
21 public: | 22 public: |
22 UpdateMsgProxy(RenderWidgetHelper* h, const IPC::Message& m) | 23 UpdateMsgProxy(RenderWidgetHelper* h, const IPC::Message& m); |
23 : helper(h), | 24 ~UpdateMsgProxy(); |
24 message(m), | 25 void Run(); |
25 cancelled(false) { | 26 void Cancel() { cancelled_ = true; } |
26 } | |
27 | 27 |
28 ~UpdateMsgProxy() { | 28 const IPC::Message& message() const { return message_; } |
29 // If the paint message was never dispatched, then we need to let the | |
30 // helper know that we are going away. | |
31 if (!cancelled && helper) | |
32 helper->OnDiscardUpdateMsg(this); | |
33 } | |
34 | 29 |
35 virtual void Run() { | 30 private: |
36 if (!cancelled) { | 31 scoped_refptr<RenderWidgetHelper> helper_; |
37 helper->OnDispatchUpdateMsg(this); | 32 IPC::Message message_; |
38 helper = NULL; | 33 bool cancelled_; // If true, then the message will not be dispatched. |
39 } | |
40 } | |
41 | |
42 scoped_refptr<RenderWidgetHelper> helper; | |
43 IPC::Message message; | |
44 bool cancelled; // If true, then the message will not be dispatched. | |
45 | 34 |
46 DISALLOW_COPY_AND_ASSIGN(UpdateMsgProxy); | 35 DISALLOW_COPY_AND_ASSIGN(UpdateMsgProxy); |
47 }; | 36 }; |
48 | 37 |
38 RenderWidgetHelper::UpdateMsgProxy::UpdateMsgProxy( | |
39 RenderWidgetHelper* h, const IPC::Message& m) | |
40 : helper_(h), message_(m), cancelled_(false) { | |
brettw
2011/12/10 00:01:55
Initializers should go on separate lines
| |
41 } | |
42 | |
43 RenderWidgetHelper::UpdateMsgProxy::~UpdateMsgProxy() { | |
44 // If the paint message was never dispatched, then we need to let the | |
45 // helper know that we are going away. | |
46 if (!cancelled_ && helper_) | |
47 helper_->OnDiscardUpdateMsg(this); | |
48 } | |
49 | |
50 void RenderWidgetHelper::UpdateMsgProxy::Run() { | |
51 if (!cancelled_) { | |
52 helper_->OnDispatchUpdateMsg(this); | |
53 helper_ = NULL; | |
54 } | |
55 } | |
56 | |
49 RenderWidgetHelper::RenderWidgetHelper() | 57 RenderWidgetHelper::RenderWidgetHelper() |
50 : render_process_id_(-1), | 58 : render_process_id_(-1), |
51 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
52 event_(CreateEvent(NULL, FALSE /* auto-reset */, FALSE, NULL)), | 60 event_(CreateEvent(NULL, FALSE /* auto-reset */, FALSE, NULL)), |
53 #elif defined(OS_POSIX) | 61 #elif defined(OS_POSIX) |
54 event_(false /* auto-reset */, false), | 62 event_(false /* auto-reset */, false), |
55 #endif | 63 #endif |
56 resource_dispatcher_host_(NULL) { | 64 resource_dispatcher_host_(NULL) { |
57 } | 65 } |
58 | 66 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 UpdateMsgProxy* proxy = NULL; | 114 UpdateMsgProxy* proxy = NULL; |
107 { | 115 { |
108 base::AutoLock lock(pending_paints_lock_); | 116 base::AutoLock lock(pending_paints_lock_); |
109 | 117 |
110 UpdateMsgProxyMap::iterator it = pending_paints_.find(render_widget_id); | 118 UpdateMsgProxyMap::iterator it = pending_paints_.find(render_widget_id); |
111 if (it != pending_paints_.end()) { | 119 if (it != pending_paints_.end()) { |
112 proxy = it->second; | 120 proxy = it->second; |
113 | 121 |
114 // Flag the proxy as cancelled so that when it is run as a task it will | 122 // Flag the proxy as cancelled so that when it is run as a task it will |
115 // do nothing. | 123 // do nothing. |
116 proxy->cancelled = true; | 124 proxy->Cancel(); |
117 | 125 |
118 pending_paints_.erase(it); | 126 pending_paints_.erase(it); |
119 } | 127 } |
120 } | 128 } |
121 | 129 |
122 if (proxy) { | 130 if (proxy) { |
123 *msg = proxy->message; | 131 *msg = proxy->message(); |
124 DCHECK(msg->routing_id() == render_widget_id); | 132 DCHECK(msg->routing_id() == render_widget_id); |
125 return true; | 133 return true; |
126 } | 134 } |
127 | 135 |
128 // Calculate the maximum amount of time that we are willing to sleep. | 136 // Calculate the maximum amount of time that we are willing to sleep. |
129 base::TimeDelta max_sleep_time = | 137 base::TimeDelta max_sleep_time = |
130 max_delay - (base::TimeTicks::Now() - time_start); | 138 max_delay - (base::TimeTicks::Now() - time_start); |
131 if (max_sleep_time <= base::TimeDelta::FromMilliseconds(0)) | 139 if (max_sleep_time <= base::TimeDelta::FromMilliseconds(0)) |
132 break; | 140 break; |
133 | 141 |
(...skipping 30 matching lines...) Expand all Loading... | |
164 } | 172 } |
165 | 173 |
166 result.first->second = (proxy = new UpdateMsgProxy(this, msg)); | 174 result.first->second = (proxy = new UpdateMsgProxy(this, msg)); |
167 } | 175 } |
168 | 176 |
169 // Notify anyone waiting on the UI thread that there is a new entry in the | 177 // Notify anyone waiting on the UI thread that there is a new entry in the |
170 // proxy map. If they don't find the entry they are looking for, then they | 178 // proxy map. If they don't find the entry they are looking for, then they |
171 // will just continue waiting. | 179 // will just continue waiting. |
172 event_.Signal(); | 180 event_.Signal(); |
173 | 181 |
174 // The proxy will be deleted when it is run as a task. | 182 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
175 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, proxy); | 183 base::Bind(&UpdateMsgProxy::Run, base::Owned(proxy))); |
176 } | 184 } |
177 | 185 |
178 void RenderWidgetHelper::OnDiscardUpdateMsg(UpdateMsgProxy* proxy) { | 186 void RenderWidgetHelper::OnDiscardUpdateMsg(UpdateMsgProxy* proxy) { |
179 const IPC::Message& msg = proxy->message; | 187 const IPC::Message& msg = proxy->message(); |
180 | 188 |
181 // Remove the proxy from the map now that we are going to handle it normally. | 189 // Remove the proxy from the map now that we are going to handle it normally. |
182 { | 190 { |
183 base::AutoLock lock(pending_paints_lock_); | 191 base::AutoLock lock(pending_paints_lock_); |
184 | 192 |
185 UpdateMsgProxyMap::iterator it = pending_paints_.find(msg.routing_id()); | 193 UpdateMsgProxyMap::iterator it = pending_paints_.find(msg.routing_id()); |
186 DCHECK(it != pending_paints_.end()); | 194 DCHECK(it != pending_paints_.end()); |
187 DCHECK(it->second == proxy); | 195 DCHECK(it->second == proxy); |
188 | 196 |
189 pending_paints_.erase(it); | 197 pending_paints_.erase(it); |
190 } | 198 } |
191 } | 199 } |
192 | 200 |
193 void RenderWidgetHelper::OnDispatchUpdateMsg(UpdateMsgProxy* proxy) { | 201 void RenderWidgetHelper::OnDispatchUpdateMsg(UpdateMsgProxy* proxy) { |
194 OnDiscardUpdateMsg(proxy); | 202 OnDiscardUpdateMsg(proxy); |
195 | 203 |
196 // It is reasonable for the host to no longer exist. | 204 // It is reasonable for the host to no longer exist. |
197 content::RenderProcessHost* host = | 205 content::RenderProcessHost* host = |
198 content::RenderProcessHost::FromID(render_process_id_); | 206 content::RenderProcessHost::FromID(render_process_id_); |
199 if (host) | 207 if (host) |
200 host->OnMessageReceived(proxy->message); | 208 host->OnMessageReceived(proxy->message()); |
201 } | 209 } |
202 | 210 |
203 void RenderWidgetHelper::OnCancelResourceRequests( | 211 void RenderWidgetHelper::OnCancelResourceRequests( |
204 int render_widget_id) { | 212 int render_widget_id) { |
205 resource_dispatcher_host_->CancelRequestsForRoute( | 213 resource_dispatcher_host_->CancelRequestsForRoute( |
206 render_process_id_, render_widget_id); | 214 render_process_id_, render_widget_id); |
207 } | 215 } |
208 | 216 |
209 void RenderWidgetHelper::OnCrossSiteSwapOutACK( | 217 void RenderWidgetHelper::OnCrossSiteSwapOutACK( |
210 const ViewMsg_SwapOut_Params& params) { | 218 const ViewMsg_SwapOut_Params& params) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 gfx::PluginWindowHandle RenderWidgetHelper::LookupCompositingSurface( | 358 gfx::PluginWindowHandle RenderWidgetHelper::LookupCompositingSurface( |
351 int render_widget_id) { | 359 int render_widget_id) { |
352 base::AutoLock locked(view_compositing_surface_map_lock_); | 360 base::AutoLock locked(view_compositing_surface_map_lock_); |
353 ViewCompositingSurfaceMap::iterator it = | 361 ViewCompositingSurfaceMap::iterator it = |
354 view_compositing_surface_map_.find(render_widget_id); | 362 view_compositing_surface_map_.find(render_widget_id); |
355 if (it == view_compositing_surface_map_.end()) | 363 if (it == view_compositing_surface_map_.end()) |
356 return gfx::kNullPluginWindow; | 364 return gfx::kNullPluginWindow; |
357 | 365 |
358 return it->second; | 366 return it->second; |
359 } | 367 } |
OLD | NEW |