Commit b4b8711a authored by droger@chromium.org's avatar droger@chromium.org

Remove Infobars notifications from GoogleURLTrackerMapEntry

The InfoBarManager::Observer() is used instead.

GoogleURLTrackerMapEntry now makes actual calls on the InfoBarManager (to
register and unregister as an observer). This has some consequences:
- the |infobar_manager_| pointer is no longer const
- the unittest has to create actual instances of InfoBarManager instead of
using placeholder integers.

BUG=373243

Review URL: https://codereview.chromium.org/290453005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274510 0039d316-1c4b-4281-b951-d872f2087c98
parent 0d06a59d
...@@ -36,7 +36,6 @@ GoogleURLTracker::GoogleURLTracker(Profile* profile, ...@@ -36,7 +36,6 @@ GoogleURLTracker::GoogleURLTracker(Profile* profile,
Mode mode) Mode mode)
: profile_(profile), : profile_(profile),
client_(client.Pass()), client_(client.Pass()),
infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)),
google_url_(mode == UNIT_TEST_MODE ? google_url_(mode == UNIT_TEST_MODE ?
kDefaultGoogleHomepage : kDefaultGoogleHomepage :
profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)),
...@@ -343,7 +342,7 @@ void GoogleURLTracker::OnNavigationCommitted( ...@@ -343,7 +342,7 @@ void GoogleURLTracker::OnNavigationCommitted(
if (map_entry->has_infobar_delegate()) { if (map_entry->has_infobar_delegate()) {
map_entry->infobar_delegate()->Update(search_url); map_entry->infobar_delegate()->Update(search_url);
} else { } else {
infobars::InfoBar* infobar = infobar_creator_.Run( infobars::InfoBar* infobar = GoogleURLTrackerInfoBarDelegate::Create(
infobar_manager, this, search_url); infobar_manager, this, search_url);
if (infobar) { if (infobar) {
map_entry->SetInfoBarDelegate( map_entry->SetInfoBarDelegate(
......
...@@ -188,13 +188,6 @@ class GoogleURLTracker : public net::URLFetcherDelegate, ...@@ -188,13 +188,6 @@ class GoogleURLTracker : public net::URLFetcherDelegate,
scoped_ptr<GoogleURLTrackerClient> client_; scoped_ptr<GoogleURLTrackerClient> client_;
// Creates an infobar and adds it to the provided InfoBarManager. Returns
// the infobar on success or NULL on failure. The caller does not own the
// returned object, the InfoBarManager does.
base::Callback<infobars::InfoBar*(infobars::InfoBarManager*,
GoogleURLTracker*,
const GURL&)> infobar_creator_;
GURL google_url_; GURL google_url_;
GURL fetched_google_url_; GURL fetched_google_url_;
scoped_ptr<net::URLFetcher> fetcher_; scoped_ptr<net::URLFetcher> fetcher_;
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_url_tracker.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry( GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry(
GoogleURLTracker* google_url_tracker, GoogleURLTracker* google_url_tracker,
...@@ -17,25 +15,14 @@ GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry( ...@@ -17,25 +15,14 @@ GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry(
: google_url_tracker_(google_url_tracker), : google_url_tracker_(google_url_tracker),
infobar_manager_(infobar_manager), infobar_manager_(infobar_manager),
infobar_delegate_(NULL), infobar_delegate_(NULL),
navigation_helper_(navigation_helper.Pass()) { navigation_helper_(navigation_helper.Pass()),
observing_(false) {
DCHECK(infobar_manager_);
} }
GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() { GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() {
} if (observing_)
infobar_manager_->RemoveObserver(this);
void GoogleURLTrackerMapEntry::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(infobar_delegate_);
DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
DCHECK_EQ(infobar_manager_,
content::Source<infobars::InfoBarManager>(source).ptr());
if (content::Details<infobars::InfoBar::RemovedDetails>(
details)->first->delegate() == infobar_delegate_) {
google_url_tracker_->DeleteMapEntryForManager(infobar_manager_);
// WARNING: At this point |this| has been deleted!
}
} }
void GoogleURLTrackerMapEntry::SetInfoBarDelegate( void GoogleURLTrackerMapEntry::SetInfoBarDelegate(
...@@ -47,9 +34,8 @@ void GoogleURLTrackerMapEntry::SetInfoBarDelegate( ...@@ -47,9 +34,8 @@ void GoogleURLTrackerMapEntry::SetInfoBarDelegate(
// the case where the user accepts the new Google URL. // the case where the user accepts the new Google URL.
infobar_delegate->set_navigation_helper(navigation_helper_.Pass()); infobar_delegate->set_navigation_helper(navigation_helper_.Pass());
infobar_delegate_ = infobar_delegate; infobar_delegate_ = infobar_delegate;
registrar_.Add(this, infobar_manager_->AddObserver(this);
chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, observing_ = true;
content::Source<infobars::InfoBarManager>(infobar_manager_));
} }
void GoogleURLTrackerMapEntry::Close(bool redo_search) { void GoogleURLTrackerMapEntry::Close(bool redo_search) {
...@@ -62,3 +48,20 @@ void GoogleURLTrackerMapEntry::Close(bool redo_search) { ...@@ -62,3 +48,20 @@ void GoogleURLTrackerMapEntry::Close(bool redo_search) {
} }
// WARNING: At this point |this| has been deleted! // WARNING: At this point |this| has been deleted!
} }
void GoogleURLTrackerMapEntry::OnInfoBarRemoved(infobars::InfoBar* infobar,
bool animate) {
DCHECK(infobar_delegate_);
if (infobar->delegate() == infobar_delegate_) {
google_url_tracker_->DeleteMapEntryForManager(infobar_manager_);
// WARNING: At this point |this| has been deleted!
}
}
void GoogleURLTrackerMapEntry::OnManagerShuttingDown(
infobars::InfoBarManager* manager) {
DCHECK(observing_);
DCHECK_EQ(infobar_manager_, manager);
manager->RemoveObserver(this);
observing_ = false;
}
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/google/google_url_tracker_infobar_delegate.h" #include "chrome/browser/google/google_url_tracker_infobar_delegate.h"
#include "chrome/browser/google/google_url_tracker_navigation_helper.h" #include "chrome/browser/google/google_url_tracker_navigation_helper.h"
#include "content/public/browser/notification_observer.h" #include "components/infobars/core/infobar_manager.h"
#include "content/public/browser/notification_registrar.h"
class GoogleURLTracker; class GoogleURLTracker;
...@@ -17,7 +16,7 @@ namespace infobars { ...@@ -17,7 +16,7 @@ namespace infobars {
class InfoBarManager; class InfoBarManager;
} }
class GoogleURLTrackerMapEntry : public content::NotificationObserver { class GoogleURLTrackerMapEntry : public infobars::InfoBarManager::Observer {
public: public:
GoogleURLTrackerMapEntry( GoogleURLTrackerMapEntry(
GoogleURLTracker* google_url_tracker, GoogleURLTracker* google_url_tracker,
...@@ -38,21 +37,26 @@ class GoogleURLTrackerMapEntry : public content::NotificationObserver { ...@@ -38,21 +37,26 @@ class GoogleURLTrackerMapEntry : public content::NotificationObserver {
infobar_delegate_->navigation_helper() : navigation_helper_.get(); infobar_delegate_->navigation_helper() : navigation_helper_.get();
} }
const infobars::InfoBarManager* infobar_manager() const {
return infobar_manager_;
}
void Close(bool redo_search); void Close(bool redo_search);
private: private:
friend class GoogleURLTrackerTest; friend class GoogleURLTrackerTest;
// content::NotificationObserver: // infobars::InfoBarManager::Observer:
virtual void Observe(int type, virtual void OnInfoBarRemoved(infobars::InfoBar* infobar,
const content::NotificationSource& source, bool animate) OVERRIDE;
const content::NotificationDetails& details) OVERRIDE; virtual void OnManagerShuttingDown(
infobars::InfoBarManager* manager) OVERRIDE;
content::NotificationRegistrar registrar_;
GoogleURLTracker* const google_url_tracker_; GoogleURLTracker* const google_url_tracker_;
const infobars::InfoBarManager* const infobar_manager_; infobars::InfoBarManager* const infobar_manager_;
GoogleURLTrackerInfoBarDelegate* infobar_delegate_; GoogleURLTrackerInfoBarDelegate* infobar_delegate_;
scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper_; scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper_;
bool observing_;
DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerMapEntry); DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerMapEntry);
}; };
......
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