Chromium Code Reviews| Index: chrome/browser/chromeos/locale_change_guard.cc |
| diff --git a/chrome/browser/chromeos/locale_change_guard.cc b/chrome/browser/chromeos/locale_change_guard.cc |
| index dc6f294eb37b49ec7ce2cb7abf59c3451262c5cf..8346f5168420abdcefef1bd2709cf50b8da628b9 100644 |
| --- a/chrome/browser/chromeos/locale_change_guard.cc |
| +++ b/chrome/browser/chromeos/locale_change_guard.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/utf_string_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chromeos/login/user_manager.h" |
| #include "chrome/browser/metrics/user_metrics.h" |
| #include "chrome/browser/notifications/notification_delegate.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| @@ -44,6 +45,8 @@ LocaleChangeGuard::LocaleChangeGuard(Profile* profile) |
| DCHECK(profile_); |
| registrar_.Add(this, NotificationType::LOAD_COMPLETED_MAIN_FRAME, |
| NotificationService::AllSources()); |
| + registrar_.Add(this, NotificationType::OWNERSHIP_CHECKED, |
| + NotificationService::AllSources()); |
| } |
| void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) { |
| @@ -56,11 +59,6 @@ void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) { |
| } |
| if (reverted_) |
| return; |
| - |
| - PrefService* prefs = profile_->GetPrefs(); |
| - if (prefs == NULL) |
| - return; |
| - |
| reverted_ = true; |
| UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert")); |
| profile_->ChangeAppLocale( |
| @@ -74,21 +72,42 @@ void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) { |
| void LocaleChangeGuard::Observe(NotificationType type, |
| const NotificationSource& source, |
| const NotificationDetails& details) { |
| - if (type != NotificationType::LOAD_COMPLETED_MAIN_FRAME) { |
| - NOTREACHED(); |
| - return; |
| - } |
| if (profile_ == NULL) { |
| NOTREACHED(); |
| return; |
| } |
| + switch (type.value) { |
| + case NotificationType::LOAD_COMPLETED_MAIN_FRAME: |
| + // We need to perform locale change check only once, so unsubscribe. |
| + registrar_.Remove(this, NotificationType::LOAD_COMPLETED_MAIN_FRAME, |
| + NotificationService::AllSources()); |
| + Check(); |
| + break; |
| + case NotificationType::OWNERSHIP_CHECKED: |
| + if (UserManager::Get()->current_user_is_owner()) { |
| + PrefService* local_state = g_browser_process->local_state(); |
| + if (local_state) { |
| + PrefService* prefs = profile_->GetPrefs(); |
| + if (prefs == NULL) |
|
altimofeev
2011/03/16 11:35:54
You can add NOTREACHED() here, since GetPrefs() sh
Denis Lagno
2011/03/16 11:55:14
Done.
|
| + return; |
| + std::string owner_locale = |
| + prefs->GetString(prefs::kApplicationLocale); |
| + if (!owner_locale.empty()) { |
| + local_state->SetString(prefs::kOwnerLocale, owner_locale); |
| + local_state->ScheduleSavePersistentPrefs(); |
| + } |
| + } |
| + } |
| + break; |
| + default: |
| + NOTREACHED(); |
| + break; |
| + } |
| +} |
| - // We need to perform locale change check only once: so we want to |
| - // unsubscribe from notifications in any case. |
| - registrar_.RemoveAll(); |
| - |
| +void LocaleChangeGuard::Check() { |
| if (note_ != NULL || !from_locale_.empty() || !to_locale_.empty()) { |
| - // Somehow we are notified more than once. Once is enough. |
| + // Somehow we are invoked more than once. Once is enough. |
| return; |
| } |