Chromium Code Reviews| Index: chrome/browser/instant/instant_loader.cc |
| diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc |
| index b6b47a6d1595336eafe5b37c53f5b288353a760e..fdcfe399e365ccd1dcd120318f4106d82eb2c41c 100644 |
| --- a/chrome/browser/instant/instant_loader.cc |
| +++ b/chrome/browser/instant/instant_loader.cc |
| @@ -33,6 +33,7 @@ |
| #include "chrome/common/notification_details.h" |
| #include "chrome/common/notification_observer.h" |
| #include "chrome/common/notification_registrar.h" |
| +#include "chrome/common/notification_service.h" |
| #include "chrome/common/notification_source.h" |
| #include "chrome/common/notification_type.h" |
| #include "chrome/common/page_transition_types.h" |
| @@ -133,30 +134,26 @@ class InstantLoader::FrameLoadObserver : public NotificationObserver { |
| // tracked by TabContentsDelegateImpl, but owned by RenderWidgetHost. When |
| // deleted this notifies the TabContentsDelegateImpl so that it can clean |
| // up appropriately. |
| -class InstantLoader::PaintObserverImpl |
| - : public RenderWidgetHost::PaintObserver { |
| +class InstantLoader::PaintObserverImpl : public NotificationObserver { |
| public: |
| PaintObserverImpl(TabContentsDelegateImpl* delegate, |
| - RenderWidgetHost* rwh) |
| - : delegate_(delegate), |
| - rwh_(rwh) { |
| - rwh_->set_paint_observer(this); |
| + RenderWidgetHost* render_widget_host) |
| + : delegate_(delegate) { |
| + registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT, |
| + Source<RenderWidgetHost>(render_widget_host)); |
| + registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, |
| + Source<RenderWidgetHost>(render_widget_host)); |
| } |
| ~PaintObserverImpl(); |
| - // Deletes this object by resetting the PaintObserver on the RenderWidgetHost. |
| - void Destroy() { |
| - rwh_->set_paint_observer(NULL); |
| - } |
| - |
| - virtual void RenderWidgetHostWillPaint(RenderWidgetHost* rwh) {} |
| - |
| - virtual void RenderWidgetHostDidPaint(RenderWidgetHost* rwh); |
| + void Observe(NotificationType type, |
| + const NotificationSource& source, |
|
brettw
2011/01/03 19:48:30
Indent these two args to the first one.
DaveMoore
2011/01/07 19:04:05
N/A
On 2011/01/03 19:48:30, brettw wrote:
|
| + const NotificationDetails& details); |
| private: |
| TabContentsDelegateImpl* delegate_; |
| - RenderWidgetHost* rwh_; |
| + NotificationRegistrar registrar_; |
| DISALLOW_COPY_AND_ASSIGN(PaintObserverImpl); |
| }; |
| @@ -415,8 +412,8 @@ class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate { |
| // If the PaintObserver is non-null Destroy is invoked on it. |
| void DestroyPaintObserver() { |
| if (paint_observer_) { |
| - paint_observer_->Destroy(); |
| - // Destroy should result in invoking PaintObserverDestroyed and NULLing |
| + delete paint_observer_; |
| + // delete should result in invoking PaintObserverDestroyed and NULLing |
| // out paint_observer_. |
| DCHECK(!paint_observer_); |
| } |
| @@ -452,16 +449,20 @@ InstantLoader::PaintObserverImpl::~PaintObserverImpl() { |
| delegate_->PaintObserverDestroyed(this); |
| } |
| -void InstantLoader::PaintObserverImpl::RenderWidgetHostDidPaint( |
| - RenderWidgetHost* rwh) { |
| - TabContentsDelegateImpl* delegate = delegate_; |
| - // Set the paint observer to NULL, which deletes us. Showing the preview may |
| - // reset the paint observer, and delete us. By resetting the delegate first we |
| - // know we've been deleted and can deal correctly. |
| - rwh->set_paint_observer(NULL); |
| - // WARNING: we've been deleted. |
| - if (delegate) |
| - delegate->PreviewPainted(); |
| +void InstantLoader::PaintObserverImpl::Observe(NotificationType type, |
|
brettw
2011/01/03 19:48:30
Move this arg to the next line, indented 4 spaces.
DaveMoore
2011/01/07 19:04:05
N/A
On 2011/01/03 19:48:30, brettw wrote:
|
| + const NotificationSource& source, |
| + const NotificationDetails& details) { |
| + if (type == NotificationType::RENDER_WIDGET_HOST_DID_PAINT) { |
| + TabContentsDelegateImpl* delegate = delegate_; |
| + // Delete outselves. Showing the preview may reload content. By resetting |
| + // the observer first we know we've been deleted and can deal correctly. |
| + delete this; |
| + // WARNING: we've been deleted. |
| + if (delegate) |
| + delegate->PreviewPainted(); |
| + } else if (type == NotificationType::RENDER_WIDGET_HOST_DESTROYED) { |
| + delete this; |
| + } |
| } |
| InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id) |
| @@ -628,11 +629,7 @@ TabContentsWrapper* InstantLoader::ReleasePreviewContents( |
| if (preview_contents_.get()) { |
| if (type != INSTANT_COMMIT_DESTROY) |
| preview_tab_contents_delegate_->CommitHistory(); |
| - // Destroy the paint observer. |
| - // RenderWidgetHostView may be null during shutdown. |
| if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { |
| - preview_contents_->tab_contents()->GetRenderWidgetHostView()-> |
| - GetRenderWidgetHost()->set_paint_observer(NULL); |
| #if defined(OS_MACOSX) |
| preview_contents_->tab_contents()->GetRenderWidgetHostView()-> |
| SetTakesFocusOnlyOnMouseDown(false); |