diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-16 21:00:48 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-16 21:00:48 +0000 |
commit | 447c79c28fa36d23081359920e45c810eca94dfe (patch) | |
tree | ce29d19af3d2a745019ee9f10e387c27e1860936 /chrome/browser/alternate_nav_url_fetcher.cc | |
parent | e57d57f04228aee2cfe96a598669f8e0b1662f09 (diff) | |
download | chromium_src-447c79c28fa36d23081359920e45c810eca94dfe.zip chromium_src-447c79c28fa36d23081359920e45c810eca94dfe.tar.gz chromium_src-447c79c28fa36d23081359920e45c810eca94dfe.tar.bz2 |
Remove the rest of the alternate nav url fetcher from the navigation controller.
This changes the memory model around a bit, and it's not the most clear thing
ever, not that it was before. The alternate URL fetcher is now responsible for
deleting itself in most cases.
BUG=2370 (Assertion when using the alternate URL tracker twice in a row)
BUG=1324500 (Move the AlternateNavURLFetcher logic out of NavigationController)
Review URL: http://codereview.chromium.org/2905
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2279 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/alternate_nav_url_fetcher.cc')
-rw-r--r-- | chrome/browser/alternate_nav_url_fetcher.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc index 3f16e2f..9560d9b 100644 --- a/chrome/browser/alternate_nav_url_fetcher.cc +++ b/chrome/browser/alternate_nav_url_fetcher.cc @@ -19,25 +19,23 @@ AlternateNavURLFetcher::AlternateNavURLFetcher( NotificationService::AllSources()); } -AlternateNavURLFetcher::~AlternateNavURLFetcher() { -} - void AlternateNavURLFetcher::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { switch (type) { case NOTIFY_NAV_ENTRY_PENDING: controller_ = Source<NavigationController>(source).ptr(); - if (!controller_->GetPendingEntry()) - return; // No entry to attach ourselves to. - controller_->SetAlternateNavURLFetcher(this); + DCHECK(controller_->GetPendingEntry()); // Unregister for this notification now that we're pending, and start - // listening for the corresponding commit. + // listening for the corresponding commit. We also need to listen for the + // tab close command since that means the load will never commit! registrar_.Remove(this, NOTIFY_NAV_ENTRY_PENDING, NotificationService::AllSources()); registrar_.Add(this, NOTIFY_NAV_ENTRY_COMMITTED, Source<NavigationController>(controller_)); + registrar_.Add(this, NOTIFY_TAB_CLOSED, + Source<NavigationController>(controller_)); DCHECK_EQ(NOT_STARTED, state_); state_ = IN_PROGRESS; @@ -53,6 +51,14 @@ void AlternateNavURLFetcher::Observe(NotificationType type, Source<NavigationController>(controller_)); navigated_to_entry_ = true; ShowInfobarIfPossible(); + // DON'T DO ANYTHING AFTER HERE SINCE |this| MAY BE DELETED! + break; + + case NOTIFY_TAB_CLOSED: + // We listen either for tab closed or navigation committed to know when to + // delete ourselves. Here, the tab closed, so we can just give up with + // all our waiting for notifications and delete ourselves. + delete this; break; default: @@ -73,6 +79,7 @@ void AlternateNavURLFetcher::OnURLFetchComplete(const URLFetcher* source, (response_code == 401) || (response_code == 407))) { state_ = SUCCEEDED; ShowInfobarIfPossible(); + // DON'T DO ANYTHING AFTER HERE SINCE |this| MAY BE DELETED! } else { state_ = FAILED; } @@ -94,5 +101,9 @@ void AlternateNavURLFetcher::ShowInfobarIfPossible() { // navigation, so we don't need to keep track of it. web_contents->GetInfoBarView()->AddChildView(new InfoBarAlternateNavURLView( alternate_nav_url_)); + + // Now we're no longer referencing the navigation controller or the url fetch, + // so our job is done. + delete this; } |