icu_util.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_I18N_ICU_UTIL_H_
  5. #define BASE_I18N_ICU_UTIL_H_
  6. #include <stdint.h>
  7. #include "base/files/memory_mapped_file.h"
  8. #include "base/i18n/base_i18n_export.h"
  9. #include "build/build_config.h"
  10. #include "build/chromeos_buildflags.h"
  11. #if BUILDFLAG(IS_CHROMEOS_LACROS)
  12. #include "icu_mergeable_data_file.h"
  13. #endif // BUILDFLAG(IS_CHROMEOS_LACROS)
  14. #define ICU_UTIL_DATA_FILE 0
  15. #define ICU_UTIL_DATA_STATIC 1
  16. namespace base::i18n {
  17. #if !BUILDFLAG(IS_NACL)
  18. // Call this function to load ICU's data tables for the current process. This
  19. // function should be called before ICU is used.
  20. BASE_I18N_EXPORT bool InitializeICU();
  21. #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
  22. // In ChromeOS, two versions of icudtl.dat are shipped separately with Ash and
  23. // Lacros. Although the two files can differ, there's a big overlap in content.
  24. // We can take advantage of that and save memory by scanning the two files and
  25. // merging the pages that are in common.
  26. #if BUILDFLAG(IS_CHROMEOS_LACROS)
  27. using IcuDataFile = IcuMergeableDataFile;
  28. #else
  29. // Outside of Lacros, we simply memory map the ICU data file.
  30. using IcuDataFile = MemoryMappedFile;
  31. #endif // BUILDFLAG(IS_CHROMEOS_LACROS)
  32. // Returns the PlatformFile and Region that was initialized by InitializeICU().
  33. // Use with InitializeICUWithFileDescriptor().
  34. BASE_I18N_EXPORT PlatformFile
  35. GetIcuDataFileHandle(MemoryMappedFile::Region* out_region);
  36. // Loads ICU data file from file descriptor passed by browser process to
  37. // initialize ICU in render processes.
  38. BASE_I18N_EXPORT bool InitializeICUWithFileDescriptor(
  39. PlatformFile data_fd,
  40. const MemoryMappedFile::Region& data_region);
  41. BASE_I18N_EXPORT void ResetGlobalsForTesting();
  42. #if BUILDFLAG(IS_FUCHSIA)
  43. // Overrides the directory used by ICU for external time zone data.
  44. BASE_I18N_EXPORT void SetIcuTimeZoneDataDirForTesting(const char* dir);
  45. #endif // BUILDFLAG(IS_FUCHSIA)
  46. #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
  47. // In a test binary, initialize functions might be called twice.
  48. BASE_I18N_EXPORT void AllowMultipleInitializeCallsForTesting();
  49. #endif // !BUILDFLAG(IS_NACL)
  50. } // namespace base::i18n
  51. #endif // BASE_I18N_ICU_UTIL_H_