summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-09 22:31:07 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-09 22:31:07 +0000
commit624896101d464fa075a49075331dc2281c821d3b (patch)
tree72a200d60759a89db08378c04eb09f1e76b85d9b /chrome/browser/google
parent67f540544a7d469a9f9ada49e6365ac43650275f (diff)
downloadchromium_src-624896101d464fa075a49075331dc2281c821d3b.zip
chromium_src-624896101d464fa075a49075331dc2281c821d3b.tar.gz
chromium_src-624896101d464fa075a49075331dc2281c821d3b.tar.bz2
Cleanup precursor patch #3: Convert factory class into a simple function pointer, move a few more bits around, remove a portion of a test that isn't important.
BUG=54274 TEST=none Review URL: http://codereview.chromium.org/4661005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65583 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google')
-rw-r--r--chrome/browser/google/google_url_tracker.cc75
-rw-r--r--chrome/browser/google/google_url_tracker.h14
-rw-r--r--chrome/browser/google/google_url_tracker_unittest.cc37
3 files changed, 53 insertions, 73 deletions
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc
index 3925378..afd9592 100644
--- a/chrome/browser/google/google_url_tracker.cc
+++ b/chrome/browser/google/google_url_tracker.cc
@@ -35,19 +35,22 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
const GURL& new_google_url);
// ConfirmInfoBarDelegate
- virtual string16 GetMessageText() const;
- virtual int GetButtons() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
virtual bool Accept();
virtual bool Cancel();
virtual void InfoBarClosed();
- private:
+ protected:
virtual ~GoogleURLTrackerInfoBarDelegate();
GoogleURLTracker* google_url_tracker_;
const GURL new_google_url_;
+ private:
+ // ConfirmInfoBarDelegate
+ virtual string16 GetMessageText() const;
+ virtual int GetButtons() const;
+ virtual string16 GetButtonLabel(InfoBarButton button) const;
+
DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate);
};
@@ -60,23 +63,6 @@ GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate(
new_google_url_(new_google_url) {
}
-string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const {
- // TODO(ukai): change new_google_url to google_base_domain?
- return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE,
- UTF8ToUTF16(new_google_url_.spec()));
-}
-
-int GoogleURLTrackerInfoBarDelegate::GetButtons() const {
- return BUTTON_OK | BUTTON_CANCEL;
-}
-
-string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel(
- InfoBarButton button) const {
- return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
- IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL :
- IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
-}
-
bool GoogleURLTrackerInfoBarDelegate::Accept() {
google_url_tracker_->AcceptGoogleURL(new_google_url_);
google_url_tracker_->RedoSearch();
@@ -96,6 +82,32 @@ void GoogleURLTrackerInfoBarDelegate::InfoBarClosed() {
GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
}
+string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const {
+ // TODO(ukai): change new_google_url to google_base_domain?
+ return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE,
+ UTF8ToUTF16(new_google_url_.spec()));
+}
+
+int GoogleURLTrackerInfoBarDelegate::GetButtons() const {
+ return BUTTON_OK | BUTTON_CANCEL;
+}
+
+string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
+ IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL :
+ IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
+}
+
+InfoBarDelegate* CreateInfobar(TabContents* tab_contents,
+ GoogleURLTracker* google_url_tracker,
+ const GURL& new_google_url) {
+ InfoBarDelegate* infobar = new GoogleURLTrackerInfoBarDelegate(tab_contents,
+ google_url_tracker, new_google_url);
+ tab_contents->AddInfoBar(infobar);
+ return infobar;
+}
+
// GoogleURLTracker -----------------------------------------------------------
@@ -104,20 +116,9 @@ const char GoogleURLTracker::kDefaultGoogleHomepage[] =
const char GoogleURLTracker::kSearchDomainCheckURL[] =
"https://www.google.com/searchdomaincheck?format=domain&type=chrome";
-InfoBarDelegate* GoogleURLTracker::InfoBarDelegateFactory::CreateInfoBar(
- TabContents* tab_contents,
- GoogleURLTracker* google_url_tracker,
- const GURL& new_google_url) {
- InfoBarDelegate* infobar =
- new GoogleURLTrackerInfoBarDelegate(tab_contents,
- google_url_tracker,
- new_google_url);
- tab_contents->AddInfoBar(infobar);
- return infobar;
-}
-
GoogleURLTracker::GoogleURLTracker()
- : google_url_(g_browser_process->local_state()->GetString(
+ : infobar_creator_(&CreateInfobar),
+ google_url_(g_browser_process->local_state()->GetString(
prefs::kLastKnownGoogleURL)),
ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)),
fetcher_id_(0),
@@ -127,7 +128,6 @@ GoogleURLTracker::GoogleURLTracker()
request_context_available_(!!Profile::GetDefaultRequestContext()),
need_to_prompt_(false),
controller_(NULL),
- infobar_factory_(new InfoBarDelegateFactory),
infobar_(NULL) {
registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
NotificationService::AllSources());
@@ -374,9 +374,6 @@ void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary(
if (!need_to_prompt_)
return;
DCHECK(!fetched_google_url_.is_empty());
- DCHECK(infobar_factory_.get());
- infobar_ = infobar_factory_->CreateInfoBar(tab_contents,
- this,
- fetched_google_url_);
+ infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_);
}
diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h
index b00bd25..bf89a9c 100644
--- a/chrome/browser/google/google_url_tracker.h
+++ b/chrome/browser/google/google_url_tracker.h
@@ -39,14 +39,6 @@ class GoogleURLTracker : public URLFetcher::Delegate,
public NotificationObserver,
public net::NetworkChangeNotifier::Observer {
public:
- class InfoBarDelegateFactory {
- public:
- virtual ~InfoBarDelegateFactory() {}
- virtual InfoBarDelegate* CreateInfoBar(TabContents* tab_contents,
- GoogleURLTracker* google_url_tracker,
- const GURL& new_google_url);
- };
-
// Only the main browser process loop should call this, when setting up
// g_browser_process->google_url_tracker_. No code other than the
// GoogleURLTracker itself should actually use
@@ -94,6 +86,10 @@ class GoogleURLTracker : public URLFetcher::Delegate,
private:
friend class GoogleURLTrackerTest;
+ typedef InfoBarDelegate* (*InfobarCreator)(TabContents*,
+ GoogleURLTracker*,
+ const GURL&);
+
// Registers consumer interest in getting an updated URL from the server.
// It will be notified as NotificationType::GOOGLE_URL_UPDATED, so the
// consumer should observe this notification before calling this.
@@ -128,6 +124,7 @@ class GoogleURLTracker : public URLFetcher::Delegate,
void ShowGoogleURLInfoBarIfNecessary(TabContents* tab_contents);
NotificationRegistrar registrar_;
+ InfobarCreator infobar_creator_;
// TODO(ukai): GoogleURLTracker should track google domain (e.g. google.co.uk)
// rather than URL (e.g. http://www.google.co.uk/), so that user could
// configure to use https in search engine templates.
@@ -153,7 +150,6 @@ class GoogleURLTracker : public URLFetcher::Delegate,
// matched with current user's default Google URL
// nor the last prompted Google URL.
NavigationController* controller_;
- scoped_ptr<InfoBarDelegateFactory> infobar_factory_;
InfoBarDelegate* infobar_;
GURL search_url_;
diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc
index 7b8fb10..94cc193 100644
--- a/chrome/browser/google/google_url_tracker_unittest.cc
+++ b/chrome/browser/google/google_url_tracker_unittest.cc
@@ -59,11 +59,12 @@ class TestInfoBarDelegate : public InfoBarDelegate {
const GURL& new_google_url);
virtual ~TestInfoBarDelegate();
+ // InfoBarDelegate
+ virtual InfoBar* CreateInfoBar();
+
GoogleURLTracker* google_url_tracker() const { return google_url_tracker_; }
const GURL& new_google_url() const { return new_google_url_; }
- virtual InfoBar* CreateInfoBar();
-
private:
GoogleURLTracker* google_url_tracker_;
GURL new_google_url_;
@@ -83,20 +84,14 @@ InfoBar* TestInfoBarDelegate::CreateInfoBar() {
return NULL;
}
-} // namespace
-
-
-// TestInfoBarDelegateFactory -------------------------------------------------
+InfoBarDelegate* CreateTestInfobar(
+ TabContents* tab_contents,
+ GoogleURLTracker* google_url_tracker,
+ const GURL& new_google_url) {
+ return new TestInfoBarDelegate(google_url_tracker, new_google_url);
+}
-class TestInfoBarDelegateFactory
- : public GoogleURLTracker::InfoBarDelegateFactory {
- public:
- virtual InfoBarDelegate* CreateInfoBar(TabContents* tab_contents,
- GoogleURLTracker* google_url_tracker,
- const GURL& new_google_url) {
- return new TestInfoBarDelegate(google_url_tracker, new_google_url);
- }
-};
+} // namespace
// GoogleURLTrackerTest -------------------------------------------------------
@@ -167,8 +162,8 @@ void GoogleURLTrackerTest::SetUp() {
URLFetcher::set_factory(&fetcher_factory_);
observer_.reset(new TestNotificationObserver);
- g_browser_process->google_url_tracker()->infobar_factory_.reset(
- new TestInfoBarDelegateFactory);
+ g_browser_process->google_url_tracker()->infobar_creator_ =
+ &CreateTestInfobar;
}
void GoogleURLTrackerTest::TearDown() {
@@ -362,14 +357,6 @@ TEST_F(GoogleURLTrackerTest, UpdatePromptedURLWhenBack) {
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL());
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL());
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
-
- SearchCommitted(GURL("http://www.google.co.uk/search?q=test"));
- NavEntryCommitted();
-
- EXPECT_FALSE(InfoBarIsShown());
- EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
}
TEST_F(GoogleURLTrackerTest, MonitorNetworkChange) {