Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/chromeos/locale_change_guard.cc

Issue 471403005: Revert of ChromeOS: should not show "Language changed" notification for certain languages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
9 #include "ash/shell.h" 7 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray.h" 8 #include "ash/system/tray/system_tray.h"
11 #include "ash/system/tray/system_tray_notifier.h" 9 #include "ash/system/tray/system_tray_notifier.h"
12 #include "base/bind.h" 10 #include "base/bind.h"
13 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
14 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/chromeos/settings/device_settings_service.h" 16 #include "chrome/browser/chromeos/settings/device_settings_service.h"
19 #include "chrome/browser/lifetime/application_lifetime.h" 17 #include "chrome/browser/lifetime/application_lifetime.h"
20 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_commands.h" 20 #include "chrome/browser/ui/browser_commands.h"
23 #include "chrome/browser/ui/host_desktop.h" 21 #include "chrome/browser/ui/host_desktop.h"
24 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
25 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
26 #include "chrome/grit/theme_resources.h" 24 #include "chrome/grit/theme_resources.h"
27 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
29 #include "content/public/browser/user_metrics.h" 27 #include "content/public/browser/user_metrics.h"
30 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
31 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
32 30
33 using base::UserMetricsAction; 31 using base::UserMetricsAction;
34 using content::WebContents; 32 using content::WebContents;
35 33
36 namespace chromeos { 34 namespace chromeos {
37 35
38 namespace {
39
40 // This is the list of languages that do not require user notification when
41 // locale is switched automatically between regions within the same language.
42 //
43 // New language in kAcceptLanguageList should be added either here or to
44 // to the exception list in unit test.
45 const char* const kSkipShowNotificationLanguages[4] = {"en", "de", "fr", "it"};
46
47 } // anonymous namespace
48
49 LocaleChangeGuard::LocaleChangeGuard(Profile* profile) 36 LocaleChangeGuard::LocaleChangeGuard(Profile* profile)
50 : profile_(profile), 37 : profile_(profile),
51 reverted_(false), 38 reverted_(false),
52 session_started_(false), 39 session_started_(false),
53 main_frame_loaded_(false) { 40 main_frame_loaded_(false) {
54 DCHECK(profile_); 41 DCHECK(profile_);
55 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, 42 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED,
56 content::NotificationService::AllSources()); 43 content::NotificationService::AllSources());
57 } 44 }
58 45
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 return; 146 return;
160 } 147 }
161 148
162 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup); 149 std::string from_locale = prefs->GetString(prefs::kApplicationLocaleBackup);
163 if (from_locale.empty() || from_locale == to_locale) 150 if (from_locale.empty() || from_locale == to_locale)
164 return; // No locale change was detected, just exit. 151 return; // No locale change was detected, just exit.
165 152
166 if (prefs->GetString(prefs::kApplicationLocaleAccepted) == to_locale) 153 if (prefs->GetString(prefs::kApplicationLocaleAccepted) == to_locale)
167 return; // Already accepted. 154 return; // Already accepted.
168 155
169 // Locale change detected. 156 // Locale change detected, showing notification.
170 if (!ShouldShowLocaleChangeNotification(from_locale, to_locale))
171 return;
172
173 // Showing notification.
174 if (from_locale_ != from_locale || to_locale_ != to_locale) { 157 if (from_locale_ != from_locale || to_locale_ != to_locale) {
175 // Falling back to showing message in current locale. 158 // Falling back to showing message in current locale.
176 LOG(ERROR) << 159 LOG(ERROR) <<
177 "Showing locale change notification in current (not previous) language"; 160 "Showing locale change notification in current (not previous) language";
178 PrepareChangingLocale(from_locale, to_locale); 161 PrepareChangingLocale(from_locale, to_locale);
179 } 162 }
180 163
181 ash::Shell::GetInstance()->system_tray_notifier()->NotifyLocaleChanged( 164 ash::Shell::GetInstance()->system_tray_notifier()->NotifyLocaleChanged(
182 this, cur_locale, from_locale_, to_locale_); 165 this, cur_locale, from_locale_, to_locale_);
183 } 166 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 205
223 title_text_ = l10n_util::GetStringUTF16( 206 title_text_ = l10n_util::GetStringUTF16(
224 IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE); 207 IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE);
225 message_text_ = l10n_util::GetStringFUTF16( 208 message_text_ = l10n_util::GetStringFUTF16(
226 IDS_LOCALE_CHANGE_MESSAGE, from, to); 209 IDS_LOCALE_CHANGE_MESSAGE, from, to);
227 revert_link_text_ = l10n_util::GetStringFUTF16( 210 revert_link_text_ = l10n_util::GetStringFUTF16(
228 IDS_LOCALE_CHANGE_REVERT_MESSAGE, from); 211 IDS_LOCALE_CHANGE_REVERT_MESSAGE, from);
229 } 212 }
230 } 213 }
231 214
232 // static
233 bool LocaleChangeGuard::ShouldShowLocaleChangeNotification(
234 const std::string& from_locale,
235 const std::string& to_locale) {
236 const std::string from_lang = l10n_util::GetLanguage(from_locale);
237 const std::string to_lang = l10n_util::GetLanguage(to_locale);
238
239 if (from_locale == to_locale)
240 return false;
241
242 if (from_lang != to_lang)
243 return true;
244
245 const char* const* begin = kSkipShowNotificationLanguages;
246 const char* const* end = kSkipShowNotificationLanguages +
247 arraysize(kSkipShowNotificationLanguages);
248
249 return std::find(begin, end, from_lang) == end;
250 }
251
252 // static
253 const char* const*
254 LocaleChangeGuard::GetSkipShowNotificationLanguagesForTesting() {
255 return kSkipShowNotificationLanguages;
256 }
257
258 // static
259 size_t LocaleChangeGuard::GetSkipShowNotificationLanguagesSizeForTesting() {
260 return arraysize(kSkipShowNotificationLanguages);
261 }
262
263 } // namespace chromeos 215 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/locale_change_guard.h ('k') | chrome/browser/chromeos/locale_change_guard_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698