1*6777b538SAndroid Build Coastguard Worker // Copyright 2011 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_I18N_ICU_UTIL_H_ 6*6777b538SAndroid Build Coastguard Worker #define BASE_I18N_ICU_UTIL_H_ 7*6777b538SAndroid Build Coastguard Worker 8*6777b538SAndroid Build Coastguard Worker #include <stdint.h> 9*6777b538SAndroid Build Coastguard Worker 10*6777b538SAndroid Build Coastguard Worker #include "base/files/memory_mapped_file.h" 11*6777b538SAndroid Build Coastguard Worker #include "base/i18n/base_i18n_export.h" 12*6777b538SAndroid Build Coastguard Worker #include "build/build_config.h" 13*6777b538SAndroid Build Coastguard Worker #include "build/chromeos_buildflags.h" 14*6777b538SAndroid Build Coastguard Worker 15*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_CHROMEOS_LACROS) 16*6777b538SAndroid Build Coastguard Worker #include "icu_mergeable_data_file.h" 17*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_CHROMEOS_LACROS) 18*6777b538SAndroid Build Coastguard Worker 19*6777b538SAndroid Build Coastguard Worker #define ICU_UTIL_DATA_FILE 0 20*6777b538SAndroid Build Coastguard Worker #define ICU_UTIL_DATA_STATIC 1 21*6777b538SAndroid Build Coastguard Worker 22*6777b538SAndroid Build Coastguard Worker namespace base::i18n { 23*6777b538SAndroid Build Coastguard Worker 24*6777b538SAndroid Build Coastguard Worker #if !BUILDFLAG(IS_NACL) 25*6777b538SAndroid Build Coastguard Worker // Call this function to load ICU's data tables for the current process. This 26*6777b538SAndroid Build Coastguard Worker // function should be called before ICU is used. 27*6777b538SAndroid Build Coastguard Worker BASE_I18N_EXPORT bool InitializeICU(); 28*6777b538SAndroid Build Coastguard Worker 29*6777b538SAndroid Build Coastguard Worker #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE 30*6777b538SAndroid Build Coastguard Worker 31*6777b538SAndroid Build Coastguard Worker // In ChromeOS, two versions of icudtl.dat are shipped separately with Ash and 32*6777b538SAndroid Build Coastguard Worker // Lacros. Although the two files can differ, there's a big overlap in content. 33*6777b538SAndroid Build Coastguard Worker // We can take advantage of that and save memory by scanning the two files and 34*6777b538SAndroid Build Coastguard Worker // merging the pages that are in common. 35*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_CHROMEOS_LACROS) 36*6777b538SAndroid Build Coastguard Worker using IcuDataFile = IcuMergeableDataFile; 37*6777b538SAndroid Build Coastguard Worker #else 38*6777b538SAndroid Build Coastguard Worker // Outside of Lacros, we simply memory map the ICU data file. 39*6777b538SAndroid Build Coastguard Worker using IcuDataFile = MemoryMappedFile; 40*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_CHROMEOS_LACROS) 41*6777b538SAndroid Build Coastguard Worker // Returns the PlatformFile and Region that was initialized by InitializeICU(). 42*6777b538SAndroid Build Coastguard Worker // Use with InitializeICUWithFileDescriptor(). 43*6777b538SAndroid Build Coastguard Worker BASE_I18N_EXPORT PlatformFile 44*6777b538SAndroid Build Coastguard Worker GetIcuDataFileHandle(MemoryMappedFile::Region* out_region); 45*6777b538SAndroid Build Coastguard Worker 46*6777b538SAndroid Build Coastguard Worker // Loads ICU data file from file descriptor passed by browser process to 47*6777b538SAndroid Build Coastguard Worker // initialize ICU in render processes. 48*6777b538SAndroid Build Coastguard Worker BASE_I18N_EXPORT bool InitializeICUWithFileDescriptor( 49*6777b538SAndroid Build Coastguard Worker PlatformFile data_fd, 50*6777b538SAndroid Build Coastguard Worker const MemoryMappedFile::Region& data_region); 51*6777b538SAndroid Build Coastguard Worker 52*6777b538SAndroid Build Coastguard Worker // Calls `u_cleanup()` to reset the ICU library, and clears global state, 53*6777b538SAndroid Build Coastguard Worker // notably releasing the mapped ICU data file, and handle. 54*6777b538SAndroid Build Coastguard Worker BASE_I18N_EXPORT void ResetGlobalsForTesting(); 55*6777b538SAndroid Build Coastguard Worker 56*6777b538SAndroid Build Coastguard Worker #if BUILDFLAG(IS_FUCHSIA) 57*6777b538SAndroid Build Coastguard Worker // Overrides the directory used by ICU for external time zone data. 58*6777b538SAndroid Build Coastguard Worker BASE_I18N_EXPORT void SetIcuTimeZoneDataDirForTesting(const char* dir); 59*6777b538SAndroid Build Coastguard Worker #endif // BUILDFLAG(IS_FUCHSIA) 60*6777b538SAndroid Build Coastguard Worker #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE 61*6777b538SAndroid Build Coastguard Worker 62*6777b538SAndroid Build Coastguard Worker // In a test binary, initialize functions might be called twice. 63*6777b538SAndroid Build Coastguard Worker BASE_I18N_EXPORT void AllowMultipleInitializeCallsForTesting(); 64*6777b538SAndroid Build Coastguard Worker #endif // !BUILDFLAG(IS_NACL) 65*6777b538SAndroid Build Coastguard Worker 66*6777b538SAndroid Build Coastguard Worker } // namespace base::i18n 67*6777b538SAndroid Build Coastguard Worker 68*6777b538SAndroid Build Coastguard Worker #endif // BASE_I18N_ICU_UTIL_H_ 69