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