summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate
diff options
context:
space:
mode:
authordanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 13:47:59 +0000
committerdanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 13:47:59 +0000
commit2510323ec78d771c9258fa95d8f98b5d18f3efaa (patch)
tree2bbb6a5c3ebba6adf5f01982c75ba52275aadcc4 /chrome/browser/translate
parent37d5293518a8657af4d79035f7ef2e8c3a8d6b9a (diff)
downloadchromium_src-2510323ec78d771c9258fa95d8f98b5d18f3efaa.zip
chromium_src-2510323ec78d771c9258fa95d8f98b5d18f3efaa.tar.gz
chromium_src-2510323ec78d771c9258fa95d8f98b5d18f3efaa.tar.bz2
Revert 60169 - Use PrefChangeRegistrar everywhere
BUG=54955 TEST=PrefChangeRegistrarTest.* Review URL: http://codereview.chromium.org/3304015 TBR=danno@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60170 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/translate')
-rw-r--r--chrome/browser/translate/translate_manager.cc6
-rw-r--r--chrome/browser/translate/translate_manager.h2
-rw-r--r--chrome/browser/translate/translate_manager_unittest.cc25
3 files changed, 14 insertions, 19 deletions
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index 336eb2a..1ea9fad 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -248,7 +248,7 @@ void TranslateManager::Observe(NotificationType type,
// We should know about this profile since we are listening for
// notifications on it.
DCHECK(count > 0);
- pref_change_registrar_.Remove(prefs::kAcceptLanguages, this);
+ profile->GetPrefs()->RemovePrefObserver(prefs::kAcceptLanguages, this);
break;
}
case NotificationType::PREF_CHANGED: {
@@ -341,8 +341,6 @@ void TranslateManager::InitiateTranslation(TabContents* tab,
if (!prefs->GetBoolean(prefs::kEnableTranslate))
return;
- pref_change_registrar_.Init(prefs);
-
// Allow disabling of translate from the command line to assist with
// automated browser testing.
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableTranslate))
@@ -535,7 +533,7 @@ bool TranslateManager::IsAcceptLanguage(TabContents* tab,
notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
Source<Profile>(tab->profile()));
// Also start listening for changes in the accept languages.
- pref_change_registrar_.Add(prefs::kAcceptLanguages, this);
+ tab->profile()->GetPrefs()->AddPrefObserver(prefs::kAcceptLanguages, this);
iter = accept_languages_.find(pref_service);
}
diff --git a/chrome/browser/translate/translate_manager.h b/chrome/browser/translate/translate_manager.h
index 3ddcabf..adec281 100644
--- a/chrome/browser/translate/translate_manager.h
+++ b/chrome/browser/translate/translate_manager.h
@@ -14,7 +14,6 @@
#include "base/lazy_instance.h"
#include "base/singleton.h"
#include "base/task.h"
-#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/common/net/url_fetcher.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
@@ -154,7 +153,6 @@ class TranslateManager : public NotificationObserver,
TabContents* tab);
NotificationRegistrar notification_registrar_;
- PrefChangeRegistrar pref_change_registrar_;
// A map that associates a profile with its parsed "accept languages".
typedef std::set<std::string> LanguageSet;
diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc
index f578b3f..8f2b801 100644
--- a/chrome/browser/translate/translate_manager_unittest.cc
+++ b/chrome/browser/translate/translate_manager_unittest.cc
@@ -7,7 +7,6 @@
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/browser/renderer_host/mock_render_process_host.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/render_view_context_menu.h"
@@ -852,10 +851,8 @@ TEST_F(TranslateManagerTest, NeverTranslateLanguagePref) {
// Select never translate this language.
PrefService* prefs = contents()->profile()->GetPrefs();
- PrefChangeRegistrar registrar;
- registrar.Init(prefs);
- registrar.Add(TranslatePrefs::kPrefTranslateLanguageBlacklist,
- &pref_observer_);
+ prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateLanguageBlacklist,
+ &pref_observer_);
TranslatePrefs translate_prefs(prefs);
EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr"));
EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
@@ -884,6 +881,8 @@ TEST_F(TranslateManagerTest, NeverTranslateLanguagePref) {
// There should be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
+ prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateLanguageBlacklist,
+ &pref_observer_);
}
// Tests the "Never translate this site" pref.
@@ -898,10 +897,8 @@ TEST_F(TranslateManagerTest, NeverTranslateSitePref) {
// Select never translate this site.
PrefService* prefs = contents()->profile()->GetPrefs();
- PrefChangeRegistrar registrar;
- registrar.Init(prefs);
- registrar.Add(TranslatePrefs::kPrefTranslateSiteBlacklist,
- &pref_observer_);
+ prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateSiteBlacklist,
+ &pref_observer_);
TranslatePrefs translate_prefs(prefs);
EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(host));
EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
@@ -930,16 +927,16 @@ TEST_F(TranslateManagerTest, NeverTranslateSitePref) {
// There should be a translate infobar.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
+ prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateSiteBlacklist,
+ &pref_observer_);
}
// Tests the "Always translate this language" pref.
TEST_F(TranslateManagerTest, AlwaysTranslateLanguagePref) {
// Select always translate French to English.
PrefService* prefs = contents()->profile()->GetPrefs();
- PrefChangeRegistrar registrar;
- registrar.Init(prefs);
- registrar.Add(TranslatePrefs::kPrefTranslateWhitelists,
- &pref_observer_);
+ prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateWhitelists,
+ &pref_observer_);
TranslatePrefs translate_prefs(prefs);
SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists);
translate_prefs.WhitelistLanguagePair("fr", "en");
@@ -988,6 +985,8 @@ TEST_F(TranslateManagerTest, AlwaysTranslateLanguagePref) {
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type());
+ prefs->RemovePrefObserver(TranslatePrefs::kPrefTranslateWhitelists,
+ &pref_observer_);
}
// Context menu.