Index: base/i18n/icu_util.cc |
diff --git a/base/i18n/icu_util.cc b/base/i18n/icu_util.cc |
index a9f0b129633cd596934b8cf7d680d1fcca7f7a8a..3e8e0cf47ff728bbcc2235cc9855ad85aa0fcbcb 100644 |
--- a/base/i18n/icu_util.cc |
+++ b/base/i18n/icu_util.cc |
@@ -23,6 +23,10 @@ |
#include "third_party/icu/source/i18n/unicode/timezone.h" |
#endif |
+#if defined(OS_ANDROID) |
+#include "base/android/apk_assets.h" |
+#endif |
+ |
#if defined(OS_MACOSX) |
#include "base/mac/foundation_util.h" |
#endif |
@@ -38,7 +42,11 @@ namespace i18n { |
// No need to change the filename in multiple places (gyp files, windows |
// build pkg configurations, etc). 'l' stands for Little Endian. |
// This variable is exported through the header file. |
+#if defined(OS_ANDROID) |
+const char kIcuDataFileName[] = "assets/icudtl.dat"; |
+#else |
const char kIcuDataFileName[] = "icudtl.dat"; |
+#endif // defined(OS_ANDROID) |
#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED |
#define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" |
#if defined(OS_WIN) |
@@ -47,27 +55,19 @@ const char kIcuDataFileName[] = "icudtl.dat"; |
#endif |
namespace { |
- |
+#if !defined(OS_NACL) |
#if !defined(NDEBUG) |
// 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 |
// indicates a programming error. |
-#if !defined(OS_NACL) |
-bool g_called_once = false; |
-#endif |
bool g_check_called_once = true; |
-#endif |
-} |
+bool g_called_once = false; |
+#endif // !defined(NDEBUG) |
-#if !defined(OS_NACL) |
-bool InitializeICUWithFileDescriptor( |
+ |
+bool InitializeICUWithFileDescriptorInternal( |
PlatformFile data_fd, |
MemoryMappedFile::Region data_region) { |
-#if !defined(NDEBUG) |
- DCHECK(!g_check_called_once || !g_called_once); |
- g_called_once = true; |
-#endif |
- |
#if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC) |
// The ICU data is statically linked. |
return true; |
@@ -84,7 +84,20 @@ bool InitializeICUWithFileDescriptor( |
return err == U_ZERO_ERROR; |
#endif // ICU_UTIL_DATA_FILE |
} |
+#endif // !defined(OS_NACL) |
+ |
+} // namespace |
+#if !defined(OS_NACL) |
+bool InitializeICUWithFileDescriptor( |
+ PlatformFile data_fd, |
+ MemoryMappedFile::Region data_region) { |
+#if !defined(NDEBUG) |
+ DCHECK(!g_check_called_once || !g_called_once); |
+ g_called_once = true; |
+#endif |
+ return InitializeICUWithFileDescriptorInternal(data_fd, data_region); |
+} |
bool InitializeICU() { |
#if !defined(NDEBUG) |
@@ -118,7 +131,12 @@ bool InitializeICU() { |
#elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC) |
// The ICU data is statically linked. |
result = true; |
-#elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) |
+#elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) && defined(OS_ANDROID) |
+ base::MemoryMappedFile::Region region; |
+ int fd = base::android::OpenApkAsset(kIcuDataFileName, ®ion); |
+ CHECK_GE(fd, 0); |
+ result = InitializeICUWithFileDescriptorInternal(fd, region); |
+#elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) && !defined(OS_ANDROID) |
// If the ICU data directory is set, ICU won't actually load the data until |
// it is needed. This can fail if the process is sandboxed at that time. |
// Instead, we map the file in and hand off the data so the sandbox won't |
@@ -137,8 +155,6 @@ bool InitializeICU() { |
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 |
@@ -193,10 +209,10 @@ bool InitializeICU() { |
#endif |
return result; |
} |
-#endif |
+#endif // !defined(OS_NACL) |
void AllowMultipleInitializeCallsForTesting() { |
-#if !defined(NDEBUG) |
+#if !defined(NDEBUG) && !defined(OS_NACL) |
g_check_called_once = false; |
#endif |
} |