| Index: base/i18n/icu_util.cc
|
| diff --git a/base/i18n/icu_util.cc b/base/i18n/icu_util.cc
|
| index 1dd54cd606d8b750663a471b4efd277e5ec4980f..0adb4d0fbb6d239e45c575a9a22e382983600b12 100644
|
| --- a/base/i18n/icu_util.cc
|
| +++ b/base/i18n/icu_util.cc
|
| @@ -82,57 +82,10 @@ void LazyInitIcuDataFile() {
|
| if (g_icudtl_pf != kInvalidPlatformFile) {
|
| return;
|
| }
|
| -#if defined(OS_ANDROID)
|
| - int fd = base::android::OpenApkAsset(kAndroidAssetsIcuDataFileName,
|
| - &g_icudtl_region);
|
| - g_icudtl_pf = fd;
|
| - if (fd != -1) {
|
| - return;
|
| - }
|
| -// For unit tests, data file is located on disk, so try there as a fallback.
|
| -#endif // defined(OS_ANDROID)
|
| -#if !defined(OS_MACOSX)
|
| - FilePath data_path;
|
| -#if defined(OS_WIN)
|
| - // The data file will be in the same directory as the current module.
|
| - bool path_ok = PathService::Get(DIR_MODULE, &data_path);
|
| - wchar_t tmp_buffer[_MAX_PATH] = {0};
|
| - wcscpy_s(tmp_buffer, data_path.value().c_str());
|
| - debug::Alias(tmp_buffer);
|
| - CHECK(path_ok); // TODO(scottmg): http://crbug.com/445616
|
| -#elif defined(OS_ANDROID)
|
| - bool path_ok = PathService::Get(DIR_ANDROID_APP_DATA, &data_path);
|
| -#else
|
| - // For now, expect the data file to be alongside the executable.
|
| - // This is sufficient while we work on unit tests, but will eventually
|
| - // likely live in a data directory.
|
| - bool path_ok = PathService::Get(DIR_EXE, &data_path);
|
| -#endif
|
| - DCHECK(path_ok);
|
| - data_path = data_path.AppendASCII(kIcuDataFileName);
|
|
|
| -#if defined(OS_WIN)
|
| - // TODO(scottmg): http://crbug.com/445616
|
| - wchar_t tmp_buffer2[_MAX_PATH] = {0};
|
| - wcscpy_s(tmp_buffer2, data_path.value().c_str());
|
| - debug::Alias(tmp_buffer2);
|
| -#endif
|
| -
|
| -#else
|
| - // Assume it is in the framework bundle's Resources directory.
|
| - ScopedCFTypeRef<CFStringRef> data_file_name(
|
| - SysUTF8ToCFStringRef(kIcuDataFileName));
|
| - FilePath data_path = mac::PathForFrameworkBundleResource(data_file_name);
|
| - if (data_path.empty()) {
|
| - LOG(ERROR) << kIcuDataFileName << " not found in bundle";
|
| - return;
|
| - }
|
| -#endif // !defined(OS_MACOSX)
|
| - File file(data_path, File::FLAG_OPEN | File::FLAG_READ);
|
| - if (file.IsValid()) {
|
| - g_icudtl_pf = file.TakePlatformFile();
|
| + g_icudtl_pf = OpenIcuDataFile();
|
| + if (g_icudtl_pf != kInvalidPlatformFile)
|
| g_icudtl_region = MemoryMappedFile::Region::kWholeFile;
|
| - }
|
| }
|
|
|
| bool InitializeICUWithFileDescriptorInternal(
|
| @@ -181,6 +134,58 @@ PlatformFile GetIcuDataFileHandle(MemoryMappedFile::Region* out_region) {
|
| }
|
| #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
|
|
|
| +PlatformFile OpenIcuDataFile() {
|
| +#if defined(OS_ANDROID)
|
| + int fd = base::android::OpenApkAsset(kAndroidAssetsIcuDataFileName,
|
| + &g_icudtl_region);
|
| + if (fd != -1)
|
| + return fd;
|
| +// For unit tests, data file is located on disk, so try there as a fallback.
|
| +#endif // defined(OS_ANDROID)
|
| +#if !defined(OS_MACOSX)
|
| + FilePath data_path;
|
| +#if defined(OS_WIN)
|
| + // The data file will be in the same directory as the current module.
|
| + bool path_ok = PathService::Get(DIR_MODULE, &data_path);
|
| + wchar_t tmp_buffer[_MAX_PATH] = {0};
|
| + wcscpy_s(tmp_buffer, data_path.value().c_str());
|
| + debug::Alias(tmp_buffer);
|
| + CHECK(path_ok); // TODO(scottmg): http://crbug.com/445616
|
| +#elif defined(OS_ANDROID)
|
| + bool path_ok = PathService::Get(DIR_ANDROID_APP_DATA, &data_path);
|
| +#else
|
| + // For now, expect the data file to be alongside the executable.
|
| + // This is sufficient while we work on unit tests, but will eventually
|
| + // likely live in a data directory.
|
| + bool path_ok = PathService::Get(DIR_EXE, &data_path);
|
| +#endif
|
| + DCHECK(path_ok);
|
| + data_path = data_path.AppendASCII(kIcuDataFileName);
|
| +
|
| +#if defined(OS_WIN)
|
| + // TODO(scottmg): http://crbug.com/445616
|
| + wchar_t tmp_buffer2[_MAX_PATH] = {0};
|
| + wcscpy_s(tmp_buffer2, data_path.value().c_str());
|
| + debug::Alias(tmp_buffer2);
|
| +#endif
|
| +
|
| +#else
|
| + // Assume it is in the framework bundle's Resources directory.
|
| + ScopedCFTypeRef<CFStringRef> data_file_name(
|
| + SysUTF8ToCFStringRef(kIcuDataFileName));
|
| + FilePath data_path = mac::PathForFrameworkBundleResource(data_file_name);
|
| + if (data_path.empty()) {
|
| + LOG(ERROR) << kIcuDataFileName << " not found in bundle";
|
| + return kInvalidPlatformFile;
|
| + }
|
| +#endif // !defined(OS_MACOSX)
|
| + File file(data_path, File::FLAG_OPEN | File::FLAG_READ);
|
| + if (file.IsValid())
|
| + return file.TakePlatformFile();
|
| +
|
| + return kInvalidPlatformFile;
|
| +}
|
| +
|
| bool InitializeICU() {
|
| #if !defined(NDEBUG)
|
| DCHECK(!g_check_called_once || !g_called_once);
|
|
|