Commit 0a9d452d authored by dcheng@chromium.org's avatar dcheng@chromium.org

Remove custom Task implementation from RenderWidgetHelper::UpdateMsgProxy.

BUG=none
TEST=none


Review URL: http://codereview.chromium.org/8872038

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113930 0039d316-1c4b-4281-b951-d872f2087c98
parent 8f7825b6
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "content/browser/renderer_host/render_widget_helper.h" #include "content/browser/renderer_host/render_widget_helper.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/eintr_wrapper.h" #include "base/eintr_wrapper.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_process_host_impl.h"
...@@ -15,37 +16,46 @@ ...@@ -15,37 +16,46 @@
using content::BrowserThread; using content::BrowserThread;
// A Task used with InvokeLater that we hold a pointer to in pending_paints_. // A helper used with DidReceiveUpdateMsg that we hold a pointer to in
// Instances are deleted by MessageLoop after it calls their Run method. // pending_paints_.
class RenderWidgetHelper::UpdateMsgProxy : public Task { class RenderWidgetHelper::UpdateMsgProxy {
public: public:
UpdateMsgProxy(RenderWidgetHelper* h, const IPC::Message& m) UpdateMsgProxy(RenderWidgetHelper* h, const IPC::Message& m);
: helper(h), ~UpdateMsgProxy();
message(m), void Run();
cancelled(false) { void Cancel() { cancelled_ = true; }
}
~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);
}
virtual void Run() { const IPC::Message& message() const { return message_; }
if (!cancelled) {
helper->OnDispatchUpdateMsg(this);
helper = NULL;
}
}
scoped_refptr<RenderWidgetHelper> helper; private:
IPC::Message message; scoped_refptr<RenderWidgetHelper> helper_;
bool cancelled; // If true, then the message will not be dispatched. IPC::Message message_;
bool cancelled_; // If true, then the message will not be dispatched.
DISALLOW_COPY_AND_ASSIGN(UpdateMsgProxy); DISALLOW_COPY_AND_ASSIGN(UpdateMsgProxy);
}; };
RenderWidgetHelper::UpdateMsgProxy::UpdateMsgProxy(
RenderWidgetHelper* h, const IPC::Message& m)
: helper_(h),
message_(m),
cancelled_(false) {
}
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() RenderWidgetHelper::RenderWidgetHelper()
: render_process_id_(-1), : render_process_id_(-1),
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -115,7 +125,7 @@ bool RenderWidgetHelper::WaitForUpdateMsg(int render_widget_id, ...@@ -115,7 +125,7 @@ bool RenderWidgetHelper::WaitForUpdateMsg(int render_widget_id,
// Flag the proxy as cancelled so that when it is run as a task it will // Flag the proxy as cancelled so that when it is run as a task it will
// do nothing. // do nothing.
proxy->cancelled = true; proxy->Cancel();
queue.pop_front(); queue.pop_front();
if (queue.empty()) if (queue.empty())
...@@ -124,7 +134,7 @@ bool RenderWidgetHelper::WaitForUpdateMsg(int render_widget_id, ...@@ -124,7 +134,7 @@ bool RenderWidgetHelper::WaitForUpdateMsg(int render_widget_id,
} }
if (proxy) { if (proxy) {
*msg = proxy->message; *msg = proxy->message();
DCHECK(msg->routing_id() == render_widget_id); DCHECK(msg->routing_id() == render_widget_id);
return true; return true;
} }
...@@ -156,12 +166,12 @@ void RenderWidgetHelper::DidReceiveUpdateMsg(const IPC::Message& msg) { ...@@ -156,12 +166,12 @@ void RenderWidgetHelper::DidReceiveUpdateMsg(const IPC::Message& msg) {
// will just continue waiting. // will just continue waiting.
event_.Signal(); event_.Signal();
// The proxy will be deleted when it is run as a task. BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, proxy); base::Bind(&UpdateMsgProxy::Run, base::Owned(proxy)));
} }
void RenderWidgetHelper::OnDiscardUpdateMsg(UpdateMsgProxy* 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. // Remove the proxy from the map now that we are going to handle it normally.
{ {
...@@ -185,7 +195,7 @@ void RenderWidgetHelper::OnDispatchUpdateMsg(UpdateMsgProxy* proxy) { ...@@ -185,7 +195,7 @@ void RenderWidgetHelper::OnDispatchUpdateMsg(UpdateMsgProxy* proxy) {
content::RenderProcessHost* host = content::RenderProcessHost* host =
content::RenderProcessHost::FromID(render_process_id_); content::RenderProcessHost::FromID(render_process_id_);
if (host) if (host)
host->OnMessageReceived(proxy->message); host->OnMessageReceived(proxy->message());
} }
void RenderWidgetHelper::OnCancelResourceRequests( void RenderWidgetHelper::OnCancelResourceRequests(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment