Commit 8da5ccf2 authored by blundell@chromium.org's avatar blundell@chromium.org

Turn GoogleURLTrackerNavigationHelper(Impl) into a per-tab object.

The goal of this CL is to eliminate the dependence of
GoogleURLTracker(MapEntry) on NavigationController. To accomplish this goal,
GoogleURLTrackerNavigationHelper is turned into a conceptually per-tab
interface. GoogleURLTracker::OnNavigationPending() now takes in the
GoogleURLTrackerNavigationHelper with which the navigation is associated rather
than the associated NavigationController; GoogleURLTracker performs per-tab
actions by calling the navigation helper associated with the tab.

A followup CL will turn GoogleURLTrackerNavigationHelper(Impl) into the
GoogleURLTrackerDriver interface and ContentURLTrackerDriver implementation.

BUG=373230

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272094 0039d316-1c4b-4281-b951-d872f2087c98
parent 6dfed694
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#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 "chrome/browser/google/google_url_tracker_navigation_helper_impl.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
...@@ -48,12 +49,13 @@ void ChromeGoogleURLTrackerClient::Observe( ...@@ -48,12 +49,13 @@ void ChromeGoogleURLTrackerClient::Observe(
content::Source<content::NavigationController>(source).ptr(); content::Source<content::NavigationController>(source).ptr();
InfoBarService* infobar_service = InfoBarService* infobar_service =
InfoBarService::FromWebContents(controller->GetWebContents()); InfoBarService::FromWebContents(controller->GetWebContents());
// Because we're listening to all sources, there may be no // Because we're listening to all sources, there may be no InfoBarService for
// InfoBarService for some notifications, e.g. navigations in // some notifications, e.g. navigations in bubbles/balloons etc.
// bubbles/balloons etc.
if (infobar_service) { if (infobar_service) {
google_url_tracker()->OnNavigationPending( google_url_tracker()->OnNavigationPending(
controller, scoped_ptr<GoogleURLTrackerNavigationHelper>(
new GoogleURLTrackerNavigationHelperImpl(
controller->GetWebContents(), google_url_tracker())),
infobar_service, infobar_service,
controller->GetPendingEntry()->GetUniqueID()); controller->GetPendingEntry()->GetUniqueID());
} }
......
...@@ -33,14 +33,11 @@ const char GoogleURLTracker::kDefaultGoogleHomepage[] = ...@@ -33,14 +33,11 @@ const char GoogleURLTracker::kDefaultGoogleHomepage[] =
const char GoogleURLTracker::kSearchDomainCheckURL[] = const char GoogleURLTracker::kSearchDomainCheckURL[] =
"https://www.google.com/searchdomaincheck?format=url&type=chrome"; "https://www.google.com/searchdomaincheck?format=url&type=chrome";
GoogleURLTracker::GoogleURLTracker( GoogleURLTracker::GoogleURLTracker(Profile* profile,
Profile* profile, scoped_ptr<GoogleURLTrackerClient> client,
scoped_ptr<GoogleURLTrackerClient> client, Mode mode)
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
Mode mode)
: profile_(profile), : profile_(profile),
client_(client.Pass()), client_(client.Pass()),
nav_helper_(nav_helper.Pass()),
infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)), infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)),
google_url_(mode == UNIT_TEST_MODE ? google_url_(mode == UNIT_TEST_MODE ?
kDefaultGoogleHomepage : kDefaultGoogleHomepage :
...@@ -54,7 +51,6 @@ GoogleURLTracker::GoogleURLTracker( ...@@ -54,7 +51,6 @@ GoogleURLTracker::GoogleURLTracker(
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
net::NetworkChangeNotifier::AddIPAddressObserver(this); net::NetworkChangeNotifier::AddIPAddressObserver(this);
client_->set_google_url_tracker(this); client_->set_google_url_tracker(this);
nav_helper_->SetGoogleURLTracker(this);
// Because this function can be called during startup, when kicking off a URL // Because this function can be called during startup, when kicking off a URL
// fetch can eat up 20 ms of time, we delay five seconds, which is hopefully // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully
...@@ -205,7 +201,6 @@ void GoogleURLTracker::OnIPAddressChanged() { ...@@ -205,7 +201,6 @@ void GoogleURLTracker::OnIPAddressChanged() {
void GoogleURLTracker::Shutdown() { void GoogleURLTracker::Shutdown() {
client_.reset(); client_.reset();
nav_helper_.reset();
fetcher_.reset(); fetcher_.reset();
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
net::NetworkChangeNotifier::RemoveIPAddressObserver(this); net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
...@@ -219,7 +214,7 @@ void GoogleURLTracker::DeleteMapEntryForService( ...@@ -219,7 +214,7 @@ void GoogleURLTracker::DeleteMapEntryForService(
DCHECK(i != entry_map_.end()); DCHECK(i != entry_map_.end());
GoogleURLTrackerMapEntry* map_entry = i->second; GoogleURLTrackerMapEntry* map_entry = i->second;
UnregisterForEntrySpecificNotifications(*map_entry, false); UnregisterForEntrySpecificNotifications(map_entry, false);
entry_map_.erase(i); entry_map_.erase(i);
delete map_entry; delete map_entry;
} }
...@@ -281,39 +276,41 @@ void GoogleURLTracker::SearchCommitted() { ...@@ -281,39 +276,41 @@ void GoogleURLTracker::SearchCommitted() {
} }
void GoogleURLTracker::OnNavigationPending( void GoogleURLTracker::OnNavigationPending(
content::NavigationController* navigation_controller, scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
InfoBarService* infobar_service, InfoBarService* infobar_service,
int pending_id) { int pending_id) {
GoogleURLTrackerMapEntry* map_entry = NULL;
EntryMap::iterator i(entry_map_.find(infobar_service)); EntryMap::iterator i(entry_map_.find(infobar_service));
if (i != entry_map_.end())
map_entry = i->second;
if (search_committed_) { if (search_committed_) {
search_committed_ = false; search_committed_ = false;
// Whether there's an existing infobar or not, we need to listen for the if (!map_entry) {
// load to commit, so we can show and/or update the infobar when it does.
// (We may already be registered for this if there is an existing infobar
// that had a previous pending search that hasn't yet committed.)
if (!nav_helper_->IsListeningForNavigationCommit(navigation_controller)) {
nav_helper_->SetListeningForNavigationCommit(navigation_controller,
true);
}
if (i == entry_map_.end()) {
// This is a search on a tab that doesn't have one of our infobars, so // This is a search on a tab that doesn't have one of our infobars, so
// prepare to add one. Note that we only listen for the tab's destruction // prepare to add one. Note that we only listen for the tab's destruction
// on this path; if there was already a map entry, then either it doesn't // on this path; if there was already a map entry, then either it doesn't
// yet have an infobar and we're already registered for this, or it has an // yet have an infobar and we're already registered for this, or it has an
// infobar and the infobar's owner will handle tearing it down when the // infobar and the infobar's owner will handle tearing it down when the
// tab is destroyed. // tab is destroyed.
nav_helper_->SetListeningForTabDestruction(navigation_controller, true); map_entry = new GoogleURLTrackerMapEntry(
entry_map_.insert(std::make_pair( this, infobar_service, nav_helper.Pass());
infobar_service, map_entry->navigation_helper()->SetListeningForTabDestruction(true);
new GoogleURLTrackerMapEntry(this, infobar_service, entry_map_.insert(std::make_pair(infobar_service, map_entry));
navigation_controller))); } else if (map_entry->infobar_delegate()) {
} else if (i->second->has_infobar_delegate()) {
// This is a new search on a tab where we already have an infobar. // This is a new search on a tab where we already have an infobar.
i->second->infobar_delegate()->set_pending_id(pending_id); map_entry->infobar_delegate()->set_pending_id(pending_id);
} }
} else if (i != entry_map_.end()){
if (i->second->has_infobar_delegate()) { // Whether there's an existing infobar or not, we need to listen for the
// load to commit, so we can show and/or update the infobar when it does.
// (We may already be registered for this if there is an existing infobar
// that had a previous pending search that hasn't yet committed.)
if (!map_entry->navigation_helper()->IsListeningForNavigationCommit())
map_entry->navigation_helper()->SetListeningForNavigationCommit(true);
} else if (map_entry) {
if (map_entry->has_infobar_delegate()) {
// This is a non-search navigation on a tab with an infobar. If there was // This is a non-search navigation on a tab with an infobar. If there was
// a previous pending search on this tab, this means it won't commit, so // a previous pending search on this tab, this means it won't commit, so
// undo anything we did in response to seeing that. Note that if there // undo anything we did in response to seeing that. Note that if there
...@@ -323,13 +320,13 @@ void GoogleURLTracker::OnNavigationPending( ...@@ -323,13 +320,13 @@ void GoogleURLTracker::OnNavigationPending(
// If this navigation actually commits, that will trigger the infobar's // If this navigation actually commits, that will trigger the infobar's
// owner to expire the infobar if need be. If it doesn't commit, then // owner to expire the infobar if need be. If it doesn't commit, then
// simply leaving the infobar as-is will have been the right thing. // simply leaving the infobar as-is will have been the right thing.
UnregisterForEntrySpecificNotifications(*i->second, false); UnregisterForEntrySpecificNotifications(map_entry, false);
i->second->infobar_delegate()->set_pending_id(0); map_entry->infobar_delegate()->set_pending_id(0);
} else { } else {
// Non-search navigation on a tab with an entry that has not yet created // Non-search navigation on a tab with an entry that has not yet created
// an infobar. This means the original search won't commit, so delete the // an infobar. This means the original search won't commit, so delete the
// entry. // entry.
i->second->Close(false); map_entry->Close(false);
} }
} else { } else {
// Non-search navigation on a tab without an infobars. This is irrelevant // Non-search navigation on a tab without an infobars. This is irrelevant
...@@ -344,7 +341,7 @@ void GoogleURLTracker::OnNavigationCommitted(InfoBarService* infobar_service, ...@@ -344,7 +341,7 @@ void GoogleURLTracker::OnNavigationCommitted(InfoBarService* infobar_service,
GoogleURLTrackerMapEntry* map_entry = i->second; GoogleURLTrackerMapEntry* map_entry = i->second;
DCHECK(search_url.is_valid()); DCHECK(search_url.is_valid());
UnregisterForEntrySpecificNotifications(*map_entry, true); UnregisterForEntrySpecificNotifications(map_entry, true);
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 {
...@@ -360,7 +357,7 @@ void GoogleURLTracker::OnNavigationCommitted(InfoBarService* infobar_service, ...@@ -360,7 +357,7 @@ void GoogleURLTracker::OnNavigationCommitted(InfoBarService* infobar_service,
} }
void GoogleURLTracker::OnTabClosed( void GoogleURLTracker::OnTabClosed(
content::NavigationController* navigation_controller) { GoogleURLTrackerNavigationHelper* nav_helper) {
// Because InfoBarService tears itself down on tab destruction, it's possible // Because InfoBarService tears itself down on tab destruction, it's possible
// to get a non-NULL InfoBarService pointer here, depending on which order // to get a non-NULL InfoBarService pointer here, depending on which order
// notifications fired in. Likewise, the pointer in |entry_map_| (and in its // notifications fired in. Likewise, the pointer in |entry_map_| (and in its
...@@ -370,7 +367,7 @@ void GoogleURLTracker::OnTabClosed( ...@@ -370,7 +367,7 @@ void GoogleURLTracker::OnTabClosed(
// function doesn't need to do even that, but others in the call chain from // function doesn't need to do even that, but others in the call chain from
// here might (and have comments pointing back here). // here might (and have comments pointing back here).
for (EntryMap::iterator i(entry_map_.begin()); i != entry_map_.end(); ++i) { for (EntryMap::iterator i(entry_map_.begin()); i != entry_map_.end(); ++i) {
if (i->second->navigation_controller() == navigation_controller) { if (i->second->navigation_helper() == nav_helper) {
i->second->Close(false); i->second->Close(false);
return; return;
} }
...@@ -390,26 +387,22 @@ void GoogleURLTracker::CloseAllEntries(bool redo_searches) { ...@@ -390,26 +387,22 @@ void GoogleURLTracker::CloseAllEntries(bool redo_searches) {
} }
void GoogleURLTracker::UnregisterForEntrySpecificNotifications( void GoogleURLTracker::UnregisterForEntrySpecificNotifications(
const GoogleURLTrackerMapEntry& map_entry, GoogleURLTrackerMapEntry* map_entry,
bool must_be_listening_for_commit) { bool must_be_listening_for_commit) {
// For tabs with map entries but no infobars, we should always be listening // For tabs with map entries but no infobars, we should always be listening
// for both these notifications. For tabs with infobars, we may be listening // for both these notifications. For tabs with infobars, we may be listening
// for navigation commits if the user has performed a new search on this tab. // for navigation commits if the user has performed a new search on this tab.
if (nav_helper_->IsListeningForNavigationCommit( if (map_entry->navigation_helper()->IsListeningForNavigationCommit()) {
map_entry.navigation_controller())) { map_entry->navigation_helper()->SetListeningForNavigationCommit(false);
nav_helper_->SetListeningForNavigationCommit(
map_entry.navigation_controller(), false);
} else { } else {
DCHECK(!must_be_listening_for_commit); DCHECK(!must_be_listening_for_commit);
DCHECK(map_entry.has_infobar_delegate()); DCHECK(map_entry->has_infobar_delegate());
} }
const bool registered_for_tab_destruction = const bool registered_for_tab_destruction =
nav_helper_->IsListeningForTabDestruction( map_entry->navigation_helper()->IsListeningForTabDestruction();
map_entry.navigation_controller()); DCHECK_NE(registered_for_tab_destruction, map_entry->has_infobar_delegate());
DCHECK_NE(registered_for_tab_destruction, map_entry.has_infobar_delegate());
if (registered_for_tab_destruction) { if (registered_for_tab_destruction) {
nav_helper_->SetListeningForTabDestruction( map_entry->navigation_helper()->SetListeningForTabDestruction(false);
map_entry.navigation_controller(), false);
} }
// Our global listeners for these other notifications should be in place iff // Our global listeners for these other notifications should be in place iff
...@@ -419,8 +412,7 @@ void GoogleURLTracker::UnregisterForEntrySpecificNotifications( ...@@ -419,8 +412,7 @@ void GoogleURLTracker::UnregisterForEntrySpecificNotifications(
// See the various cases inside OnNavigationPending(). // See the various cases inside OnNavigationPending().
for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end(); for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end();
++i) { ++i) {
if (nav_helper_->IsListeningForNavigationCommit( if (i->second->navigation_helper()->IsListeningForNavigationCommit()) {
i->second->navigation_controller())) {
DCHECK(client_->IsListeningForNavigationStart()); DCHECK(client_->IsListeningForNavigationStart());
return; return;
} }
......
...@@ -26,10 +26,6 @@ class GoogleURLTrackerNavigationHelper; ...@@ -26,10 +26,6 @@ class GoogleURLTrackerNavigationHelper;
class PrefService; class PrefService;
class Profile; class Profile;
namespace content {
class NavigationController;
}
namespace infobars { namespace infobars {
class InfoBar; class InfoBar;
} }
...@@ -72,7 +68,6 @@ class GoogleURLTracker : public net::URLFetcherDelegate, ...@@ -72,7 +68,6 @@ class GoogleURLTracker : public net::URLFetcherDelegate,
// GoogleURLTrackerFactory::GetForProfile(). // GoogleURLTrackerFactory::GetForProfile().
GoogleURLTracker(Profile* profile, GoogleURLTracker(Profile* profile,
scoped_ptr<GoogleURLTrackerClient> client, scoped_ptr<GoogleURLTrackerClient> client,
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
Mode mode); Mode mode);
virtual ~GoogleURLTracker(); virtual ~GoogleURLTracker();
...@@ -113,14 +108,14 @@ class GoogleURLTracker : public net::URLFetcherDelegate, ...@@ -113,14 +108,14 @@ class GoogleURLTracker : public net::URLFetcherDelegate,
// Called by the client after SearchCommitted() registers listeners, to // Called by the client after SearchCommitted() registers listeners, to
// indicate that we've received the "load now pending" notification. // indicate that we've received the "load now pending" notification.
// |navigation_controller| is the NavigationController for this load; // |nav_helper| is the GoogleURLTrackerNavigationHelper associated with this
// |infobar_service| is the InfoBarService of the associated tab; and // navigation; |infobar_service| is the InfoBarService of the associated tab;
// |pending_id| is the unique ID of the newly pending NavigationEntry. If // and |pending_id| is the unique ID of the newly pending NavigationEntry.
// there is already a visible GoogleURLTracker infobar for this tab, this // If there is already a visible GoogleURLTracker infobar for this tab, this
// function resets its associated pending entry ID to the new ID. Otherwise // function resets its associated pending entry ID to the new ID. Otherwise
// this function creates a map entry for the associated tab. // this function creates a map entry for the associated tab.
virtual void OnNavigationPending( virtual void OnNavigationPending(
content::NavigationController* navigation_controller, scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
InfoBarService* infobar_service, InfoBarService* infobar_service,
int pending_id); int pending_id);
...@@ -131,8 +126,7 @@ class GoogleURLTracker : public net::URLFetcherDelegate, ...@@ -131,8 +126,7 @@ class GoogleURLTracker : public net::URLFetcherDelegate,
const GURL& search_url); const GURL& search_url);
// Called by the navigation observer when a tab closes. // Called by the navigation observer when a tab closes.
virtual void OnTabClosed( virtual void OnTabClosed(GoogleURLTrackerNavigationHelper* nav_helper);
content::NavigationController* navigation_controller);
scoped_ptr<Subscription> RegisterCallback( scoped_ptr<Subscription> RegisterCallback(
const OnGoogleURLUpdatedCallback& cb); const OnGoogleURLUpdatedCallback& cb);
...@@ -174,14 +168,14 @@ class GoogleURLTracker : public net::URLFetcherDelegate, ...@@ -174,14 +168,14 @@ class GoogleURLTracker : public net::URLFetcherDelegate,
// Google TLD. // Google TLD.
void CloseAllEntries(bool redo_searches); void CloseAllEntries(bool redo_searches);
// Unregisters any listeners for the navigation controller in |map_entry|. // Unregisters any listeners for the navigation helper in |map_entry|.
// This sanity-DCHECKs that these are registered (or not) in the specific // This sanity-DCHECKs that these are registered (or not) in the specific
// cases we expect. (|must_be_listening_for_commit| is used purely for this // cases we expect. (|must_be_listening_for_commit| is used purely for this
// sanity-checking.) This also unregisters the global navigation pending // sanity-checking.) This also unregisters the global navigation pending
// listener if there are no remaining listeners for navigation commits, as we // listener if there are no remaining listeners for navigation commits, as we
// no longer need them until another search is committed. // no longer need them until another search is committed.
void UnregisterForEntrySpecificNotifications( void UnregisterForEntrySpecificNotifications(
const GoogleURLTrackerMapEntry& map_entry, GoogleURLTrackerMapEntry* map_entry,
bool must_be_listening_for_commit); bool must_be_listening_for_commit);
void NotifyGoogleURLUpdated(GURL old_url, GURL new_url); void NotifyGoogleURLUpdated(GURL old_url, GURL new_url);
...@@ -192,8 +186,6 @@ class GoogleURLTracker : public net::URLFetcherDelegate, ...@@ -192,8 +186,6 @@ class GoogleURLTracker : public net::URLFetcherDelegate,
scoped_ptr<GoogleURLTrackerClient> client_; scoped_ptr<GoogleURLTrackerClient> client_;
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_;
// Creates an infobar and adds it to the provided InfoBarService. Returns the // Creates an infobar and adds it to the provided InfoBarService. Returns the
// infobar on success or NULL on failure. The caller does not own the // infobar on success or NULL on failure. The caller does not own the
// returned object, the InfoBarService does. // returned object, the InfoBarService does.
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/google/chrome_google_url_tracker_client.h" #include "chrome/browser/google/chrome_google_url_tracker_client.h"
#include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/google/google_url_tracker_navigation_helper_impl.h"
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -38,11 +37,8 @@ GoogleURLTrackerFactory::~GoogleURLTrackerFactory() { ...@@ -38,11 +37,8 @@ GoogleURLTrackerFactory::~GoogleURLTrackerFactory() {
KeyedService* GoogleURLTrackerFactory::BuildServiceInstanceFor( KeyedService* GoogleURLTrackerFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const { content::BrowserContext* profile) const {
scoped_ptr<GoogleURLTrackerClient> client(new ChromeGoogleURLTrackerClient()); scoped_ptr<GoogleURLTrackerClient> client(new ChromeGoogleURLTrackerClient());
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(
new GoogleURLTrackerNavigationHelperImpl());
return new GoogleURLTracker(static_cast<Profile*>(profile), return new GoogleURLTracker(static_cast<Profile*>(profile),
client.Pass(), client.Pass(),
nav_helper.Pass(),
GoogleURLTracker::NORMAL_MODE); GoogleURLTracker::NORMAL_MODE);
} }
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry( GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry(
GoogleURLTracker* google_url_tracker, GoogleURLTracker* google_url_tracker,
InfoBarService* infobar_service, InfoBarService* infobar_service,
const content::NavigationController* navigation_controller) scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper)
: google_url_tracker_(google_url_tracker), : google_url_tracker_(google_url_tracker),
infobar_service_(infobar_service), infobar_service_(infobar_service),
infobar_delegate_(NULL), infobar_delegate_(NULL),
navigation_controller_(navigation_controller) { navigation_helper_(navigation_helper.Pass()) {
} }
GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() { GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_MAP_ENTRY_H_ #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_MAP_ENTRY_H_
#define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_MAP_ENTRY_H_ #define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_MAP_ENTRY_H_
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/google/google_url_tracker_navigation_helper.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
...@@ -12,16 +14,12 @@ class GoogleURLTracker; ...@@ -12,16 +14,12 @@ class GoogleURLTracker;
class GoogleURLTrackerInfoBarDelegate; class GoogleURLTrackerInfoBarDelegate;
class InfoBarService; class InfoBarService;
namespace content {
class NavigationController;
}
class GoogleURLTrackerMapEntry : public content::NotificationObserver { class GoogleURLTrackerMapEntry : public content::NotificationObserver {
public: public:
GoogleURLTrackerMapEntry( GoogleURLTrackerMapEntry(
GoogleURLTracker* google_url_tracker, GoogleURLTracker* google_url_tracker,
InfoBarService* infobar_service, InfoBarService* infobar_service,
const content::NavigationController* navigation_controller); scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper);
virtual ~GoogleURLTrackerMapEntry(); virtual ~GoogleURLTrackerMapEntry();
bool has_infobar_delegate() const { return !!infobar_delegate_; } bool has_infobar_delegate() const { return !!infobar_delegate_; }
...@@ -30,8 +28,8 @@ class GoogleURLTrackerMapEntry : public content::NotificationObserver { ...@@ -30,8 +28,8 @@ class GoogleURLTrackerMapEntry : public content::NotificationObserver {
} }
void SetInfoBarDelegate(GoogleURLTrackerInfoBarDelegate* infobar_delegate); void SetInfoBarDelegate(GoogleURLTrackerInfoBarDelegate* infobar_delegate);
const content::NavigationController* navigation_controller() const { GoogleURLTrackerNavigationHelper* navigation_helper() {
return navigation_controller_; return navigation_helper_.get();
} }
void Close(bool redo_search); void Close(bool redo_search);
...@@ -48,7 +46,7 @@ class GoogleURLTrackerMapEntry : public content::NotificationObserver { ...@@ -48,7 +46,7 @@ class GoogleURLTrackerMapEntry : public content::NotificationObserver {
GoogleURLTracker* const google_url_tracker_; GoogleURLTracker* const google_url_tracker_;
const InfoBarService* const infobar_service_; const InfoBarService* const infobar_service_;
GoogleURLTrackerInfoBarDelegate* infobar_delegate_; GoogleURLTrackerInfoBarDelegate* infobar_delegate_;
const content::NavigationController* const navigation_controller_; scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper_;
DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerMapEntry); DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerMapEntry);
}; };
......
// Copyright 2014 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 "chrome/browser/google/google_url_tracker_navigation_helper.h"
GoogleURLTrackerNavigationHelper::GoogleURLTrackerNavigationHelper(
GoogleURLTracker* google_url_tracker)
: google_url_tracker_(google_url_tracker) {
}
GoogleURLTrackerNavigationHelper::~GoogleURLTrackerNavigationHelper() {
}
...@@ -5,46 +5,42 @@ ...@@ -5,46 +5,42 @@
#ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_H_ #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_H_
#define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_H_ #define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_H_
class GoogleURLTracker; #include "base/macros.h"
class InfoBarService;
class Profile;
namespace content { class GoogleURLTracker;
class NavigationController;
}
// A helper class for GoogleURLTracker that abstracts the details of listening // A helper class for GoogleURLTracker that abstracts the details of listening
// for various navigation events. // for various navigation events.
class GoogleURLTrackerNavigationHelper { class GoogleURLTrackerNavigationHelper {
public: public:
virtual ~GoogleURLTrackerNavigationHelper() {} explicit GoogleURLTrackerNavigationHelper(
GoogleURLTracker* google_url_tracker);
virtual ~GoogleURLTrackerNavigationHelper();
// Sets the GoogleURLTracker that is associated with this object. // Enables or disables listening for navigation commits.
virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) = 0; // OnNavigationCommitted will be called for each navigation commit if
// listening is enabled.
virtual void SetListeningForNavigationCommit(bool listen) = 0;
// Enables or disables listening for navigation commits for the given // Returns whether or not this object is currently listening for navigation
// NavigationController. OnNavigationCommitted will be called for each // commits.
// navigation commit if listening is enabled. virtual bool IsListeningForNavigationCommit() = 0;
virtual void SetListeningForNavigationCommit(
const content::NavigationController* nav_controller,
bool listen) = 0;
// Returns whether or not the observer is currently listening for navigation // Enables or disables listening for tab destruction. OnTabClosed will be
// commits for the given NavigationController. // called on tab destruction if listening is enabled.
virtual bool IsListeningForNavigationCommit( virtual void SetListeningForTabDestruction(bool listen) = 0;
const content::NavigationController* nav_controller) = 0;
// Enables or disables listening for tab destruction for the given // Returns whether or not this object is currently listening for tab
// NavigationController. OnTabClosed will be called on tab destruction if // destruction.
// listening is enabled. virtual bool IsListeningForTabDestruction() = 0;
virtual void SetListeningForTabDestruction(
const content::NavigationController* nav_controller, protected:
bool listen) = 0; GoogleURLTracker* google_url_tracker() { return google_url_tracker_; }
// Returns whether or not the observer is currently listening for tab private:
// destruction for the given NavigationController. GoogleURLTracker* google_url_tracker_;
virtual bool IsListeningForTabDestruction(
const content::NavigationController* nav_controller) = 0; DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerNavigationHelper);
}; };
#endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_H_ #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_H_
...@@ -12,25 +12,21 @@ ...@@ -12,25 +12,21 @@
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
GoogleURLTrackerNavigationHelperImpl:: GoogleURLTrackerNavigationHelperImpl::GoogleURLTrackerNavigationHelperImpl(
GoogleURLTrackerNavigationHelperImpl() : tracker_(NULL) { content::WebContents* web_contents,
GoogleURLTracker* tracker)
: GoogleURLTrackerNavigationHelper(tracker),
web_contents_(web_contents) {
} }
GoogleURLTrackerNavigationHelperImpl:: GoogleURLTrackerNavigationHelperImpl::~GoogleURLTrackerNavigationHelperImpl() {
~GoogleURLTrackerNavigationHelperImpl() {
}
void GoogleURLTrackerNavigationHelperImpl::SetGoogleURLTracker(
GoogleURLTracker* tracker) {
DCHECK(tracker);
tracker_ = tracker;
} }
void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit(
const content::NavigationController* nav_controller,
bool listen) { bool listen) {
content::NotificationSource navigation_controller_source = content::NotificationSource navigation_controller_source =
content::Source<content::NavigationController>(nav_controller); content::Source<content::NavigationController>(
&web_contents_->GetController());
if (listen) { if (listen) {
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
navigation_controller_source); navigation_controller_source);
...@@ -40,47 +36,35 @@ void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( ...@@ -40,47 +36,35 @@ void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit(
} }
} }
bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit( bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationCommit() {
const content::NavigationController* nav_controller) {
content::NotificationSource navigation_controller_source = content::NotificationSource navigation_controller_source =
content::Source<content::NavigationController>(nav_controller); content::Source<content::NavigationController>(
&web_contents_->GetController());
return registrar_.IsRegistered( return registrar_.IsRegistered(
this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
navigation_controller_source); navigation_controller_source);
} }
void GoogleURLTrackerNavigationHelperImpl::SetListeningForTabDestruction( void GoogleURLTrackerNavigationHelperImpl::SetListeningForTabDestruction(
const content::NavigationController* nav_controller,
bool listen) { bool listen) {
content::NotificationSource navigation_controller_source = content::NotificationSource web_contents_source =
content::Source<content::NavigationController>(nav_controller); content::Source<content::WebContents>(web_contents_);
if (listen) { if (listen) {
registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, registrar_.Add(this,
GetWebContentsSource(navigation_controller_source)); content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
web_contents_source);
} else { } else {
registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, registrar_.Remove(this,
GetWebContentsSource(navigation_controller_source)); content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
web_contents_source);
} }
} }
bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction( bool GoogleURLTrackerNavigationHelperImpl::IsListeningForTabDestruction() {
const content::NavigationController* nav_controller) {
content::NotificationSource navigation_controller_source =
content::Source<content::NavigationController>(nav_controller);
return registrar_.IsRegistered( return registrar_.IsRegistered(
this, this,
content::NOTIFICATION_WEB_CONTENTS_DESTROYED, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
GetWebContentsSource(navigation_controller_source)); content::Source<content::WebContents>(web_contents_));
}
content::NotificationSource
GoogleURLTrackerNavigationHelperImpl::GetWebContentsSource(
const content::NotificationSource& nav_controller_source) {
content::NavigationController* controller =
content::Source<content::NavigationController>(
nav_controller_source).ptr();
content::WebContents* web_contents = controller->GetWebContents();
return content::Source<content::WebContents>(web_contents);
} }
void GoogleURLTrackerNavigationHelperImpl::Observe( void GoogleURLTrackerNavigationHelperImpl::Observe(
...@@ -91,23 +75,24 @@ void GoogleURLTrackerNavigationHelperImpl::Observe( ...@@ -91,23 +75,24 @@ void GoogleURLTrackerNavigationHelperImpl::Observe(
case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
content::NavigationController* controller = content::NavigationController* controller =
content::Source<content::NavigationController>(source).ptr(); content::Source<content::NavigationController>(source).ptr();
DCHECK_EQ(web_contents_, controller->GetWebContents());
// Here we're only listening to notifications where we already know // Here we're only listening to notifications where we already know
// there's an associated InfoBarService. // there's an associated InfoBarService.
content::WebContents* web_contents = controller->GetWebContents();
InfoBarService* infobar_service = InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents); InfoBarService::FromWebContents(web_contents_);
DCHECK(infobar_service); DCHECK(infobar_service);
const GURL& search_url = controller->GetActiveEntry()->GetURL(); const GURL& search_url = controller->GetActiveEntry()->GetURL();
if (!search_url.is_valid()) // Not clear if this can happen. if (!search_url.is_valid()) // Not clear if this can happen.
tracker_->OnTabClosed(controller); google_url_tracker()->OnTabClosed(this);
tracker_->OnNavigationCommitted(infobar_service, search_url); google_url_tracker()->OnNavigationCommitted(infobar_service, search_url);
break; break;
} }
case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: {
content::WebContents* web_contents = DCHECK_EQ(web_contents_,
content::Source<content::WebContents>(source).ptr(); content::Source<content::WebContents>(source).ptr());
tracker_->OnTabClosed(&web_contents->GetController()); google_url_tracker()->OnTabClosed(this);
break; break;
} }
......
...@@ -10,25 +10,25 @@ ...@@ -10,25 +10,25 @@
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace content {
class WebContents;
}
class GoogleURLTrackerNavigationHelperImpl class GoogleURLTrackerNavigationHelperImpl
: public GoogleURLTrackerNavigationHelper, : public GoogleURLTrackerNavigationHelper,
public content::NotificationObserver { public content::NotificationObserver {
public: public:
explicit GoogleURLTrackerNavigationHelperImpl(); GoogleURLTrackerNavigationHelperImpl(content::WebContents* web_contents,
GoogleURLTracker* tracker);
virtual ~GoogleURLTrackerNavigationHelperImpl(); virtual ~GoogleURLTrackerNavigationHelperImpl();
// GoogleURLTrackerNavigationHelper. // GoogleURLTrackerNavigationHelper:
virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE;
virtual void SetListeningForNavigationCommit( virtual void SetListeningForNavigationCommit(
const content::NavigationController* nav_controller,
bool listen) OVERRIDE; bool listen) OVERRIDE;
virtual bool IsListeningForNavigationCommit( virtual bool IsListeningForNavigationCommit() OVERRIDE;
const content::NavigationController* nav_controller) OVERRIDE;
virtual void SetListeningForTabDestruction( virtual void SetListeningForTabDestruction(
const content::NavigationController* nav_controller,
bool listen) OVERRIDE; bool listen) OVERRIDE;
virtual bool IsListeningForTabDestruction( virtual bool IsListeningForTabDestruction() OVERRIDE;
const content::NavigationController* nav_controller) OVERRIDE;
private: private:
// content::NotificationObserver: // content::NotificationObserver:
...@@ -36,13 +36,10 @@ class GoogleURLTrackerNavigationHelperImpl ...@@ -36,13 +36,10 @@ class GoogleURLTrackerNavigationHelperImpl
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
// Returns a WebContents NavigationSource for the WebContents corresponding to content::WebContents* web_contents_;
// the given NavigationController NotificationSource.
virtual content::NotificationSource GetWebContentsSource(
const content::NotificationSource& nav_controller_source);
GoogleURLTracker* tracker_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerNavigationHelperImpl);
}; };
#endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_IMPL_H_ #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_IMPL_H_
...@@ -137,73 +137,53 @@ bool TestGoogleURLTrackerClient::IsListeningForNavigationStart() { ...@@ -137,73 +137,53 @@ bool TestGoogleURLTrackerClient::IsListeningForNavigationStart() {
return observe_nav_start_; return observe_nav_start_;
} }
// TestGoogleURLTrackerNavigationHelper --------------------------------------- // TestGoogleURLTrackerNavigationHelper ---------------------------------------
class TestGoogleURLTrackerNavigationHelper class TestGoogleURLTrackerNavigationHelper
: public GoogleURLTrackerNavigationHelper { : public GoogleURLTrackerNavigationHelper {
public: public:
TestGoogleURLTrackerNavigationHelper(); explicit TestGoogleURLTrackerNavigationHelper(GoogleURLTracker* tracker);
virtual ~TestGoogleURLTrackerNavigationHelper(); virtual ~TestGoogleURLTrackerNavigationHelper();
virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE; virtual void SetListeningForNavigationCommit(bool listen) OVERRIDE;
virtual void SetListeningForNavigationCommit( virtual bool IsListeningForNavigationCommit() OVERRIDE;
const content::NavigationController* nav_controller, virtual void SetListeningForTabDestruction(bool listen) OVERRIDE;
bool listen) OVERRIDE; virtual bool IsListeningForTabDestruction() OVERRIDE;
virtual bool IsListeningForNavigationCommit(
const content::NavigationController* nav_controller) OVERRIDE;
virtual void SetListeningForTabDestruction(
const content::NavigationController* nav_controller,
bool listen) OVERRIDE;
virtual bool IsListeningForTabDestruction(
const content::NavigationController* nav_controller) OVERRIDE;
private: private:
GoogleURLTracker* tracker_; bool listening_for_nav_commit_;
std::set<const content::NavigationController*> bool listening_for_tab_destruction_;
nav_controller_commit_listeners_;
std::set<const content::NavigationController*>
nav_controller_tab_close_listeners_;
};
TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper() DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerNavigationHelper);
: tracker_(NULL) { };
}
TestGoogleURLTrackerNavigationHelper:: TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper(
~TestGoogleURLTrackerNavigationHelper() { GoogleURLTracker* tracker)
: GoogleURLTrackerNavigationHelper(tracker),
listening_for_nav_commit_(false),
listening_for_tab_destruction_(false) {
} }
void TestGoogleURLTrackerNavigationHelper::SetGoogleURLTracker( TestGoogleURLTrackerNavigationHelper::~TestGoogleURLTrackerNavigationHelper() {
GoogleURLTracker* tracker) {
tracker_ = tracker;
} }
void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit( void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit(
const content::NavigationController* nav_controller,
bool listen) { bool listen) {
if (listen) listening_for_nav_commit_ = listen;
nav_controller_commit_listeners_.insert(nav_controller);
else
nav_controller_commit_listeners_.erase(nav_controller);
} }
bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationCommit( bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationCommit() {
const content::NavigationController* nav_controller) { return listening_for_nav_commit_;
return nav_controller_commit_listeners_.count(nav_controller) > 0;
} }
void TestGoogleURLTrackerNavigationHelper::SetListeningForTabDestruction( void TestGoogleURLTrackerNavigationHelper::SetListeningForTabDestruction(
const content::NavigationController* nav_controller,
bool listen) { bool listen) {
if (listen) listening_for_tab_destruction_ = listen;
nav_controller_tab_close_listeners_.insert(nav_controller);
else
nav_controller_tab_close_listeners_.erase(nav_controller);
} }
bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction( bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction() {
const content::NavigationController* nav_controller) { return listening_for_tab_destruction_;
return nav_controller_tab_close_listeners_.count(nav_controller) > 0;
} }
} // namespace } // namespace
...@@ -260,6 +240,7 @@ class GoogleURLTrackerTest : public testing::Test { ...@@ -260,6 +240,7 @@ class GoogleURLTrackerTest : public testing::Test {
void CloseTab(intptr_t unique_id); void CloseTab(intptr_t unique_id);
GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id);
GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id); GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id);
GoogleURLTrackerNavigationHelper* GetNavigationHelper(intptr_t unique_id);
void ExpectDefaultURLs() const; void ExpectDefaultURLs() const;
void ExpectListeningForCommit(intptr_t unique_id, bool listening); void ExpectListeningForCommit(intptr_t unique_id, bool listening);
bool listener_notified() const { return listener_.notified(); } bool listener_notified() const { return listener_.notified(); }
...@@ -282,7 +263,6 @@ class GoogleURLTrackerTest : public testing::Test { ...@@ -282,7 +263,6 @@ class GoogleURLTrackerTest : public testing::Test {
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
net::TestURLFetcherFactory fetcher_factory_; net::TestURLFetcherFactory fetcher_factory_;
GoogleURLTrackerClient* client_; GoogleURLTrackerClient* client_;
GoogleURLTrackerNavigationHelper* nav_helper_;
TestingProfile profile_; TestingProfile profile_;
scoped_ptr<GoogleURLTracker> google_url_tracker_; scoped_ptr<GoogleURLTracker> google_url_tracker_;
TestCallbackListener listener_; TestCallbackListener listener_;
...@@ -321,17 +301,12 @@ GoogleURLTrackerTest::~GoogleURLTrackerTest() { ...@@ -321,17 +301,12 @@ GoogleURLTrackerTest::~GoogleURLTrackerTest() {
void GoogleURLTrackerTest::SetUp() { void GoogleURLTrackerTest::SetUp() {
network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
// Ownership is passed to google_url_tracker_, but weak pointers are kept; // Ownership is passed to google_url_tracker_, but a weak pointer is kept;
// this is safe since GoogleURLTracker keeps these objects for its lifetime. // this is safe since GoogleURLTracker keeps the client for its lifetime.
client_ = new TestGoogleURLTrackerClient(); client_ = new TestGoogleURLTrackerClient();
nav_helper_ = new TestGoogleURLTrackerNavigationHelper();
scoped_ptr<GoogleURLTrackerClient> client(client_); scoped_ptr<GoogleURLTrackerClient> client(client_);
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(nav_helper_); google_url_tracker_.reset(new GoogleURLTracker(
google_url_tracker_.reset( &profile_, client.Pass(), GoogleURLTracker::UNIT_TEST_MODE));
new GoogleURLTracker(&profile_,
client.Pass(),
nav_helper.Pass(),
GoogleURLTracker::UNIT_TEST_MODE));
google_url_tracker_->infobar_creator_ = base::Bind( google_url_tracker_->infobar_creator_ = base::Bind(
&GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this)); &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this));
} }
...@@ -395,8 +370,11 @@ void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id, ...@@ -395,8 +370,11 @@ void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id,
unique_ids_seen_.insert(unique_id); unique_ids_seen_.insert(unique_id);
if (client_->IsListeningForNavigationStart()) { if (client_->IsListeningForNavigationStart()) {
google_url_tracker_->OnNavigationPending( google_url_tracker_->OnNavigationPending(
reinterpret_cast<content::NavigationController*>(unique_id), scoped_ptr<GoogleURLTrackerNavigationHelper>(
reinterpret_cast<InfoBarService*>(unique_id), unique_id); new TestGoogleURLTrackerNavigationHelper(
google_url_tracker_.get())),
reinterpret_cast<InfoBarService*>(unique_id),
unique_id);
} }
} }
...@@ -422,8 +400,8 @@ void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { ...@@ -422,8 +400,8 @@ void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) {
void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id,
const GURL& search_url) { const GURL& search_url) {
DCHECK(search_url.is_valid()); DCHECK(search_url.is_valid());
if (nav_helper_->IsListeningForNavigationCommit( GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id);
reinterpret_cast<content::NavigationController*>(unique_id))) { if (nav_helper && nav_helper->IsListeningForNavigationCommit()) {
google_url_tracker_->OnNavigationCommitted( google_url_tracker_->OnNavigationCommitted(
reinterpret_cast<InfoBarService*>(unique_id), search_url); reinterpret_cast<InfoBarService*>(unique_id), search_url);
} }
...@@ -431,10 +409,9 @@ void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, ...@@ -431,10 +409,9 @@ void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id,
void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) { void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) {
unique_ids_seen_.erase(unique_id); unique_ids_seen_.erase(unique_id);
content::NavigationController* nav_controller = GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id);
reinterpret_cast<content::NavigationController*>(unique_id); if (nav_helper && nav_helper->IsListeningForTabDestruction()) {
if (nav_helper_->IsListeningForTabDestruction(nav_controller)) { google_url_tracker_->OnTabClosed(nav_helper);
google_url_tracker_->OnTabClosed(nav_controller);
} else { } else {
// Closing a tab with an infobar showing would close the infobar. // Closing a tab with an infobar showing would close the infobar.
GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id); GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id);
...@@ -457,6 +434,12 @@ GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate( ...@@ -457,6 +434,12 @@ GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate(
return map_entry ? map_entry->infobar_delegate() : NULL; return map_entry ? map_entry->infobar_delegate() : NULL;
} }
GoogleURLTrackerNavigationHelper* GoogleURLTrackerTest::GetNavigationHelper(
intptr_t unique_id) {
GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
return map_entry ? map_entry->navigation_helper() : NULL;
}
void GoogleURLTrackerTest::ExpectDefaultURLs() const { void GoogleURLTrackerTest::ExpectDefaultURLs() const {
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
EXPECT_EQ(GURL(), fetched_google_url()); EXPECT_EQ(GURL(), fetched_google_url());
...@@ -466,8 +449,8 @@ void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id, ...@@ -466,8 +449,8 @@ void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id,
bool listening) { bool listening) {
GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
if (map_entry) { if (map_entry) {
EXPECT_EQ(listening, nav_helper_->IsListeningForNavigationCommit( EXPECT_EQ(listening,
map_entry->navigation_controller())); map_entry->navigation_helper()->IsListeningForNavigationCommit());
} else { } else {
EXPECT_FALSE(listening); EXPECT_FALSE(listening);
} }
......
...@@ -696,6 +696,7 @@ ...@@ -696,6 +696,7 @@
'browser/google/google_url_tracker_infobar_delegate.h', 'browser/google/google_url_tracker_infobar_delegate.h',
'browser/google/google_url_tracker_map_entry.cc', 'browser/google/google_url_tracker_map_entry.cc',
'browser/google/google_url_tracker_map_entry.h', 'browser/google/google_url_tracker_map_entry.h',
'browser/google/google_url_tracker_navigation_helper.cc',
'browser/google/google_url_tracker_navigation_helper.h', 'browser/google/google_url_tracker_navigation_helper.h',
'browser/google/google_url_tracker_navigation_helper_impl.cc', 'browser/google/google_url_tracker_navigation_helper_impl.cc',
'browser/google/google_url_tracker_navigation_helper_impl.h', 'browser/google/google_url_tracker_navigation_helper_impl.h',
......
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