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