diff options
author | dilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-18 10:54:36 +0000 |
---|---|---|
committer | dilmah@chromium.org <dilmah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-18 10:54:36 +0000 |
commit | b0db45aa1d4cf98e4ce1636c2fa1a1b2d924495d (patch) | |
tree | 280d9b238886514f85d9f6664783eb279c995e74 | |
parent | 39ab09839e7c5e6c80f7cec84c6e94f070cd451f (diff) | |
download | chromium_src-b0db45aa1d4cf98e4ce1636c2fa1a1b2d924495d.zip chromium_src-b0db45aa1d4cf98e4ce1636c2fa1a1b2d924495d.tar.gz chromium_src-b0db45aa1d4cf98e4ce1636c2fa1a1b2d924495d.tar.bz2 |
Cleanup of r71320 commit.
For ChromeOS: when starting session: if locale was changed (as a result of sync or because user preference differs from login locale): show notification.
BUG=chromium-os:9164
TEST=Manual
Review URL: http://codereview.chromium.org/6249009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71646 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/locale_change_guard.cc | 75 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 2 |
3 files changed, 59 insertions, 20 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 605ba1a..5f94492 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4341,7 +4341,7 @@ Keep your key file in a safe place. You will need it to create new versions of y <!-- Locale Change Notification--> <if expr="pp_ifdef('chromeos')"> <message name="IDS_LOCALE_CHANGE_MESSAGE" desc="Message shown when locale was changed based on profile content."> - Interface language was changed: "<ph name="FROM_LOCALE">$1</ph>" => "<ph name="TO_LOCALE">$2</ph>" based on your preference. + Interface language has been changed: "<ph name="FROM_LOCALE">$1</ph>" => "<ph name="TO_LOCALE">$2</ph>" based on your preference. </message> <message name="IDS_LOCALE_CHANGE_REVERT_MESSAGE" desc="Link to revert a change."> If you are unhappy about it: click here to close browser, sign out and revert. diff --git a/chrome/browser/chromeos/locale_change_guard.cc b/chrome/browser/chromeos/locale_change_guard.cc index f875cdf..f107751 100644 --- a/chrome/browser/chromeos/locale_change_guard.cc +++ b/chrome/browser/chromeos/locale_change_guard.cc @@ -33,15 +33,27 @@ LocaleChangeGuard::LocaleChangeGuard() } void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) { + if (note_ == NULL || + tab_contents_ == NULL || + from_locale_.empty() || + to_locale_.empty()) { + NOTREACHED(); + return; + } + if (reverted_) + return; + + PrefService* prefs = tab_contents_->profile()->GetPrefs(); + if (prefs == NULL) + return; + reverted_ = true; UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert")); tab_contents_->profile()->ChangeApplicationLocale(from_locale_, true); - PrefService* prefs = tab_contents_->profile()->GetPrefs(); - if (prefs) { - prefs->SetString(prefs::kApplicationLocaleBackup, from_locale_); - prefs->ClearPref(prefs::kApplicationLocaleAccepted); - prefs->ScheduleSavePersistentPrefs(); - } + prefs->SetString(prefs::kApplicationLocaleBackup, from_locale_); + prefs->ClearPref(prefs::kApplicationLocaleAccepted); + prefs->ScheduleSavePersistentPrefs(); + Browser* browser = Browser::GetBrowserForController( &tab_contents_->controller(), NULL); if (browser) @@ -52,37 +64,58 @@ void LocaleChangeGuard::CheckLocaleChange(TabContents* tab_contents) { // We want notification to be shown no more than once per session. if (note_ != NULL) return; + DCHECK(note_ == NULL && tab_contents_ == NULL); + DCHECK(from_locale_.empty() && to_locale_.empty()); + // We check profile Id because: // (1) we want to exit fast in common case when nothing should be done. // (2) on ChromeOS this guard may be invoked for a dummy profile first time. ProfileId cur_profile_id = tab_contents->profile()->GetRuntimeId(); - if (cur_profile_id == profile_id_) + if (cur_profile_id == profile_id_) { + // We have already checked this profile, exiting fast. return; + } profile_id_ = cur_profile_id; + std::string cur_locale = g_browser_process->GetApplicationLocale(); - if (cur_locale.empty()) + if (cur_locale.empty()) { + NOTREACHED(); return; + } + PrefService* prefs = tab_contents->profile()->GetPrefs(); if (prefs == NULL) return; - to_locale_ = prefs->GetString(prefs::kApplicationLocaleOverride); - if (!to_locale_.empty()) { - DCHECK(to_locale_ == cur_locale); + + std::string to_locale = prefs->GetString(prefs::kApplicationLocaleOverride); + if (!to_locale.empty()) { + DCHECK(to_locale == cur_locale); return; } - to_locale_ = prefs->GetString(prefs::kApplicationLocale); - if (to_locale_ != cur_locale) + + to_locale = prefs->GetString(prefs::kApplicationLocale); + if (to_locale != cur_locale) { + // This conditional branch can occur in case kApplicationLocale + // preference was modified by synchronization. return; - from_locale_ = prefs->GetString(prefs::kApplicationLocaleBackup); - if (from_locale_.empty() || from_locale_ == to_locale_) + } + + std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup); + if (from_locale.empty() || from_locale == to_locale) { + // No locale change was detected, just exit. return; + } + + // Locale change detected, showing notification. + from_locale_ = from_locale; + to_locale_ = to_locale; + tab_contents_ = tab_contents; note_.reset(new chromeos::SystemNotification( tab_contents->profile(), new Delegate(this), IDR_DEFAULT_FAVICON, l10n_util::GetStringUTF16( IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE))); - tab_contents_ = tab_contents; note_->Show( l10n_util::GetStringFUTF16( IDS_LOCALE_CHANGE_MESSAGE, @@ -95,10 +128,16 @@ void LocaleChangeGuard::CheckLocaleChange(TabContents* tab_contents) { } void LocaleChangeGuard::AcceptLocaleChange() { + if (note_ == NULL || + tab_contents_ == NULL || + from_locale_.empty() || + to_locale_.empty()) { + NOTREACHED(); + return; + } + // Check whether locale has been reverted or changed. // If not: mark current locale as accepted. - if (tab_contents_ == NULL) - return; if (reverted_) return; PrefService* prefs = tab_contents_->profile()->GetPrefs(); diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 925933a..e4495e3 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -1351,7 +1351,7 @@ void ProfileImpl::ChangeApplicationLocale( GetPrefs()->SetString(prefs::kApplicationLocaleOverride, locale); } else { GetPrefs()->SetString(prefs::kApplicationLocale, locale); - GetPrefs()->SetString(prefs::kApplicationLocaleOverride, ""); + GetPrefs()->ClearPref(prefs::kApplicationLocaleOverride); } GetPrefs()->SetString(prefs::kApplicationLocaleBackup, locale); GetPrefs()->ClearPref(prefs::kApplicationLocaleAccepted); |