xref: /aosp_15_r20/external/libchrome/base/i18n/icu_util.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef BASE_I18N_ICU_UTIL_H_
6*635a8641SAndroid Build Coastguard Worker #define BASE_I18N_ICU_UTIL_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include <stdint.h>
9*635a8641SAndroid Build Coastguard Worker 
10*635a8641SAndroid Build Coastguard Worker #include "base/files/memory_mapped_file.h"
11*635a8641SAndroid Build Coastguard Worker #include "base/i18n/base_i18n_export.h"
12*635a8641SAndroid Build Coastguard Worker #include "build/build_config.h"
13*635a8641SAndroid Build Coastguard Worker 
14*635a8641SAndroid Build Coastguard Worker #define ICU_UTIL_DATA_FILE   0
15*635a8641SAndroid Build Coastguard Worker #define ICU_UTIL_DATA_SHARED 1
16*635a8641SAndroid Build Coastguard Worker #define ICU_UTIL_DATA_STATIC 2
17*635a8641SAndroid Build Coastguard Worker 
18*635a8641SAndroid Build Coastguard Worker namespace base {
19*635a8641SAndroid Build Coastguard Worker namespace i18n {
20*635a8641SAndroid Build Coastguard Worker 
21*635a8641SAndroid Build Coastguard Worker #if !defined(OS_NACL)
22*635a8641SAndroid Build Coastguard Worker // Call this function to load ICU's data tables for the current process.  This
23*635a8641SAndroid Build Coastguard Worker // function should be called before ICU is used.
24*635a8641SAndroid Build Coastguard Worker BASE_I18N_EXPORT bool InitializeICU();
25*635a8641SAndroid Build Coastguard Worker 
26*635a8641SAndroid Build Coastguard Worker #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
27*635a8641SAndroid Build Coastguard Worker #if defined(OS_ANDROID)
28*635a8641SAndroid Build Coastguard Worker // Returns the PlatformFile and Region that was initialized by InitializeICU().
29*635a8641SAndroid Build Coastguard Worker // Use with InitializeICUWithFileDescriptor().
30*635a8641SAndroid Build Coastguard Worker BASE_I18N_EXPORT PlatformFile GetIcuDataFileHandle(
31*635a8641SAndroid Build Coastguard Worker     MemoryMappedFile::Region* out_region);
32*635a8641SAndroid Build Coastguard Worker 
33*635a8641SAndroid Build Coastguard Worker // Android uses a file descriptor passed by browser process to initialize ICU
34*635a8641SAndroid Build Coastguard Worker // in render processes.
35*635a8641SAndroid Build Coastguard Worker BASE_I18N_EXPORT bool InitializeICUWithFileDescriptor(
36*635a8641SAndroid Build Coastguard Worker     PlatformFile data_fd,
37*635a8641SAndroid Build Coastguard Worker     const MemoryMappedFile::Region& data_region);
38*635a8641SAndroid Build Coastguard Worker #endif
39*635a8641SAndroid Build Coastguard Worker 
40*635a8641SAndroid Build Coastguard Worker // Returns a void pointer to the memory mapped ICU data file.
41*635a8641SAndroid Build Coastguard Worker //
42*635a8641SAndroid Build Coastguard Worker // There are cases on Android where we would be unsafely reusing a file
43*635a8641SAndroid Build Coastguard Worker // descriptor within the same process when initializing two copies of ICU from
44*635a8641SAndroid Build Coastguard Worker // different binaries in the same address space. This returns an unowned
45*635a8641SAndroid Build Coastguard Worker // pointer to the memory mapped icu data file; consumers copies of base must
46*635a8641SAndroid Build Coastguard Worker // not outlive the copy of base that owns the memory mapped file.
47*635a8641SAndroid Build Coastguard Worker BASE_I18N_EXPORT const uint8_t* GetRawIcuMemory();
48*635a8641SAndroid Build Coastguard Worker 
49*635a8641SAndroid Build Coastguard Worker // Initializes ICU memory
50*635a8641SAndroid Build Coastguard Worker //
51*635a8641SAndroid Build Coastguard Worker // This does nothing in component builds; this initialization should only be
52*635a8641SAndroid Build Coastguard Worker // done in cases where there could be two copies of base in a single process in
53*635a8641SAndroid Build Coastguard Worker // non-component builds. (The big example is standalone service libraries: the
54*635a8641SAndroid Build Coastguard Worker // Service Manager will have a copy of base linked in, and the majority of
55*635a8641SAndroid Build Coastguard Worker // service libraries will have base linked in but in non-component builds,
56*635a8641SAndroid Build Coastguard Worker // these will be separate copies of base.)
57*635a8641SAndroid Build Coastguard Worker BASE_I18N_EXPORT bool InitializeICUFromRawMemory(const uint8_t* raw_memory);
58*635a8641SAndroid Build Coastguard Worker #endif  // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
59*635a8641SAndroid Build Coastguard Worker #endif  // !defined(OS_NACL)
60*635a8641SAndroid Build Coastguard Worker 
61*635a8641SAndroid Build Coastguard Worker // In a test binary, the call above might occur twice.
62*635a8641SAndroid Build Coastguard Worker BASE_I18N_EXPORT void AllowMultipleInitializeCallsForTesting();
63*635a8641SAndroid Build Coastguard Worker 
64*635a8641SAndroid Build Coastguard Worker }  // namespace i18n
65*635a8641SAndroid Build Coastguard Worker }  // namespace base
66*635a8641SAndroid Build Coastguard Worker 
67*635a8641SAndroid Build Coastguard Worker #endif  // BASE_I18N_ICU_UTIL_H_
68