Commit 6047f192 authored by blundell@chromium.org's avatar blundell@chromium.org

Create GoogleURLTrackerClient interface and //chrome implementation

GoogleURLTrackerClient is the interface via which GoogleURLTracker will talk to
its embedder. This CL creates that interface as well as
ChromeGoogleURLTrackerClient, the //chrome implementation. The interface and
implementation are carved out of GoogleURLTrackerNavigationTracker(Impl),
specifically the parts that are not per-tab. A followup CL will modify
GoogleURLTrackerNavigationTracker to the driver interface for
GoogleURLTracker.

BUG=373220

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271638 0039d316-1c4b-4281-b951-d872f2087c98
parent 61b0d48b
// 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/chrome_google_url_tracker_client.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
ChromeGoogleURLTrackerClient::ChromeGoogleURLTrackerClient() {
}
ChromeGoogleURLTrackerClient::~ChromeGoogleURLTrackerClient() {
}
void ChromeGoogleURLTrackerClient::SetListeningForNavigationStart(bool listen) {
if (listen) {
registrar_.Add(
this,
content::NOTIFICATION_NAV_ENTRY_PENDING,
content::NotificationService::AllBrowserContextsAndSources());
} else {
registrar_.Remove(
this,
content::NOTIFICATION_NAV_ENTRY_PENDING,
content::NotificationService::AllBrowserContextsAndSources());
}
}
bool ChromeGoogleURLTrackerClient::IsListeningForNavigationStart() {
return registrar_.IsRegistered(
this,
content::NOTIFICATION_NAV_ENTRY_PENDING,
content::NotificationService::AllBrowserContextsAndSources());
}
void ChromeGoogleURLTrackerClient::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_PENDING, type);
content::NavigationController* controller =
content::Source<content::NavigationController>(source).ptr();
InfoBarService* infobar_service =
InfoBarService::FromWebContents(controller->GetWebContents());
// Because we're listening to all sources, there may be no
// InfoBarService for some notifications, e.g. navigations in
// bubbles/balloons etc.
if (infobar_service) {
google_url_tracker()->OnNavigationPending(
controller,
infobar_service,
controller->GetPendingEntry()->GetUniqueID());
}
}
// 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.
#ifndef CHROME_BROWSER_GOOGLE_CHROME_GOOGLE_URL_TRACKER_CLIENT_H_
#define CHROME_BROWSER_GOOGLE_CHROME_GOOGLE_URL_TRACKER_CLIENT_H_
#include "components/google/core/browser/google_url_tracker_client.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class ChromeGoogleURLTrackerClient : public GoogleURLTrackerClient,
public content::NotificationObserver {
public:
ChromeGoogleURLTrackerClient();
virtual ~ChromeGoogleURLTrackerClient();
// GoogleURLTrackerClient:
virtual void SetListeningForNavigationStart(bool listen) OVERRIDE;
virtual bool IsListeningForNavigationStart() OVERRIDE;
private:
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(ChromeGoogleURLTrackerClient);
};
#endif // CHROME_BROWSER_GOOGLE_CHROME_GOOGLE_URL_TRACKER_CLIENT_H_
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/google/core/browser/google_url_tracker_client.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.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"
...@@ -34,12 +35,15 @@ const char GoogleURLTracker::kSearchDomainCheckURL[] = ...@@ -34,12 +35,15 @@ const char GoogleURLTracker::kSearchDomainCheckURL[] =
GoogleURLTracker::GoogleURLTracker( GoogleURLTracker::GoogleURLTracker(
Profile* profile, Profile* profile,
scoped_ptr<GoogleURLTrackerClient> client,
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
Mode mode) Mode mode)
: profile_(profile), : profile_(profile),
client_(client.Pass()),
nav_helper_(nav_helper.Pass()), nav_helper_(nav_helper.Pass()),
infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)), infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)),
google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage : google_url_(mode == UNIT_TEST_MODE ?
kDefaultGoogleHomepage :
profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)),
fetcher_id_(0), fetcher_id_(0),
in_startup_sleep_(true), in_startup_sleep_(true),
...@@ -49,6 +53,7 @@ GoogleURLTracker::GoogleURLTracker( ...@@ -49,6 +53,7 @@ GoogleURLTracker::GoogleURLTracker(
search_committed_(false), search_committed_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
net::NetworkChangeNotifier::AddIPAddressObserver(this); net::NetworkChangeNotifier::AddIPAddressObserver(this);
client_->set_google_url_tracker(this);
nav_helper_->SetGoogleURLTracker(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
...@@ -199,6 +204,7 @@ void GoogleURLTracker::OnIPAddressChanged() { ...@@ -199,6 +204,7 @@ void GoogleURLTracker::OnIPAddressChanged() {
} }
void GoogleURLTracker::Shutdown() { void GoogleURLTracker::Shutdown() {
client_.reset();
nav_helper_.reset(); nav_helper_.reset();
fetcher_.reset(); fetcher_.reset();
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
...@@ -269,8 +275,8 @@ void GoogleURLTracker::SearchCommitted() { ...@@ -269,8 +275,8 @@ void GoogleURLTracker::SearchCommitted() {
search_committed_ = true; search_committed_ = true;
// These notifications will fire a bit later in the same call chain we're // These notifications will fire a bit later in the same call chain we're
// currently in. // currently in.
if (!nav_helper_->IsListeningForNavigationStart()) if (!client_->IsListeningForNavigationStart())
nav_helper_->SetListeningForNavigationStart(true); client_->SetListeningForNavigationStart(true);
} }
} }
...@@ -415,13 +421,13 @@ void GoogleURLTracker::UnregisterForEntrySpecificNotifications( ...@@ -415,13 +421,13 @@ void GoogleURLTracker::UnregisterForEntrySpecificNotifications(
++i) { ++i) {
if (nav_helper_->IsListeningForNavigationCommit( if (nav_helper_->IsListeningForNavigationCommit(
i->second->navigation_controller())) { i->second->navigation_controller())) {
DCHECK(nav_helper_->IsListeningForNavigationStart()); DCHECK(client_->IsListeningForNavigationStart());
return; return;
} }
} }
if (nav_helper_->IsListeningForNavigationStart()) { if (client_->IsListeningForNavigationStart()) {
DCHECK(!search_committed_); DCHECK(!search_committed_);
nav_helper_->SetListeningForNavigationStart(false); client_->SetListeningForNavigationStart(false);
} }
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_fetcher_delegate.h"
#include "url/gurl.h" #include "url/gurl.h"
class GoogleURLTrackerClient;
class GoogleURLTrackerNavigationHelper; class GoogleURLTrackerNavigationHelper;
class PrefService; class PrefService;
class Profile; class Profile;
...@@ -70,6 +71,7 @@ class GoogleURLTracker : public net::URLFetcherDelegate, ...@@ -70,6 +71,7 @@ class GoogleURLTracker : public net::URLFetcherDelegate,
// than the GoogleURLTracker itself should actually use // than the GoogleURLTracker itself should actually use
// GoogleURLTrackerFactory::GetForProfile(). // GoogleURLTrackerFactory::GetForProfile().
GoogleURLTracker(Profile* profile, GoogleURLTracker(Profile* profile,
scoped_ptr<GoogleURLTrackerClient> client,
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
Mode mode); Mode mode);
...@@ -109,12 +111,12 @@ class GoogleURLTracker : public net::URLFetcherDelegate, ...@@ -109,12 +111,12 @@ class GoogleURLTracker : public net::URLFetcherDelegate,
// No one but GoogleURLTrackerMapEntry should call this. // No one but GoogleURLTrackerMapEntry should call this.
void DeleteMapEntryForService(const InfoBarService* infobar_service); void DeleteMapEntryForService(const InfoBarService* infobar_service);
// Called by the navigation observer after SearchCommitted() registers // Called by the client after SearchCommitted() registers listeners, to
// listeners, to indicate that we've received the "load now pending" // indicate that we've received the "load now pending" notification.
// notification. |navigation_controller| is the NavigationController for this // |navigation_controller| is the NavigationController for this load;
// load; |infobar_service| is the InfoBarService of the associated tab; and // |infobar_service| is the InfoBarService of the associated tab; and
// |pending_id| is the unique ID of the newly pending NavigationEntry. // |pending_id| is the unique ID of the newly pending NavigationEntry. If
// If there is already a visible GoogleURLTracker infobar for this tab, this // 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(
...@@ -188,6 +190,8 @@ class GoogleURLTracker : public net::URLFetcherDelegate, ...@@ -188,6 +190,8 @@ class GoogleURLTracker : public net::URLFetcherDelegate,
Profile* profile_; Profile* profile_;
scoped_ptr<GoogleURLTrackerClient> client_;
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_; 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
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/google/google_url_tracker_factory.h" #include "chrome/browser/google/google_url_tracker_factory.h"
#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/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/google/google_url_tracker_navigation_helper_impl.h"
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
...@@ -36,9 +37,12 @@ GoogleURLTrackerFactory::~GoogleURLTrackerFactory() { ...@@ -36,9 +37,12 @@ GoogleURLTrackerFactory::~GoogleURLTrackerFactory() {
KeyedService* GoogleURLTrackerFactory::BuildServiceInstanceFor( KeyedService* GoogleURLTrackerFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const { content::BrowserContext* profile) const {
scoped_ptr<GoogleURLTrackerClient> client(new ChromeGoogleURLTrackerClient());
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper( scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(
new GoogleURLTrackerNavigationHelperImpl()); new GoogleURLTrackerNavigationHelperImpl());
return new GoogleURLTracker(static_cast<Profile*>(profile), nav_helper.Pass(), return new GoogleURLTracker(static_cast<Profile*>(profile),
client.Pass(),
nav_helper.Pass(),
GoogleURLTracker::NORMAL_MODE); GoogleURLTracker::NORMAL_MODE);
} }
......
...@@ -19,17 +19,9 @@ class GoogleURLTrackerNavigationHelper { ...@@ -19,17 +19,9 @@ class GoogleURLTrackerNavigationHelper {
public: public:
virtual ~GoogleURLTrackerNavigationHelper() {} virtual ~GoogleURLTrackerNavigationHelper() {}
// Sets the GoogleURLTracker that should receive callbacks from this observer. // Sets the GoogleURLTracker that is associated with this object.
virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) = 0; virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) = 0;
// Enables or disables listening for navigation starts. OnNavigationPending
// will be called for each navigation start if listening is enabled.
virtual void SetListeningForNavigationStart(bool listen) = 0;
// Returns whether or not the observer is currently listening for navigation
// starts.
virtual bool IsListeningForNavigationStart() = 0;
// Enables or disables listening for navigation commits for the given // Enables or disables listening for navigation commits for the given
// NavigationController. OnNavigationCommitted will be called for each // NavigationController. OnNavigationCommitted will be called for each
// navigation commit if listening is enabled. // navigation commit if listening is enabled.
......
...@@ -26,22 +26,6 @@ void GoogleURLTrackerNavigationHelperImpl::SetGoogleURLTracker( ...@@ -26,22 +26,6 @@ void GoogleURLTrackerNavigationHelperImpl::SetGoogleURLTracker(
tracker_ = tracker; tracker_ = tracker;
} }
void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationStart(
bool listen) {
if (listen) {
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
content::NotificationService::AllBrowserContextsAndSources());
} else {
registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
content::NotificationService::AllBrowserContextsAndSources());
}
}
bool GoogleURLTrackerNavigationHelperImpl::IsListeningForNavigationStart() {
return registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
content::NotificationService::AllBrowserContextsAndSources());
}
void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit( void GoogleURLTrackerNavigationHelperImpl::SetListeningForNavigationCommit(
const content::NavigationController* nav_controller, const content::NavigationController* nav_controller,
bool listen) { bool listen) {
...@@ -104,23 +88,6 @@ void GoogleURLTrackerNavigationHelperImpl::Observe( ...@@ -104,23 +88,6 @@ void GoogleURLTrackerNavigationHelperImpl::Observe(
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
switch (type) { switch (type) {
case content::NOTIFICATION_NAV_ENTRY_PENDING: {
content::NavigationController* controller =
content::Source<content::NavigationController>(source).ptr();
content::WebContents* web_contents = controller->GetWebContents();
InfoBarService* infobar_service =
InfoBarService::FromWebContents(web_contents);
// Because we're listening to all sources, there may be no
// InfoBarService for some notifications, e.g. navigations in
// bubbles/balloons etc.
if (infobar_service) {
tracker_->OnNavigationPending(
controller, infobar_service,
controller->GetPendingEntry()->GetUniqueID());
}
break;
}
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();
......
...@@ -19,8 +19,6 @@ class GoogleURLTrackerNavigationHelperImpl ...@@ -19,8 +19,6 @@ class GoogleURLTrackerNavigationHelperImpl
// GoogleURLTrackerNavigationHelper. // GoogleURLTrackerNavigationHelper.
virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE; virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE;
virtual void SetListeningForNavigationStart(bool listen) OVERRIDE;
virtual bool IsListeningForNavigationStart() OVERRIDE;
virtual void SetListeningForNavigationCommit( virtual void SetListeningForNavigationCommit(
const content::NavigationController* nav_controller, const content::NavigationController* nav_controller,
bool listen) OVERRIDE; bool listen) OVERRIDE;
...@@ -33,8 +31,6 @@ class GoogleURLTrackerNavigationHelperImpl ...@@ -33,8 +31,6 @@ class GoogleURLTrackerNavigationHelperImpl
const content::NavigationController* nav_controller) OVERRIDE; const content::NavigationController* nav_controller) OVERRIDE;
private: private:
friend class GoogleURLTrackerNavigationHelperTest;
// content::NotificationObserver: // content::NotificationObserver:
virtual void Observe(int type, virtual void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/google/google_url_tracker_navigation_helper.h" #include "chrome/browser/google/google_url_tracker_navigation_helper.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/google/core/browser/google_url_tracker_client.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include "components/infobars/core/infobar_delegate.h" #include "components/infobars/core/infobar_delegate.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -104,7 +105,39 @@ void TestCallbackListener::RegisterCallback( ...@@ -104,7 +105,39 @@ void TestCallbackListener::RegisterCallback(
&TestCallbackListener::OnGoogleURLUpdated, base::Unretained(this))); &TestCallbackListener::OnGoogleURLUpdated, base::Unretained(this)));
} }
// TestGoogleURLTrackerNavigationHelper -------------------------------------
// TestGoogleURLTrackerClient -------------------------------------------------
class TestGoogleURLTrackerClient : public GoogleURLTrackerClient {
public:
TestGoogleURLTrackerClient();
virtual ~TestGoogleURLTrackerClient();
virtual void SetListeningForNavigationStart(bool listen) OVERRIDE;
virtual bool IsListeningForNavigationStart() OVERRIDE;
private:
bool observe_nav_start_;
DISALLOW_COPY_AND_ASSIGN(TestGoogleURLTrackerClient);
};
TestGoogleURLTrackerClient::TestGoogleURLTrackerClient()
: observe_nav_start_(false) {
}
TestGoogleURLTrackerClient::~TestGoogleURLTrackerClient() {
}
void TestGoogleURLTrackerClient::SetListeningForNavigationStart(bool listen) {
observe_nav_start_ = listen;
}
bool TestGoogleURLTrackerClient::IsListeningForNavigationStart() {
return observe_nav_start_;
}
// TestGoogleURLTrackerNavigationHelper ---------------------------------------
class TestGoogleURLTrackerNavigationHelper class TestGoogleURLTrackerNavigationHelper
: public GoogleURLTrackerNavigationHelper { : public GoogleURLTrackerNavigationHelper {
...@@ -113,8 +146,6 @@ class TestGoogleURLTrackerNavigationHelper ...@@ -113,8 +146,6 @@ class TestGoogleURLTrackerNavigationHelper
virtual ~TestGoogleURLTrackerNavigationHelper(); virtual ~TestGoogleURLTrackerNavigationHelper();
virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE; virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE;
virtual void SetListeningForNavigationStart(bool listen) OVERRIDE;
virtual bool IsListeningForNavigationStart() OVERRIDE;
virtual void SetListeningForNavigationCommit( virtual void SetListeningForNavigationCommit(
const content::NavigationController* nav_controller, const content::NavigationController* nav_controller,
bool listen) OVERRIDE; bool listen) OVERRIDE;
...@@ -128,7 +159,6 @@ class TestGoogleURLTrackerNavigationHelper ...@@ -128,7 +159,6 @@ class TestGoogleURLTrackerNavigationHelper
private: private:
GoogleURLTracker* tracker_; GoogleURLTracker* tracker_;
bool observe_nav_start_;
std::set<const content::NavigationController*> std::set<const content::NavigationController*>
nav_controller_commit_listeners_; nav_controller_commit_listeners_;
std::set<const content::NavigationController*> std::set<const content::NavigationController*>
...@@ -136,8 +166,7 @@ class TestGoogleURLTrackerNavigationHelper ...@@ -136,8 +166,7 @@ class TestGoogleURLTrackerNavigationHelper
}; };
TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper() TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper()
: tracker_(NULL), : tracker_(NULL) {
observe_nav_start_(false) {
} }
TestGoogleURLTrackerNavigationHelper:: TestGoogleURLTrackerNavigationHelper::
...@@ -149,15 +178,6 @@ void TestGoogleURLTrackerNavigationHelper::SetGoogleURLTracker( ...@@ -149,15 +178,6 @@ void TestGoogleURLTrackerNavigationHelper::SetGoogleURLTracker(
tracker_ = tracker; tracker_ = tracker;
} }
void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationStart(
bool listen) {
observe_nav_start_ = listen;
}
bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationStart() {
return observe_nav_start_;
}
void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit( void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit(
const content::NavigationController* nav_controller, const content::NavigationController* nav_controller,
bool listen) { bool listen) {
...@@ -261,6 +281,7 @@ class GoogleURLTrackerTest : public testing::Test { ...@@ -261,6 +281,7 @@ class GoogleURLTrackerTest : public testing::Test {
// net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests().
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
net::TestURLFetcherFactory fetcher_factory_; net::TestURLFetcherFactory fetcher_factory_;
GoogleURLTrackerClient* client_;
GoogleURLTrackerNavigationHelper* nav_helper_; GoogleURLTrackerNavigationHelper* nav_helper_;
TestingProfile profile_; TestingProfile profile_;
scoped_ptr<GoogleURLTracker> google_url_tracker_; scoped_ptr<GoogleURLTracker> google_url_tracker_;
...@@ -300,12 +321,16 @@ GoogleURLTrackerTest::~GoogleURLTrackerTest() { ...@@ -300,12 +321,16 @@ 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 a weak pointer is kept; // Ownership is passed to google_url_tracker_, but weak pointers are kept;
// this is safe since GoogleURLTracker keeps the observer for its lifetime. // this is safe since GoogleURLTracker keeps these objects for its lifetime.
client_ = new TestGoogleURLTrackerClient();
nav_helper_ = new TestGoogleURLTrackerNavigationHelper(); nav_helper_ = new TestGoogleURLTrackerNavigationHelper();
scoped_ptr<GoogleURLTrackerClient> client(client_);
scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(nav_helper_); scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(nav_helper_);
google_url_tracker_.reset( google_url_tracker_.reset(
new GoogleURLTracker(&profile_, nav_helper.Pass(), new GoogleURLTracker(&profile_,
client.Pass(),
nav_helper.Pass(),
GoogleURLTracker::UNIT_TEST_MODE)); 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));
...@@ -314,9 +339,6 @@ void GoogleURLTrackerTest::SetUp() { ...@@ -314,9 +339,6 @@ void GoogleURLTrackerTest::SetUp() {
void GoogleURLTrackerTest::TearDown() { void GoogleURLTrackerTest::TearDown() {
while (!unique_ids_seen_.empty()) while (!unique_ids_seen_.empty())
CloseTab(*unique_ids_seen_.begin()); CloseTab(*unique_ids_seen_.begin());
nav_helper_ = NULL;
network_change_notifier_.reset();
} }
net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() {
...@@ -371,7 +393,7 @@ void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id, ...@@ -371,7 +393,7 @@ void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id,
// for navigation starts if the searchdomaincheck response was bogus. // for navigation starts if the searchdomaincheck response was bogus.
} }
unique_ids_seen_.insert(unique_id); unique_ids_seen_.insert(unique_id);
if (nav_helper_->IsListeningForNavigationStart()) { if (client_->IsListeningForNavigationStart()) {
google_url_tracker_->OnNavigationPending( google_url_tracker_->OnNavigationPending(
reinterpret_cast<content::NavigationController*>(unique_id), reinterpret_cast<content::NavigationController*>(unique_id),
reinterpret_cast<InfoBarService*>(unique_id), unique_id); reinterpret_cast<InfoBarService*>(unique_id), unique_id);
......
...@@ -681,6 +681,8 @@ ...@@ -681,6 +681,8 @@
'browser/geolocation/geolocation_prefs.h', 'browser/geolocation/geolocation_prefs.h',
'browser/global_keyboard_shortcuts_mac.h', 'browser/global_keyboard_shortcuts_mac.h',
'browser/global_keyboard_shortcuts_mac.mm', 'browser/global_keyboard_shortcuts_mac.mm',
'browser/google/chrome_google_url_tracker_client.cc',
'browser/google/chrome_google_url_tracker_client.h',
'browser/google/google_search_counter.cc', 'browser/google/google_search_counter.cc',
'browser/google/google_search_counter.h', 'browser/google/google_search_counter.h',
'browser/google/google_update_settings_posix.cc', 'browser/google/google_update_settings_posix.cc',
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
'sources': [ 'sources': [
'google/core/browser/google_search_metrics.cc', 'google/core/browser/google_search_metrics.cc',
'google/core/browser/google_search_metrics.h', 'google/core/browser/google_search_metrics.h',
'google/core/browser/google_url_tracker_client.cc',
'google/core/browser/google_url_tracker_client.h',
], ],
}, },
], ],
......
// 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 "components/google/core/browser/google_url_tracker_client.h"
GoogleURLTrackerClient::GoogleURLTrackerClient() : google_url_tracker_(NULL) {
}
GoogleURLTrackerClient::~GoogleURLTrackerClient() {
}
// 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.
#ifndef COMPONENTS_GOOGLE_GOOGLE_URL_TRACKER_CLIENT_H_
#define COMPONENTS_GOOGLE_GOOGLE_URL_TRACKER_CLIENT_H_
#include "base/macros.h"
class GoogleURLTracker;
// Interface by which GoogleURLTracker communicates with its embedder.
class GoogleURLTrackerClient {
public:
GoogleURLTrackerClient();
virtual ~GoogleURLTrackerClient();
// Sets the GoogleURLTracker that is associated with this client.
void set_google_url_tracker(GoogleURLTracker* google_url_tracker) {
google_url_tracker_ = google_url_tracker;
}
// Enables or disables listening for navigation starts. OnNavigationPending
// will be called for each navigation start if listening is enabled.
virtual void SetListeningForNavigationStart(bool listen) = 0;
// Returns whether or not the client is currently listening for navigation
// starts.
virtual bool IsListeningForNavigationStart() = 0;
protected:
GoogleURLTracker* google_url_tracker() { return google_url_tracker_; }
private:
GoogleURLTracker* google_url_tracker_;
DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerClient);
};
#endif // COMPONENTS_GOOGLE_GOOGLE_URL_TRACKER_CLIENT_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