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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_
6 #define CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_
10 #include "ash/system/locale/locale_observer.h"
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/lazy_instance.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/strings/string16.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/browser/notification_types.h"
29 // Performs check whether locale has been changed automatically recently
30 // (based on synchronized user preference). If so: shows notification that
31 // allows user to revert change.
32 class LocaleChangeGuard
: public content::NotificationObserver
,
33 public ash::LocaleObserver::Delegate
,
34 public base::SupportsWeakPtr
<LocaleChangeGuard
> {
36 explicit LocaleChangeGuard(Profile
* profile
);
37 ~LocaleChangeGuard() override
;
39 // ash::LocaleChangeDelegate implementation.
40 void AcceptLocaleChange() override
;
41 void RevertLocaleChange() override
;
43 // Called just before changing locale.
44 void PrepareChangingLocale(
45 const std::string
& from_locale
, const std::string
& to_locale
);
47 // Called after login.
51 FRIEND_TEST_ALL_PREFIXES(LocaleChangeGuardTest
,
52 ShowNotificationLocaleChanged
);
53 FRIEND_TEST_ALL_PREFIXES(LocaleChangeGuardTest
,
54 ShowNotificationLocaleChangedList
);
56 void RevertLocaleChangeCallback(const base::ListValue
* list
);
59 // content::NotificationObserver implementation.
60 void Observe(int type
,
61 const content::NotificationSource
& source
,
62 const content::NotificationDetails
& details
) override
;
64 // Returns true if we should notify user about automatic locale change.
65 static bool ShouldShowLocaleChangeNotification(const std::string
& from_locale
,
66 const std::string
& to_locale
);
68 static const char* const* GetSkipShowNotificationLanguagesForTesting();
69 static size_t GetSkipShowNotificationLanguagesSizeForTesting();
71 std::string from_locale_
;
72 std::string to_locale_
;
75 bool session_started_
;
76 bool main_frame_loaded_
;
77 content::NotificationRegistrar registrar_
;
79 // We want to show locale change notification in previous language however
80 // we cannot directly load strings for non-current locale. So we cache
81 // messages before locale change.
82 base::string16 title_text_
;
83 base::string16 message_text_
;
84 base::string16 revert_link_text_
;
87 } // namespace chromeos
89 #endif // CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_