Commit 257a6f59 authored by David Dorwin's avatar David Dorwin Committed by Commit Bot

Simplify conditional compilation in icu_util

Change-Id: I730f54915f7a4f219d6b970ff4651fa20eb07b11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866928
Commit-Queue: David Dorwin <ddorwin@chromium.org>
Reviewed-by: default avatarJungshik Shin <jshin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709122}
parent 1b3951bc
......@@ -40,8 +40,9 @@
namespace base {
namespace i18n {
namespace {
#if !defined(OS_NACL)
namespace {
#if DCHECK_IS_ON()
// Assert that we are not called more than once. Even though calling this
// function isn't harmful (ICU can handle it), being called twice probably
......@@ -50,7 +51,7 @@ bool g_check_called_once = true;
bool g_called_once = false;
#endif // DCHECK_IS_ON()
#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
#if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
// To debug http://crbug.com/445616.
int g_debug_icu_last_error;
......@@ -233,13 +234,11 @@ bool InitializeICUWithFileDescriptorInternal(
udata_setFileAccess(UDATA_ONLY_PACKAGES, &err);
return U_SUCCESS(err);
}
#endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
#endif // !defined(OS_NACL)
#endif // (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
} // namespace
#if !defined(OS_NACL)
#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
#if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
bool InitializeExtraICUWithFileDescriptor(
PlatformFile data_fd,
const MemoryMappedFile::Region& data_region) {
......@@ -302,6 +301,12 @@ bool InitializeExtraICU() {
return true;
}
void ResetGlobalsForTesting() {
g_icudtl_pf = kInvalidPlatformFile;
g_icudtl_mapped_file = nullptr;
g_icudtl_extra_pf = kInvalidPlatformFile;
g_icudtl_extra_mapped_file = nullptr;
}
#endif // (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
bool InitializeICU() {
......@@ -336,6 +341,8 @@ bool InitializeICU() {
debug::Alias(&debug_icu_pf_filename);
CHECK(result); // TODO(brucedawson): http://crbug.com/445616
#endif // defined(OS_WIN)
#else
#error Unsupported ICU_UTIL_DATA_IMPL value
#endif // (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC)
#if defined(OS_LINUX) && !defined(IS_CHROMECAST)
......@@ -350,23 +357,13 @@ bool InitializeICU() {
#endif // defined(OS_LINUX) && !defined(IS_CHROMECAST)
return result;
}
#endif // !defined(OS_NACL)
void AllowMultipleInitializeCallsForTesting() {
#if DCHECK_IS_ON() && !defined(OS_NACL)
#if DCHECK_IS_ON()
g_check_called_once = false;
#endif
}
#if !defined(OS_NACL)
#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
void ResetGlobalsForTesting() {
g_icudtl_pf = kInvalidPlatformFile;
g_icudtl_mapped_file = nullptr;
g_icudtl_extra_pf = kInvalidPlatformFile;
g_icudtl_extra_mapped_file = nullptr;
}
#endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
#endif // !defined(OS_NACL)
} // namespace i18n
......
......@@ -26,6 +26,7 @@ BASE_I18N_EXPORT bool InitializeICU();
// Loads ICU's extra data tables from disk for the current process. If used must
// be called before InitializeICU().
BASE_I18N_EXPORT bool InitializeExtraICU();
// Returns the PlatformFile and Region that was initialized by InitializeICU()
// or InitializeExtraICU(). Use with InitializeICUWithFileDescriptor() or
// InitializeExtraICUWithFileDescriptor().
......@@ -34,27 +35,24 @@ BASE_I18N_EXPORT PlatformFile GetIcuDataFileHandle(
BASE_I18N_EXPORT PlatformFile
GetIcuExtraDataFileHandle(MemoryMappedFile::Region* out_region);
// Loads ICU extra data file from file descriptor passed by browser process to
// initialize ICU in render processes. If used must be called before
// InitializeICUWithFileDescriptor().
BASE_I18N_EXPORT bool InitializeExtraICUWithFileDescriptor(
PlatformFile data_fd,
const MemoryMappedFile::Region& data_region);
// Loads ICU data file from file descriptor passed by browser process to
// initialize ICU in render processes.
BASE_I18N_EXPORT bool InitializeICUWithFileDescriptor(
PlatformFile data_fd,
const MemoryMappedFile::Region& data_region);
#endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
#endif // !defined(OS_NACL)
// In a test binary, the call above might occur twice.
BASE_I18N_EXPORT void AllowMultipleInitializeCallsForTesting();
// Loads ICU extra data file from file descriptor passed by browser process to
// initialize ICU in render processes. If used must be called before
// InitializeICUWithFileDescriptor().
BASE_I18N_EXPORT bool InitializeExtraICUWithFileDescriptor(
PlatformFile data_fd,
const MemoryMappedFile::Region& data_region);
#if !defined(OS_NACL)
#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
BASE_I18N_EXPORT void ResetGlobalsForTesting();
#endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
// In a test binary, initialize functions might be called twice.
BASE_I18N_EXPORT void AllowMultipleInitializeCallsForTesting();
#endif // !defined(OS_NACL)
} // namespace i18n
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment