xref: /aosp_15_r20/external/cronet/base/fuchsia/intl_profile_watcher.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2019 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef BASE_FUCHSIA_INTL_PROFILE_WATCHER_H_
6*6777b538SAndroid Build Coastguard Worker #define BASE_FUCHSIA_INTL_PROFILE_WATCHER_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include <fuchsia/intl/cpp/fidl.h>
9*6777b538SAndroid Build Coastguard Worker #include <string>
10*6777b538SAndroid Build Coastguard Worker 
11*6777b538SAndroid Build Coastguard Worker #include "base/base_export.h"
12*6777b538SAndroid Build Coastguard Worker #include "base/functional/callback.h"
13*6777b538SAndroid Build Coastguard Worker #include "base/strings/string_piece.h"
14*6777b538SAndroid Build Coastguard Worker 
15*6777b538SAndroid Build Coastguard Worker namespace base {
16*6777b538SAndroid Build Coastguard Worker 
17*6777b538SAndroid Build Coastguard Worker // Watches fuchsia.intl.PropertyProvider for change notifications and notifies
18*6777b538SAndroid Build Coastguard Worker // the provided callback. If necessary, the caller is responsible for
19*6777b538SAndroid Build Coastguard Worker // determining whether an actual change of interest has occurred.
20*6777b538SAndroid Build Coastguard Worker class BASE_EXPORT FuchsiaIntlProfileWatcher {
21*6777b538SAndroid Build Coastguard Worker  public:
22*6777b538SAndroid Build Coastguard Worker   using ProfileChangeCallback =
23*6777b538SAndroid Build Coastguard Worker       base::RepeatingCallback<void(const ::fuchsia::intl::Profile&)>;
24*6777b538SAndroid Build Coastguard Worker 
25*6777b538SAndroid Build Coastguard Worker   // |on_profile_changed| will be called each time the profile may have changed.
26*6777b538SAndroid Build Coastguard Worker   explicit FuchsiaIntlProfileWatcher(ProfileChangeCallback on_profile_changed);
27*6777b538SAndroid Build Coastguard Worker 
28*6777b538SAndroid Build Coastguard Worker   FuchsiaIntlProfileWatcher(const FuchsiaIntlProfileWatcher&) = delete;
29*6777b538SAndroid Build Coastguard Worker   FuchsiaIntlProfileWatcher& operator=(const FuchsiaIntlProfileWatcher&) =
30*6777b538SAndroid Build Coastguard Worker       delete;
31*6777b538SAndroid Build Coastguard Worker   ~FuchsiaIntlProfileWatcher();
32*6777b538SAndroid Build Coastguard Worker 
33*6777b538SAndroid Build Coastguard Worker   // Returns the ID of the primary time zone in |profile|.
34*6777b538SAndroid Build Coastguard Worker   // Returns an empty string if the ID cannot be obtained.
35*6777b538SAndroid Build Coastguard Worker   static std::string GetPrimaryTimeZoneIdFromProfile(
36*6777b538SAndroid Build Coastguard Worker       const ::fuchsia::intl::Profile& profile);
37*6777b538SAndroid Build Coastguard Worker 
38*6777b538SAndroid Build Coastguard Worker   // Returns the ID of the primary time zone for the system.
39*6777b538SAndroid Build Coastguard Worker   // Returns the empty string if the ID cannot be obtained.
40*6777b538SAndroid Build Coastguard Worker   // This is a synchronous blocking call to the system service and should only
41*6777b538SAndroid Build Coastguard Worker   // be used for ICU initialization.
42*6777b538SAndroid Build Coastguard Worker   static std::string GetPrimaryTimeZoneIdForIcuInitialization();
43*6777b538SAndroid Build Coastguard Worker 
44*6777b538SAndroid Build Coastguard Worker   // Returns the ID of the primary locale preference in |profile|.
45*6777b538SAndroid Build Coastguard Worker   // Returns an empty string if the ID cannot be obtained.
46*6777b538SAndroid Build Coastguard Worker   static std::string GetPrimaryLocaleIdFromProfile(
47*6777b538SAndroid Build Coastguard Worker       const ::fuchsia::intl::Profile& profile);
48*6777b538SAndroid Build Coastguard Worker 
49*6777b538SAndroid Build Coastguard Worker   // Returns the ID of the primary locale preference for the system.
50*6777b538SAndroid Build Coastguard Worker   // Returns an empty string if the ID cannot be obtained.
51*6777b538SAndroid Build Coastguard Worker   // This is a synchronous blocking call to the system service, and should only
52*6777b538SAndroid Build Coastguard Worker   // be used for first value initialization.
53*6777b538SAndroid Build Coastguard Worker   static std::string GetPrimaryLocaleIdForInitialization();
54*6777b538SAndroid Build Coastguard Worker 
55*6777b538SAndroid Build Coastguard Worker  private:
56*6777b538SAndroid Build Coastguard Worker   friend class GetValuesFromIntlPropertyProviderTest;
57*6777b538SAndroid Build Coastguard Worker   friend class IntlProfileWatcherTest;
58*6777b538SAndroid Build Coastguard Worker 
59*6777b538SAndroid Build Coastguard Worker   FuchsiaIntlProfileWatcher(
60*6777b538SAndroid Build Coastguard Worker       ::fuchsia::intl::PropertyProviderPtr property_provider,
61*6777b538SAndroid Build Coastguard Worker       ProfileChangeCallback on_profile_changed);
62*6777b538SAndroid Build Coastguard Worker 
63*6777b538SAndroid Build Coastguard Worker   static ::fuchsia::intl::Profile GetProfileFromPropertyProvider(
64*6777b538SAndroid Build Coastguard Worker       ::fuchsia::intl::PropertyProviderSyncPtr property_provider);
65*6777b538SAndroid Build Coastguard Worker 
66*6777b538SAndroid Build Coastguard Worker   static ::fuchsia::intl::Profile GetCurrentProfileSync();
67*6777b538SAndroid Build Coastguard Worker 
68*6777b538SAndroid Build Coastguard Worker   ::fuchsia::intl::PropertyProviderPtr property_provider_;
69*6777b538SAndroid Build Coastguard Worker   const ProfileChangeCallback on_profile_changed_;
70*6777b538SAndroid Build Coastguard Worker };
71*6777b538SAndroid Build Coastguard Worker 
72*6777b538SAndroid Build Coastguard Worker }  // namespace base
73*6777b538SAndroid Build Coastguard Worker 
74*6777b538SAndroid Build Coastguard Worker #endif  // BASE_FUCHSIA_INTL_PROFILE_WATCHER_H_
75