summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate
diff options
context:
space:
mode:
authordanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-29 12:24:28 +0000
committerdanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-29 12:24:28 +0000
commit2fb7dc983456e980d631501f4a120eb091d197e7 (patch)
treefa96aef59bf1900f56ae1b0457c4f9d36e0fb38e /chrome/browser/translate
parent0ce04e5a148136f3849e8a8b0dd351a0fc4798b5 (diff)
downloadchromium_src-2fb7dc983456e980d631501f4a120eb091d197e7.zip
chromium_src-2fb7dc983456e980d631501f4a120eb091d197e7.tar.gz
chromium_src-2fb7dc983456e980d631501f4a120eb091d197e7.tar.bz2
Use PrefChangeRegistrar everywhere
BUG=54955 TEST=PrefChangeRegistrarTest.* Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=60169 Review URL: http://codereview.chromium.org/3304015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60935 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, 19 insertions, 14 deletions
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index 6f649fd..1c70dd4 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -249,7 +249,7 @@ void TranslateManager::Observe(NotificationType type,
// We should know about this profile since we are listening for
// notifications on it.
DCHECK(count > 0);
- profile->GetPrefs()->RemovePrefObserver(prefs::kAcceptLanguages, this);
+ pref_change_registrar_.Remove(prefs::kAcceptLanguages, this);
break;
}
case NotificationType::PREF_CHANGED: {
@@ -342,6 +342,8 @@ 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))
@@ -534,7 +536,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.
- tab->profile()->GetPrefs()->AddPrefObserver(prefs::kAcceptLanguages, this);
+ pref_change_registrar_.Add(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 adec281..3ddcabf 100644
--- a/chrome/browser/translate/translate_manager.h
+++ b/chrome/browser/translate/translate_manager.h
@@ -14,6 +14,7 @@
#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"
@@ -153,6 +154,7 @@ 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 8f2b801..f578b3f 100644
--- a/chrome/browser/translate/translate_manager_unittest.cc
+++ b/chrome/browser/translate/translate_manager_unittest.cc
@@ -7,6 +7,7 @@
#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"
@@ -851,8 +852,10 @@ TEST_F(TranslateManagerTest, NeverTranslateLanguagePref) {
// Select never translate this language.
PrefService* prefs = contents()->profile()->GetPrefs();
- prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateLanguageBlacklist,
- &pref_observer_);
+ PrefChangeRegistrar registrar;
+ registrar.Init(prefs);
+ registrar.Add(TranslatePrefs::kPrefTranslateLanguageBlacklist,
+ &pref_observer_);
TranslatePrefs translate_prefs(prefs);
EXPECT_FALSE(translate_prefs.IsLanguageBlacklisted("fr"));
EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
@@ -881,8 +884,6 @@ 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.
@@ -897,8 +898,10 @@ TEST_F(TranslateManagerTest, NeverTranslateSitePref) {
// Select never translate this site.
PrefService* prefs = contents()->profile()->GetPrefs();
- prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateSiteBlacklist,
- &pref_observer_);
+ PrefChangeRegistrar registrar;
+ registrar.Init(prefs);
+ registrar.Add(TranslatePrefs::kPrefTranslateSiteBlacklist,
+ &pref_observer_);
TranslatePrefs translate_prefs(prefs);
EXPECT_FALSE(translate_prefs.IsSiteBlacklisted(host));
EXPECT_TRUE(translate_prefs.CanTranslate(prefs, "fr", url));
@@ -927,16 +930,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();
- prefs->AddPrefObserver(TranslatePrefs::kPrefTranslateWhitelists,
- &pref_observer_);
+ PrefChangeRegistrar registrar;
+ registrar.Init(prefs);
+ registrar.Add(TranslatePrefs::kPrefTranslateWhitelists,
+ &pref_observer_);
TranslatePrefs translate_prefs(prefs);
SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists);
translate_prefs.WhitelistLanguagePair("fr", "en");
@@ -985,8 +988,6 @@ 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.