| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/locale_change_guard.h" | 5 #include "chrome/browser/chromeos/locale_change_guard.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chromeos/login/user_manager.h" | 11 #include "chrome/browser/chromeos/login/user_manager.h" |
| 12 #include "chrome/browser/notifications/notification_delegate.h" | 12 #include "chrome/browser/notifications/notification_delegate.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 19 #include "content/browser/user_metrics.h" | |
| 20 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 21 #include "content/public/browser/user_metrics.h" |
| 22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 23 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 | 25 |
| 26 using content::UserMetricsAction; |
| 27 |
| 26 namespace chromeos { | 28 namespace chromeos { |
| 27 | 29 |
| 28 class LocaleChangeGuard::Delegate : public NotificationDelegate { | 30 class LocaleChangeGuard::Delegate : public NotificationDelegate { |
| 29 public: | 31 public: |
| 30 explicit Delegate(chromeos::LocaleChangeGuard* master) : master_(master) {} | 32 explicit Delegate(chromeos::LocaleChangeGuard* master) : master_(master) {} |
| 31 void Close(bool by_user); | 33 void Close(bool by_user); |
| 32 void Display() {} | 34 void Display() {} |
| 33 void Error() {} | 35 void Error() {} |
| 34 void Click() {} | 36 void Click() {} |
| 35 std::string id() const; | 37 std::string id() const; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 60 if (note_ == NULL || | 62 if (note_ == NULL || |
| 61 profile_ == NULL || | 63 profile_ == NULL || |
| 62 from_locale_.empty() || | 64 from_locale_.empty() || |
| 63 to_locale_.empty()) { | 65 to_locale_.empty()) { |
| 64 NOTREACHED(); | 66 NOTREACHED(); |
| 65 return; | 67 return; |
| 66 } | 68 } |
| 67 if (reverted_) | 69 if (reverted_) |
| 68 return; | 70 return; |
| 69 reverted_ = true; | 71 reverted_ = true; |
| 70 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Revert")); | 72 content::RecordAction(UserMetricsAction("LanguageChange_Revert")); |
| 71 profile_->ChangeAppLocale( | 73 profile_->ChangeAppLocale( |
| 72 from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT); | 74 from_locale_, Profile::APP_LOCALE_CHANGED_VIA_REVERT); |
| 73 | 75 |
| 74 Browser* browser = Browser::GetTabbedBrowser(profile_, false); | 76 Browser* browser = Browser::GetTabbedBrowser(profile_, false); |
| 75 if (browser) | 77 if (browser) |
| 76 browser->ExecuteCommand(IDC_EXIT); | 78 browser->ExecuteCommand(IDC_EXIT); |
| 77 } | 79 } |
| 78 | 80 |
| 79 void LocaleChangeGuard::Observe(int type, | 81 void LocaleChangeGuard::Observe(int type, |
| 80 const content::NotificationSource& source, | 82 const content::NotificationSource& source, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // If not: mark current locale as accepted. | 187 // If not: mark current locale as accepted. |
| 186 if (reverted_) | 188 if (reverted_) |
| 187 return; | 189 return; |
| 188 PrefService* prefs = profile_->GetPrefs(); | 190 PrefService* prefs = profile_->GetPrefs(); |
| 189 if (prefs == NULL) { | 191 if (prefs == NULL) { |
| 190 NOTREACHED(); | 192 NOTREACHED(); |
| 191 return; | 193 return; |
| 192 } | 194 } |
| 193 if (prefs->GetString(prefs::kApplicationLocale) != to_locale_) | 195 if (prefs->GetString(prefs::kApplicationLocale) != to_locale_) |
| 194 return; | 196 return; |
| 195 UserMetrics::RecordAction(UserMetricsAction("LanguageChange_Accept")); | 197 content::RecordAction(UserMetricsAction("LanguageChange_Accept")); |
| 196 prefs->SetString(prefs::kApplicationLocaleBackup, to_locale_); | 198 prefs->SetString(prefs::kApplicationLocaleBackup, to_locale_); |
| 197 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_); | 199 prefs->SetString(prefs::kApplicationLocaleAccepted, to_locale_); |
| 198 prefs->ScheduleSavePersistentPrefs(); | 200 prefs->ScheduleSavePersistentPrefs(); |
| 199 } | 201 } |
| 200 | 202 |
| 201 void LocaleChangeGuard::PrepareChangingLocale( | 203 void LocaleChangeGuard::PrepareChangingLocale( |
| 202 const std::string& from_locale, const std::string& to_locale) { | 204 const std::string& from_locale, const std::string& to_locale) { |
| 203 std::string cur_locale = g_browser_process->GetApplicationLocale(); | 205 std::string cur_locale = g_browser_process->GetApplicationLocale(); |
| 204 if (!from_locale.empty()) | 206 if (!from_locale.empty()) |
| 205 from_locale_ = from_locale; | 207 from_locale_ = from_locale; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 225 if (by_user) | 227 if (by_user) |
| 226 master_->AcceptLocaleChange(); | 228 master_->AcceptLocaleChange(); |
| 227 } | 229 } |
| 228 | 230 |
| 229 std::string LocaleChangeGuard::Delegate::id() const { | 231 std::string LocaleChangeGuard::Delegate::id() const { |
| 230 // Arbitrary unique Id. | 232 // Arbitrary unique Id. |
| 231 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; | 233 return "8c386938-1e3f-11e0-ac7b-18a90520e2e5"; |
| 232 } | 234 } |
| 233 | 235 |
| 234 } // namespace chromeos | 236 } // namespace chromeos |
| OLD | NEW |