| 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 #ifndef CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "ash/common/system/locale/locale_observer.h" | 13 #include "ash/public/interfaces/locale.mojom.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 21 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
| 22 | 22 |
| 23 class Profile; | 23 class Profile; |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 class ListValue; | 26 class ListValue; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace chromeos { | 29 namespace chromeos { |
| 30 | 30 |
| 31 // Performs check whether locale has been changed automatically recently | 31 // Performs check whether locale has been changed automatically recently |
| 32 // (based on synchronized user preference). If so: shows notification that | 32 // (based on synchronized user preference). If so: shows notification that |
| 33 // allows user to revert change. | 33 // allows user to revert change. |
| 34 class LocaleChangeGuard : public content::NotificationObserver, | 34 class LocaleChangeGuard : public content::NotificationObserver, |
| 35 public ash::LocaleObserver::Delegate, | |
| 36 public base::SupportsWeakPtr<LocaleChangeGuard> { | 35 public base::SupportsWeakPtr<LocaleChangeGuard> { |
| 37 public: | 36 public: |
| 38 explicit LocaleChangeGuard(Profile* profile); | 37 explicit LocaleChangeGuard(Profile* profile); |
| 39 ~LocaleChangeGuard() override; | 38 ~LocaleChangeGuard() override; |
| 40 | 39 |
| 41 // ash::LocaleChangeDelegate implementation. | |
| 42 void AcceptLocaleChange() override; | |
| 43 void RevertLocaleChange() override; | |
| 44 | |
| 45 // Called just before changing locale. | 40 // Called just before changing locale. |
| 46 void PrepareChangingLocale( | 41 void PrepareChangingLocale( |
| 47 const std::string& from_locale, const std::string& to_locale); | 42 const std::string& from_locale, const std::string& to_locale); |
| 48 | 43 |
| 49 // Called after login. | 44 // Called after login. |
| 50 void OnLogin(); | 45 void OnLogin(); |
| 51 | 46 |
| 52 private: | 47 private: |
| 53 FRIEND_TEST_ALL_PREFIXES(LocaleChangeGuardTest, | 48 FRIEND_TEST_ALL_PREFIXES(LocaleChangeGuardTest, |
| 54 ShowNotificationLocaleChanged); | 49 ShowNotificationLocaleChanged); |
| 55 FRIEND_TEST_ALL_PREFIXES(LocaleChangeGuardTest, | 50 FRIEND_TEST_ALL_PREFIXES(LocaleChangeGuardTest, |
| 56 ShowNotificationLocaleChangedList); | 51 ShowNotificationLocaleChangedList); |
| 57 | 52 |
| 53 void ConnectToLocaleNotificationController(); |
| 54 |
| 58 void RevertLocaleChangeCallback(const base::ListValue* list); | 55 void RevertLocaleChangeCallback(const base::ListValue* list); |
| 59 void Check(); | 56 void Check(); |
| 60 | 57 |
| 58 void OnResult(ash::mojom::LocaleNotificationResult result); |
| 59 void AcceptLocaleChange(); |
| 60 void RevertLocaleChange(); |
| 61 |
| 61 // content::NotificationObserver implementation. | 62 // content::NotificationObserver implementation. |
| 62 void Observe(int type, | 63 void Observe(int type, |
| 63 const content::NotificationSource& source, | 64 const content::NotificationSource& source, |
| 64 const content::NotificationDetails& details) override; | 65 const content::NotificationDetails& details) override; |
| 65 | 66 |
| 66 // Returns true if we should notify user about automatic locale change. | 67 // Returns true if we should notify user about automatic locale change. |
| 67 static bool ShouldShowLocaleChangeNotification(const std::string& from_locale, | 68 static bool ShouldShowLocaleChangeNotification(const std::string& from_locale, |
| 68 const std::string& to_locale); | 69 const std::string& to_locale); |
| 69 | 70 |
| 70 static const char* const* GetSkipShowNotificationLanguagesForTesting(); | 71 static const char* const* GetSkipShowNotificationLanguagesForTesting(); |
| 71 static size_t GetSkipShowNotificationLanguagesSizeForTesting(); | 72 static size_t GetSkipShowNotificationLanguagesSizeForTesting(); |
| 72 | 73 |
| 74 // Ash's mojom::LocaleNotificationController used to display notifications. |
| 75 ash::mojom::LocaleNotificationControllerPtr notification_controller_; |
| 76 |
| 73 std::string from_locale_; | 77 std::string from_locale_; |
| 74 std::string to_locale_; | 78 std::string to_locale_; |
| 75 Profile* profile_; | 79 Profile* profile_; |
| 76 bool reverted_; | 80 bool reverted_; |
| 77 bool session_started_; | 81 bool session_started_; |
| 78 bool main_frame_loaded_; | 82 bool main_frame_loaded_; |
| 79 content::NotificationRegistrar registrar_; | 83 content::NotificationRegistrar registrar_; |
| 80 | 84 |
| 81 // We want to show locale change notification in previous language however | 85 DISALLOW_COPY_AND_ASSIGN(LocaleChangeGuard); |
| 82 // we cannot directly load strings for non-current locale. So we cache | |
| 83 // messages before locale change. | |
| 84 base::string16 title_text_; | |
| 85 base::string16 message_text_; | |
| 86 base::string16 revert_link_text_; | |
| 87 }; | 86 }; |
| 88 | 87 |
| 89 } // namespace chromeos | 88 } // namespace chromeos |
| 90 | 89 |
| 91 #endif // CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_ | 90 #endif // CHROME_BROWSER_CHROMEOS_LOCALE_CHANGE_GUARD_H_ |
| OLD | NEW |