Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2238)

Unified Diff: chrome/browser/google/google_url_tracker.cc

Issue 283413002: Turn GoogleURLTrackerNavigationHelper(Impl) into a per-tab object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to review Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/google/google_url_tracker.cc
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc
index aa368692dcc4d086f4f2e99088e94660685b7a87..a5fc58a9eeec49a50d7de867a2faa23866b77606 100644
--- a/chrome/browser/google/google_url_tracker.cc
+++ b/chrome/browser/google/google_url_tracker.cc
@@ -33,18 +33,15 @@ const char GoogleURLTracker::kDefaultGoogleHomepage[] =
const char GoogleURLTracker::kSearchDomainCheckURL[] =
"https://www.google.com/searchdomaincheck?format=url&type=chrome";
-GoogleURLTracker::GoogleURLTracker(
- Profile* profile,
- scoped_ptr<GoogleURLTrackerClient> client,
- scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
- Mode mode)
+GoogleURLTracker::GoogleURLTracker(Profile* profile,
+ scoped_ptr<GoogleURLTrackerClient> client,
+ Mode mode)
: profile_(profile),
client_(client.Pass()),
- nav_helper_(nav_helper.Pass()),
infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)),
- google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage
- : profile->GetPrefs()->GetString(
- prefs::kLastKnownGoogleURL)),
+ google_url_(mode == UNIT_TEST_MODE ?
+ kDefaultGoogleHomepage :
+ profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)),
fetcher_id_(0),
in_startup_sleep_(true),
already_fetched_(false),
@@ -54,7 +51,6 @@ GoogleURLTracker::GoogleURLTracker(
weak_ptr_factory_(this) {
net::NetworkChangeNotifier::AddIPAddressObserver(this);
client_->set_google_url_tracker(this);
- nav_helper_->SetGoogleURLTracker(this);
// 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
@@ -207,7 +203,6 @@ void GoogleURLTracker::OnIPAddressChanged() {
void GoogleURLTracker::Shutdown() {
client_.reset();
- nav_helper_.reset();
fetcher_.reset();
weak_ptr_factory_.InvalidateWeakPtrs();
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
@@ -221,7 +216,7 @@ void GoogleURLTracker::DeleteMapEntryForService(
DCHECK(i != entry_map_.end());
GoogleURLTrackerMapEntry* map_entry = i->second;
- UnregisterForEntrySpecificNotifications(*map_entry, false);
+ UnregisterForEntrySpecificNotifications(map_entry, false);
entry_map_.erase(i);
delete map_entry;
}
@@ -283,39 +278,42 @@ void GoogleURLTracker::SearchCommitted() {
}
void GoogleURLTracker::OnNavigationPending(
- content::NavigationController* navigation_controller,
+ scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
InfoBarService* infobar_service,
int pending_id) {
+ GoogleURLTrackerMapEntry* map_entry = NULL;
+
EntryMap::iterator i(entry_map_.find(infobar_service));
+ if (i != entry_map_.end())
+ map_entry = i->second;
if (search_committed_) {
search_committed_ = false;
- // 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 (!nav_helper_->IsListeningForNavigationCommit(navigation_controller)) {
- nav_helper_->SetListeningForNavigationCommit(navigation_controller,
- true);
- }
- if (i == entry_map_.end()) {
+ if (!map_entry) {
// 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
// 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
// infobar and the infobar's owner will handle tearing it down when the
// tab is destroyed.
- nav_helper_->SetListeningForTabDestruction(navigation_controller, true);
- entry_map_.insert(std::make_pair(
- infobar_service,
- new GoogleURLTrackerMapEntry(this, infobar_service,
- navigation_controller)));
- } else if (i->second->has_infobar_delegate()) {
+ map_entry = new GoogleURLTrackerMapEntry(
+ this, infobar_service, nav_helper.Pass());
+ map_entry->navigation_helper()->SetListeningForTabDestruction(true);
+ entry_map_.insert(std::make_pair(infobar_service, map_entry));
+ } else if (map_entry->infobar_delegate()) {
// 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()) {
Peter Kasting 2014/05/16 23:38:13 Nit: No {}
blundell 2014/05/17 19:23:54 Done.
+ 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
// 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
@@ -325,13 +323,13 @@ void GoogleURLTracker::OnNavigationPending(
// 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
// simply leaving the infobar as-is will have been the right thing.
- UnregisterForEntrySpecificNotifications(*i->second, false);
- i->second->infobar_delegate()->set_pending_id(0);
+ UnregisterForEntrySpecificNotifications(map_entry, false);
+ map_entry->infobar_delegate()->set_pending_id(0);
} else {
// 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
// entry.
- i->second->Close(false);
+ map_entry->Close(false);
}
} else {
// Non-search navigation on a tab without an infobars. This is irrelevant
@@ -346,7 +344,7 @@ void GoogleURLTracker::OnNavigationCommitted(InfoBarService* infobar_service,
GoogleURLTrackerMapEntry* map_entry = i->second;
DCHECK(search_url.is_valid());
- UnregisterForEntrySpecificNotifications(*map_entry, true);
+ UnregisterForEntrySpecificNotifications(map_entry, true);
if (map_entry->has_infobar_delegate()) {
map_entry->infobar_delegate()->Update(search_url);
} else {
@@ -362,7 +360,7 @@ void GoogleURLTracker::OnNavigationCommitted(InfoBarService* infobar_service,
}
void GoogleURLTracker::OnTabClosed(
- content::NavigationController* navigation_controller) {
+ GoogleURLTrackerNavigationHelper* nav_helper) {
// Because InfoBarService tears itself down on tab destruction, it's possible
// to get a non-NULL InfoBarService pointer here, depending on which order
// notifications fired in. Likewise, the pointer in |entry_map_| (and in its
@@ -372,7 +370,7 @@ void GoogleURLTracker::OnTabClosed(
// function doesn't need to do even that, but others in the call chain from
// here might (and have comments pointing back here).
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);
return;
}
@@ -387,26 +385,22 @@ void GoogleURLTracker::CloseAllEntries(bool redo_searches) {
}
void GoogleURLTracker::UnregisterForEntrySpecificNotifications(
- const GoogleURLTrackerMapEntry& map_entry,
+ GoogleURLTrackerMapEntry* map_entry,
bool must_be_listening_for_commit) {
// 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 navigation commits if the user has performed a new search on this tab.
- if (nav_helper_->IsListeningForNavigationCommit(
- map_entry.navigation_controller())) {
- nav_helper_->SetListeningForNavigationCommit(
- map_entry.navigation_controller(), false);
+ if (map_entry->navigation_helper()->IsListeningForNavigationCommit()) {
+ map_entry->navigation_helper()->SetListeningForNavigationCommit(false);
} else {
DCHECK(!must_be_listening_for_commit);
- DCHECK(map_entry.has_infobar_delegate());
+ DCHECK(map_entry->has_infobar_delegate());
}
const bool registered_for_tab_destruction =
- nav_helper_->IsListeningForTabDestruction(
- map_entry.navigation_controller());
- DCHECK_NE(registered_for_tab_destruction, map_entry.has_infobar_delegate());
+ map_entry->navigation_helper()->IsListeningForTabDestruction();
+ DCHECK_NE(registered_for_tab_destruction, map_entry->has_infobar_delegate());
if (registered_for_tab_destruction) {
- nav_helper_->SetListeningForTabDestruction(
- map_entry.navigation_controller(), false);
+ map_entry->navigation_helper()->SetListeningForTabDestruction(false);
}
// Our global listeners for these other notifications should be in place iff
@@ -416,8 +410,7 @@ void GoogleURLTracker::UnregisterForEntrySpecificNotifications(
// See the various cases inside OnNavigationPending().
for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end();
++i) {
- if (nav_helper_->IsListeningForNavigationCommit(
- i->second->navigation_controller())) {
+ if (i->second->navigation_helper()->IsListeningForNavigationCommit()) {
DCHECK(client_->IsListeningForNavigationStart());
return;
}

Powered by Google App Engine
This is Rietveld 408576698