| Index: chrome/browser/google/google_url_tracker.cc
 | 
| ===================================================================
 | 
| --- chrome/browser/google/google_url_tracker.cc	(revision 134398)
 | 
| +++ chrome/browser/google/google_url_tracker.cc	(working copy)
 | 
| @@ -86,11 +86,24 @@
 | 
|  }
 | 
|  
 | 
|  void GoogleURLTrackerInfoBarDelegate::Show() {
 | 
| -  owner()->AddInfoBar(this);
 | 
|    showing_ = true;
 | 
| +  owner()->AddInfoBar(this);  // May delete |this| on failure!
 | 
|  }
 | 
|  
 | 
|  void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) {
 | 
| +  if (redo_search) {
 | 
| +    // Re-do the user's search on the new domain.
 | 
| +    url_canon::Replacements<char> replacements;
 | 
| +    const std::string& host(new_google_url_.host());
 | 
| +    replacements.SetHost(host.data(), url_parse::Component(0, host.length()));
 | 
| +    GURL new_search_url(search_url_.ReplaceComponents(replacements));
 | 
| +    if (new_search_url.is_valid()) {
 | 
| +      content::OpenURLParams params(new_search_url, content::Referrer(),
 | 
| +          CURRENT_TAB, content::PAGE_TRANSITION_GENERATED, false);
 | 
| +      owner()->web_contents()->OpenURL(params);
 | 
| +    }
 | 
| +  }
 | 
| +
 | 
|    if (!showing_) {
 | 
|      // We haven't been added to a tab, so just delete ourselves.
 | 
|      delete this;
 | 
| @@ -104,29 +117,15 @@
 | 
|    google_url_tracker_->InfoBarClosed(map_key_);
 | 
|    google_url_tracker_ = NULL;
 | 
|  
 | 
| -  // If we were showing in a background tab that was then closed, we could have
 | 
| -  // been leaked, and subsequently reached here due to
 | 
| -  // GoogleURLTracker::CloseAllInfoBars().  In this case our owner is now NULL
 | 
| -  // so we should just do nothing.
 | 
| -  // TODO(pkasting): This can go away once the InfoBar ownership model is fixed
 | 
| -  // so that infobars in background tabs don't leak on tab closure.
 | 
| -  if (!owner())
 | 
| -    return;
 | 
| -
 | 
| -  if (redo_search) {
 | 
| -    // Re-do the user's search on the new domain.
 | 
| -    url_canon::Replacements<char> replacements;
 | 
| -    const std::string& host(new_google_url_.host());
 | 
| -    replacements.SetHost(host.data(), url_parse::Component(0, host.length()));
 | 
| -    GURL new_search_url(search_url_.ReplaceComponents(replacements));
 | 
| -    if (new_search_url.is_valid()) {
 | 
| -      content::OpenURLParams params(new_search_url, content::Referrer(),
 | 
| -          CURRENT_TAB, content::PAGE_TRANSITION_GENERATED, false);
 | 
| -      owner()->web_contents()->OpenURL(params);
 | 
| -    }
 | 
| -  }
 | 
| -
 | 
| -  owner()->RemoveInfoBar(this);
 | 
| +  // If we're already animating closed, we won't have an owner.  Do nothing in
 | 
| +  // this case.
 | 
| +  // TODO(pkasting): For now, this can also happen if we were showing in a
 | 
| +  // background tab that was then closed, in which case we'll have leaked and
 | 
| +  // subsequently reached here due to GoogleURLTracker::CloseAllInfoBars().
 | 
| +  // This case will no longer happen once infobars are refactored to own their
 | 
| +  // delegates.
 | 
| +  if (owner())
 | 
| +    owner()->RemoveInfoBar(this);
 | 
|  }
 | 
|  
 | 
|  GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
 | 
| 
 |