intl_profile_watcher.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 BASE_FUCHSIA_INTL_PROFILE_WATCHER_H_
  5. #define BASE_FUCHSIA_INTL_PROFILE_WATCHER_H_
  6. #include <fuchsia/intl/cpp/fidl.h>
  7. #include <string>
  8. #include "base/base_export.h"
  9. #include "base/callback.h"
  10. #include "base/strings/string_piece_forward.h"
  11. namespace base {
  12. namespace fuchsia {
  13. // Watches fuchsia.intl.PropertyProvider for change notifications and notifies
  14. // the provided callback. If necessary, the caller is responsible for
  15. // determining whether an actual change of interest has occurred.
  16. class BASE_EXPORT IntlProfileWatcher {
  17. public:
  18. using ProfileChangeCallback =
  19. base::RepeatingCallback<void(const ::fuchsia::intl::Profile&)>;
  20. // |on_profile_changed| will be called each time the profile may have changed.
  21. explicit IntlProfileWatcher(ProfileChangeCallback on_profile_changed);
  22. IntlProfileWatcher(const IntlProfileWatcher&) = delete;
  23. IntlProfileWatcher& operator=(const IntlProfileWatcher&) = delete;
  24. ~IntlProfileWatcher();
  25. // Returns the ID of the primary time zone in |profile|.
  26. // Returns the empty string if the ID cannot be obtained.
  27. static std::string GetPrimaryTimeZoneIdFromProfile(
  28. const ::fuchsia::intl::Profile& profile);
  29. // Returns the ID of the primary time zone for the system.
  30. // Returns the empty string if the ID cannot be obtained.
  31. // This is a synchronous blocking call to the system service and should only
  32. // be used for ICU initialization.
  33. static std::string GetPrimaryTimeZoneIdForIcuInitialization();
  34. private:
  35. friend class GetPrimaryTimeZoneIdFromPropertyProviderTest;
  36. friend class IntlProfileWatcherTest;
  37. IntlProfileWatcher(::fuchsia::intl::PropertyProviderPtr property_provider,
  38. ProfileChangeCallback on_profile_changed);
  39. // Returns the ID of the primary time zone from the profile obtained from
  40. // |property_provider|. Returns the empty string if the ID cannot be obtained.
  41. static std::string GetPrimaryTimeZoneIdFromPropertyProvider(
  42. ::fuchsia::intl::PropertyProviderSyncPtr property_provider);
  43. ::fuchsia::intl::PropertyProviderPtr property_provider_;
  44. const ProfileChangeCallback on_profile_changed_;
  45. };
  46. } // namespace fuchsia
  47. } // namespace base
  48. #endif // BASE_FUCHSIA_INTL_PROFILE_WATCHER_H_