summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-03 21:04:22 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-03 21:04:22 +0000
commit23bf9296250c98d5027d721fc0578d256b5f09ff (patch)
treef92fe7aea81d49149eba15d9329b7bb14f6995ae /content
parent4a66bd015629296373bfa5d10eb9d4f721d049c4 (diff)
downloadchromium_src-23bf9296250c98d5027d721fc0578d256b5f09ff.zip
chromium_src-23bf9296250c98d5027d721fc0578d256b5f09ff.tar.gz
chromium_src-23bf9296250c98d5027d721fc0578d256b5f09ff.tar.bz2
Get rid of TabContentsRegistrar and just let TabContentsObserver support dynamically changing the tab being observed.
Review URL: http://codereview.chromium.org/7058047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/tab_contents/tab_contents.h1
-rw-r--r--content/browser/tab_contents/tab_contents_observer.cc22
-rw-r--r--content/browser/tab_contents/tab_contents_observer.h13
-rw-r--r--content/browser/tab_contents/tab_contents_observer_registrar.cc37
-rw-r--r--content/browser/tab_contents/tab_contents_observer_registrar.h34
-rw-r--r--content/content_browser.gypi2
6 files changed, 18 insertions, 91 deletions
diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h
index 164195f..8272696 100644
--- a/content/browser/tab_contents/tab_contents.h
+++ b/content/browser/tab_contents/tab_contents.h
@@ -485,7 +485,6 @@ class TabContents : public PageNavigator,
protected:
friend class TabContentsObserver;
- friend class TabContentsObserverRegistrar;
// Add and remove observers for page navigation notifications. Adding or
// removing multiple times has no effect. The order in which notifications
diff --git a/content/browser/tab_contents/tab_contents_observer.cc b/content/browser/tab_contents/tab_contents_observer.cc
index 44a4d45..6ce40e8 100644
--- a/content/browser/tab_contents/tab_contents_observer.cc
+++ b/content/browser/tab_contents/tab_contents_observer.cc
@@ -82,9 +82,9 @@ void TabContentsObserver::DidOpenURL(const GURL& url,
PageTransition::Type transition) {
}
-TabContentsObserver::TabContentsObserver(TabContents* tab_contents) {
- SetTabContents(tab_contents);
- tab_contents_->AddObserver(this);
+TabContentsObserver::TabContentsObserver(TabContents* tab_contents)
+ : tab_contents_(NULL), routing_id_(MSG_ROUTING_NONE) {
+ Observe(tab_contents);
}
TabContentsObserver::TabContentsObserver()
@@ -96,6 +96,16 @@ TabContentsObserver::~TabContentsObserver() {
tab_contents_->RemoveObserver(this);
}
+void TabContentsObserver::Observe(TabContents* tab_contents) {
+ if (tab_contents_)
+ tab_contents_->RemoveObserver(this);
+ tab_contents_ = tab_contents;
+ if (tab_contents_) {
+ routing_id_ = tab_contents->render_view_host()->routing_id();
+ tab_contents_->AddObserver(this);
+ }
+}
+
void TabContentsObserver::TabContentsDestroyed(TabContents* tab) {
}
@@ -119,12 +129,6 @@ int TabContentsObserver::routing_id() const {
return tab_contents_->render_view_host()->routing_id();
}
-void TabContentsObserver::SetTabContents(TabContents* tab_contents) {
- tab_contents_ = tab_contents;
- if (tab_contents_)
- routing_id_ = tab_contents->render_view_host()->routing_id();
-}
-
void TabContentsObserver::TabContentsDestroyed() {
// Do cleanup so that 'this' can safely be deleted from
// TabContentsDestroyed.
diff --git a/content/browser/tab_contents/tab_contents_observer.h b/content/browser/tab_contents/tab_contents_observer.h
index f085062..d7c3d77 100644
--- a/content/browser/tab_contents/tab_contents_observer.h
+++ b/content/browser/tab_contents/tab_contents_observer.h
@@ -11,7 +11,6 @@
#include "webkit/glue/window_open_disposition.h"
class RenderViewHost;
-class TabContentsObserverRegistrar;
struct ViewHostMsg_FrameNavigate_Params;
// An observer API implemented by classes which are interested in various page
@@ -84,12 +83,15 @@ class TabContentsObserver : public IPC::Channel::Listener,
explicit TabContentsObserver(TabContents* tab_contents);
// Use this constructor when the object wants to observe a TabContents for
- // part of its lifetime. It can use a TabContentsObserverRegistrar member
- // variable to start and stop observing.
+ // part of its lifetime. It can then call Observe() to start and stop
+ // observing.
TabContentsObserver();
virtual ~TabContentsObserver();
+ // Start observing a different TabContents; used with the default constructor.
+ void Observe(TabContents* tab_contents);
+
// Invoked when the TabContents is being destroyed. Gives subclasses a chance
// to cleanup. At the time this is invoked |tab_contents()| returns NULL.
// It is safe to delete 'this' from here.
@@ -104,11 +106,6 @@ class TabContentsObserver : public IPC::Channel::Listener,
TabContents* tab_contents() const { return tab_contents_; }
int routing_id() const;
- friend class TabContentsObserverRegistrar;
-
- // Called from TabContents in response to having |this| added as an observer.
- void SetTabContents(TabContents* tab_contents);
-
private:
friend class TabContents;
diff --git a/content/browser/tab_contents/tab_contents_observer_registrar.cc b/content/browser/tab_contents/tab_contents_observer_registrar.cc
deleted file mode 100644
index 352525f..0000000
--- a/content/browser/tab_contents/tab_contents_observer_registrar.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/browser/tab_contents/tab_contents_observer_registrar.h"
-
-#include "content/browser/tab_contents/tab_contents.h"
-
-TabContentsObserverRegistrar::TabContentsObserverRegistrar(
- TabContentsObserver* observer)
- : observer_(observer), tab_(NULL) {
-}
-
-TabContentsObserverRegistrar::~TabContentsObserverRegistrar() {
- if (tab_) {
- tab_->RemoveObserver(observer_);
- tab_->RemoveObserver(this);
- }
-}
-
-void TabContentsObserverRegistrar::Observe(TabContents* tab) {
- observer_->SetTabContents(tab);
- SetTabContents(tab);
- if (tab_) {
- tab_->RemoveObserver(observer_);
- tab_->RemoveObserver(this);
- }
- tab_ = tab;
- if (tab_) {
- tab_->AddObserver(observer_);
- tab_->AddObserver(this);
- }
-}
-
-void TabContentsObserverRegistrar::TabContentsDestroyed(TabContents* tab) {
- Observe(NULL);
-}
diff --git a/content/browser/tab_contents/tab_contents_observer_registrar.h b/content/browser/tab_contents/tab_contents_observer_registrar.h
deleted file mode 100644
index fa488d9..0000000
--- a/content/browser/tab_contents/tab_contents_observer_registrar.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_REGISTRAR_H_
-#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_REGISTRAR_H_
-
-#include "content/browser/tab_contents/tab_contents_observer.h"
-
-// Use this as a member variable in a class that uses the empty constructor
-// version of this interface. On destruction of TabContents being observed,
-// the registrar must either be destroyed or explicitly set to observe
-// another TabContents.
-class TabContentsObserverRegistrar : public TabContentsObserver {
- public:
- explicit TabContentsObserverRegistrar(TabContentsObserver* observer);
- virtual ~TabContentsObserverRegistrar();
-
- // Call this to start observing a tab. Passing in NULL resets it.
- // This can only be used to watch one tab at a time. If you call this and
- // you're already observing another tab, the old tab won't be observed
- // afterwards.
- void Observe(TabContents* tab);
-
- private:
- virtual void TabContentsDestroyed(TabContents* tab);
-
- TabContentsObserver* observer_;
- TabContents* tab_;
-
- DISALLOW_COPY_AND_ASSIGN(TabContentsObserverRegistrar);
-};
-
-#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_REGISTRAR_H_
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index 007cb34..f27de01 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -335,8 +335,6 @@
'browser/tab_contents/tab_contents_delegate.h',
'browser/tab_contents/tab_contents_observer.cc',
'browser/tab_contents/tab_contents_observer.h',
- 'browser/tab_contents/tab_contents_observer_registrar.cc',
- 'browser/tab_contents/tab_contents_observer_registrar.h',
'browser/tab_contents/tab_contents_view.cc',
'browser/tab_contents/tab_contents_view.h',
'browser/tab_contents/title_updated_details.h',