locale_update_controller.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2019 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.
  4. #ifndef ASH_PUBLIC_CPP_LOCALE_UPDATE_CONTROLLER_H_
  5. #define ASH_PUBLIC_CPP_LOCALE_UPDATE_CONTROLLER_H_
  6. #include <string>
  7. #include "ash/public/cpp/ash_public_export.h"
  8. #include "base/callback_forward.h"
  9. namespace ash {
  10. // The locale info to show in the system tray locale detailed view.
  11. struct ASH_PUBLIC_EXPORT LocaleInfo {
  12. LocaleInfo();
  13. LocaleInfo(const std::string& iso_code, const std::u16string& display_name);
  14. LocaleInfo(const LocaleInfo& rhs);
  15. LocaleInfo(LocaleInfo&& rhs);
  16. ~LocaleInfo();
  17. // This ISO code of the locale.
  18. std::string iso_code;
  19. // The display name of the locale.
  20. std::u16string display_name;
  21. };
  22. // Sent as the response to LocaleUpdateController.OnLocaleChanged().
  23. enum class LocaleNotificationResult {
  24. kAccept,
  25. kRevert,
  26. };
  27. class LocaleChangeObserver {
  28. public:
  29. virtual ~LocaleChangeObserver() = default;
  30. // Called when locale is changed.
  31. virtual void OnLocaleChanged() = 0;
  32. };
  33. // Used by Chrome to notify locale change events.
  34. class ASH_PUBLIC_EXPORT LocaleUpdateController {
  35. public:
  36. using LocaleChangeConfirmationCallback =
  37. base::OnceCallback<void(LocaleNotificationResult)>;
  38. // Get the singleton instance of LocaleUpdateController.
  39. static LocaleUpdateController* Get();
  40. // Called when system locale changes, and the user should be notified of the
  41. // locale change. Used during OOBE, or on user login if the user's preferred
  42. // locale does not match the login screen locale.
  43. virtual void OnLocaleChanged() = 0;
  44. // Called when the locale changes in user session (for example by sync). This
  45. // will show a notification asking the user to confirm the locale change.
  46. // |callback| will be called when the user accepts or rejects the locale
  47. // change.
  48. virtual void ConfirmLocaleChange(
  49. const std::string& current_locale,
  50. const std::string& from_locale,
  51. const std::string& to_locale,
  52. LocaleChangeConfirmationCallback callback) = 0;
  53. virtual void AddObserver(LocaleChangeObserver* observer) = 0;
  54. virtual void RemoveObserver(LocaleChangeObserver* observer) = 0;
  55. protected:
  56. LocaleUpdateController();
  57. virtual ~LocaleUpdateController();
  58. };
  59. } // namespace ash
  60. #endif // ASH_PUBLIC_CPP_LOCALE_UPDATE_CONTROLLER_H_