OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | |
8 | |
7 #include "ash/shell.h" | 9 #include "ash/shell.h" |
8 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
9 #include "ash/system/tray/system_tray_notifier.h" | 11 #include "ash/system/tray/system_tray_notifier.h" |
10 #include "base/bind.h" | 12 #include "base/bind.h" |
11 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 18 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
17 #include "chrome/browser/lifetime/application_lifetime.h" | 19 #include "chrome/browser/lifetime/application_lifetime.h" |
18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
21 #include "chrome/browser/ui/host_desktop.h" | 23 #include "chrome/browser/ui/host_desktop.h" |
22 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
23 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
25 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
27 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
28 #include "grit/theme_resources.h" | 30 #include "grit/theme_resources.h" |
29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
30 | 32 |
31 using base::UserMetricsAction; | 33 using base::UserMetricsAction; |
32 using content::WebContents; | 34 using content::WebContents; |
33 | 35 |
34 namespace chromeos { | 36 namespace chromeos { |
35 | 37 |
38 namespace { | |
39 | |
40 bool ShouldShowLanguageNotification(const std::string& from_locale, | |
Nikita (slow)
2014/07/14 09:37:42
nit: Language -> Locale
Nikita (slow)
2014/07/14 09:37:42
This function might as well have unit_test.
Alexander Alekseev
2014/07/14 22:01:59
Done.
Alexander Alekseev
2014/07/14 22:01:59
Done.
| |
41 const std::string& to_locale) { | |
42 const std::string from_lang = l10n_util::GetLanguage(from_locale); | |
43 const std::string to_lang = l10n_util::GetLanguage(to_locale); | |
44 | |
45 if (from_lang != to_lang) | |
46 return true; | |
47 | |
48 const char* const ignore_languages[] = {"en", "de", "fr", "it"}; | |
Nikita (slow)
2014/07/14 09:37:41
Do you think that pt* (pt/pt-BR/pt-PT) should not
Alexander Alekseev
2014/07/14 22:01:59
Actually no. We should show notification for "pt".
| |
49 if (std::find(ignore_languages, | |
Nikita (slow)
2014/07/14 09:37:41
return !std::find(...);
Alexander Alekseev
2014/07/14 22:01:59
Done.
| |
50 ignore_languages + arraysize(ignore_languages), | |
51 from_lang) != ignore_languages + arraysize(ignore_languages)) { | |
52 return false; | |
53 } | |
54 | |
55 return true; | |
56 } | |
57 | |
58 } // anonymous namespace | |
59 | |
36 LocaleChangeGuard::LocaleChangeGuard(Profile* profile) | 60 LocaleChangeGuard::LocaleChangeGuard(Profile* profile) |
37 : profile_(profile), | 61 : profile_(profile), |
38 reverted_(false), | 62 reverted_(false), |
39 session_started_(false), | 63 session_started_(false), |
40 main_frame_loaded_(false) { | 64 main_frame_loaded_(false) { |
41 DCHECK(profile_); | 65 DCHECK(profile_); |
42 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, | 66 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, |
43 content::NotificationService::AllSources()); | 67 content::NotificationService::AllSources()); |
44 } | 68 } |
45 | 69 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 return; | 170 return; |
147 } | 171 } |
148 | 172 |
149 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup); | 173 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup); |
150 if (from_locale.empty() || from_locale == to_locale) | 174 if (from_locale.empty() || from_locale == to_locale) |
151 return; // No locale change was detected, just exit. | 175 return; // No locale change was detected, just exit. |
152 | 176 |
153 if (prefs->GetString(prefs::kApplicationLocaleAccepted) == to_locale) | 177 if (prefs->GetString(prefs::kApplicationLocaleAccepted) == to_locale) |
154 return; // Already accepted. | 178 return; // Already accepted. |
155 | 179 |
156 // Locale change detected, showing notification. | 180 // Locale change detected |
Nikita (slow)
2014/07/14 09:37:41
nit: dot at the end.
Alexander Alekseev
2014/07/14 22:01:59
Done.
| |
181 if (!ShouldShowLanguageNotification(from_locale, to_locale)) | |
182 return; | |
183 | |
184 // Showing notification. | |
157 if (from_locale_ != from_locale || to_locale_ != to_locale) { | 185 if (from_locale_ != from_locale || to_locale_ != to_locale) { |
158 // Falling back to showing message in current locale. | 186 // Falling back to showing message in current locale. |
159 LOG(ERROR) << | 187 LOG(ERROR) << |
160 "Showing locale change notification in current (not previous) language"; | 188 "Showing locale change notification in current (not previous) language"; |
161 PrepareChangingLocale(from_locale, to_locale); | 189 PrepareChangingLocale(from_locale, to_locale); |
162 } | 190 } |
163 | 191 |
164 ash::Shell::GetInstance()->system_tray_notifier()->NotifyLocaleChanged( | 192 ash::Shell::GetInstance()->system_tray_notifier()->NotifyLocaleChanged( |
165 this, cur_locale, from_locale_, to_locale_); | 193 this, cur_locale, from_locale_, to_locale_); |
166 } | 194 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 title_text_ = l10n_util::GetStringUTF16( | 234 title_text_ = l10n_util::GetStringUTF16( |
207 IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE); | 235 IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE); |
208 message_text_ = l10n_util::GetStringFUTF16( | 236 message_text_ = l10n_util::GetStringFUTF16( |
209 IDS_LOCALE_CHANGE_MESSAGE, from, to); | 237 IDS_LOCALE_CHANGE_MESSAGE, from, to); |
210 revert_link_text_ = l10n_util::GetStringFUTF16( | 238 revert_link_text_ = l10n_util::GetStringFUTF16( |
211 IDS_LOCALE_CHANGE_REVERT_MESSAGE, from); | 239 IDS_LOCALE_CHANGE_REVERT_MESSAGE, from); |
212 } | 240 } |
213 } | 241 } |
214 | 242 |
215 } // namespace chromeos | 243 } // namespace chromeos |
OLD | NEW |