Chromium Code Reviews| Index: content/browser/renderer_host/render_widget_helper.cc |
| diff --git a/content/browser/renderer_host/render_widget_helper.cc b/content/browser/renderer_host/render_widget_helper.cc |
| index 9228e0ffdd19892ee55e5dc3b668e9e2b78992a8..f1d39541d8e423b555f94777fa7f5dc5f076777b 100644 |
| --- a/content/browser/renderer_host/render_widget_helper.cc |
| +++ b/content/browser/renderer_host/render_widget_helper.cc |
| @@ -5,6 +5,7 @@ |
| #include "content/browser/renderer_host/render_widget_helper.h" |
| #include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| #include "base/eintr_wrapper.h" |
| #include "base/threading/thread.h" |
| #include "content/browser/renderer_host/render_process_host_impl.h" |
| @@ -15,37 +16,44 @@ |
| using content::BrowserThread; |
| -// A Task used with InvokeLater that we hold a pointer to in pending_paints_. |
| -// Instances are deleted by MessageLoop after it calls their Run method. |
| -class RenderWidgetHelper::UpdateMsgProxy : public Task { |
| +// A helper used with DidReceiveUpdateMsg that we hold a pointer to in |
| +// pending_paints_. |
| +class RenderWidgetHelper::UpdateMsgProxy { |
| public: |
| - UpdateMsgProxy(RenderWidgetHelper* h, const IPC::Message& m) |
| - : helper(h), |
| - message(m), |
| - cancelled(false) { |
| - } |
| - |
| - ~UpdateMsgProxy() { |
| - // If the paint message was never dispatched, then we need to let the |
| - // helper know that we are going away. |
| - if (!cancelled && helper) |
| - helper->OnDiscardUpdateMsg(this); |
| - } |
| + UpdateMsgProxy(RenderWidgetHelper* h, const IPC::Message& m); |
| + ~UpdateMsgProxy(); |
| + void Run(); |
| + void Cancel() { cancelled_ = true; } |
| - virtual void Run() { |
| - if (!cancelled) { |
| - helper->OnDispatchUpdateMsg(this); |
| - helper = NULL; |
| - } |
| - } |
| + const IPC::Message& message() const { return message_; } |
| - scoped_refptr<RenderWidgetHelper> helper; |
| - IPC::Message message; |
| - bool cancelled; // If true, then the message will not be dispatched. |
| + private: |
| + scoped_refptr<RenderWidgetHelper> helper_; |
| + IPC::Message message_; |
| + bool cancelled_; // If true, then the message will not be dispatched. |
| DISALLOW_COPY_AND_ASSIGN(UpdateMsgProxy); |
| }; |
| +RenderWidgetHelper::UpdateMsgProxy::UpdateMsgProxy( |
| + RenderWidgetHelper* h, const IPC::Message& m) |
| + : helper_(h), message_(m), cancelled_(false) { |
|
brettw
2011/12/10 00:01:55
Initializers should go on separate lines
|
| +} |
| + |
| +RenderWidgetHelper::UpdateMsgProxy::~UpdateMsgProxy() { |
| + // If the paint message was never dispatched, then we need to let the |
| + // helper know that we are going away. |
| + if (!cancelled_ && helper_) |
| + helper_->OnDiscardUpdateMsg(this); |
| +} |
| + |
| +void RenderWidgetHelper::UpdateMsgProxy::Run() { |
| + if (!cancelled_) { |
| + helper_->OnDispatchUpdateMsg(this); |
| + helper_ = NULL; |
| + } |
| +} |
| + |
| RenderWidgetHelper::RenderWidgetHelper() |
| : render_process_id_(-1), |
| #if defined(OS_WIN) |
| @@ -113,14 +121,14 @@ bool RenderWidgetHelper::WaitForUpdateMsg(int render_widget_id, |
| // Flag the proxy as cancelled so that when it is run as a task it will |
| // do nothing. |
| - proxy->cancelled = true; |
| + proxy->Cancel(); |
| pending_paints_.erase(it); |
| } |
| } |
| if (proxy) { |
| - *msg = proxy->message; |
| + *msg = proxy->message(); |
| DCHECK(msg->routing_id() == render_widget_id); |
| return true; |
| } |
| @@ -171,12 +179,12 @@ void RenderWidgetHelper::DidReceiveUpdateMsg(const IPC::Message& msg) { |
| // will just continue waiting. |
| event_.Signal(); |
| - // The proxy will be deleted when it is run as a task. |
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, proxy); |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&UpdateMsgProxy::Run, base::Owned(proxy))); |
| } |
| void RenderWidgetHelper::OnDiscardUpdateMsg(UpdateMsgProxy* proxy) { |
| - const IPC::Message& msg = proxy->message; |
| + const IPC::Message& msg = proxy->message(); |
| // Remove the proxy from the map now that we are going to handle it normally. |
| { |
| @@ -197,7 +205,7 @@ void RenderWidgetHelper::OnDispatchUpdateMsg(UpdateMsgProxy* proxy) { |
| content::RenderProcessHost* host = |
| content::RenderProcessHost::FromID(render_process_id_); |
| if (host) |
| - host->OnMessageReceived(proxy->message); |
| + host->OnMessageReceived(proxy->message()); |
| } |
| void RenderWidgetHelper::OnCancelResourceRequests( |