| 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 | |
| 5 | #ifndef BASE_I18N_ICU_UTIL_H_ |
| 6 | #define BASE_I18N_ICU_UTIL_H_ |
| 7 | |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include "base/files/memory_mapped_file.h" |
| 11 | #include "base/i18n/base_i18n_export.h" |
| 12 | #include "build/build_config.h" |
| 13 | |
| 14 | #define ICU_UTIL_DATA_FILE 0 |
| 15 | #define ICU_UTIL_DATA_STATIC 1 |
| 16 | |
| 17 | namespace base { |
| 18 | namespace i18n { |
| 19 | |
| 20 | #if !defined(OS_NACL) |
| 21 | // Call this function to load ICU's data tables for the current process. This |
| 22 | // function should be called before ICU is used. |
| 23 | BASE_I18N_EXPORT bool InitializeICU(); |
| 24 | |
| 25 | #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE |
| 26 | // Loads ICU's extra data tables from disk for the current process. If used must |
| 27 | // be called before InitializeICU(). |
| 28 | BASE_I18N_EXPORT bool InitializeExtraICU(); |
| 29 | |
| 30 | // Returns the PlatformFile and Region that was initialized by InitializeICU() |
| 31 | // or InitializeExtraICU(). Use with InitializeICUWithFileDescriptor() or |
| 32 | // InitializeExtraICUWithFileDescriptor(). |
| 33 | BASE_I18N_EXPORT PlatformFile GetIcuDataFileHandle( |
| 34 | MemoryMappedFile::Region* out_region); |
| 35 | BASE_I18N_EXPORT PlatformFile |
| 36 | GetIcuExtraDataFileHandle(MemoryMappedFile::Region* out_region); |
| 37 | |
| 38 | // Loads ICU data file from file descriptor passed by browser process to |
| 39 | // initialize ICU in render processes. |
| 40 | BASE_I18N_EXPORT bool InitializeICUWithFileDescriptor( |
| 41 | PlatformFile data_fd, |
| 42 | const MemoryMappedFile::Region& data_region); |
| 43 | |
| 44 | // Loads ICU extra data file from file descriptor passed by browser process to |
| 45 | // initialize ICU in render processes. If used must be called before |
| 46 | // InitializeICUWithFileDescriptor(). |
| 47 | BASE_I18N_EXPORT bool InitializeExtraICUWithFileDescriptor( |
| 48 | PlatformFile data_fd, |
| 49 | const MemoryMappedFile::Region& data_region); |
| 50 | |
| 51 | BASE_I18N_EXPORT void ResetGlobalsForTesting(); |
| 52 | |
| 53 | #if defined(OS_FUCHSIA) |
| 54 | // Overrides the directory used by ICU for external time zone data. |
| 55 | BASE_I18N_EXPORT void SetIcuTimeZoneDataDirForTesting(const char* dir); |
| 56 | #endif // defined(OS_FUCHSIA) |
| 57 | #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE |
| 58 | |
| 59 | // In a test binary, initialize functions might be called twice. |
| 60 | BASE_I18N_EXPORT void AllowMultipleInitializeCallsForTesting(); |
| 61 | #endif // !defined(OS_NACL) |
| 62 | |
| 63 | } // namespace i18n |
| 64 | } // namespace base |
| 65 | |
| 66 | #endif // BASE_I18N_ICU_UTIL_H_ |
| 67 | |