OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/i18n/icu_util.h" | 5 #include "base/i18n/icu_util.h" |
6 | 6 |
7 #include "build/build_config.h" | |
8 | |
9 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
10 #include <windows.h> | 8 #include <windows.h> |
11 #endif | 9 #endif |
12 | 10 |
13 #include <string> | 11 #include <string> |
14 | 12 |
15 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
16 #include "base/files/memory_mapped_file.h" | 14 #include "base/files/memory_mapped_file.h" |
17 #include "base/logging.h" | 15 #include "base/logging.h" |
18 #include "base/path_service.h" | 16 #include "base/path_service.h" |
(...skipping 29 matching lines...) Expand all Loading... |
48 | 46 |
49 #if !defined(NDEBUG) | 47 #if !defined(NDEBUG) |
50 // Assert that we are not called more than once. Even though calling this | 48 // Assert that we are not called more than once. Even though calling this |
51 // function isn't harmful (ICU can handle it), being called twice probably | 49 // function isn't harmful (ICU can handle it), being called twice probably |
52 // indicates a programming error. | 50 // indicates a programming error. |
53 bool g_called_once = false; | 51 bool g_called_once = false; |
54 bool g_check_called_once = true; | 52 bool g_check_called_once = true; |
55 #endif | 53 #endif |
56 } | 54 } |
57 | 55 |
| 56 |
| 57 #if defined(OS_ANDROID) |
| 58 bool InitializeICUWithFileDescriptor(int data_fd) { |
| 59 #if !defined(NDEBUG) |
| 60 DCHECK(!g_check_called_once || !g_called_once); |
| 61 g_called_once = true; |
| 62 #endif |
| 63 |
| 64 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC) |
| 65 // The ICU data is statically linked. |
| 66 return true; |
| 67 #elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) |
| 68 CR_DEFINE_STATIC_LOCAL(base::MemoryMappedFile, mapped_file, ()); |
| 69 if (!mapped_file.IsValid()) { |
| 70 if (!mapped_file.Initialize(base::File(data_fd))) { |
| 71 LOG(ERROR) << "Couldn't mmap icu data file"; |
| 72 return false; |
| 73 } |
| 74 } |
| 75 UErrorCode err = U_ZERO_ERROR; |
| 76 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); |
| 77 return err == U_ZERO_ERROR; |
| 78 #endif // ICU_UTIL_DATA_FILE |
| 79 } |
| 80 #endif |
| 81 |
| 82 |
58 bool InitializeICU() { | 83 bool InitializeICU() { |
59 #if !defined(NDEBUG) | 84 #if !defined(NDEBUG) |
60 DCHECK(!g_check_called_once || !g_called_once); | 85 DCHECK(!g_check_called_once || !g_called_once); |
61 g_called_once = true; | 86 g_called_once = true; |
62 #endif | 87 #endif |
63 | 88 |
64 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) | 89 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) |
65 // We expect to find the ICU data module alongside the current module. | 90 // We expect to find the ICU data module alongside the current module. |
66 FilePath data_path; | 91 FilePath data_path; |
67 PathService::Get(base::DIR_MODULE, &data_path); | 92 PathService::Get(base::DIR_MODULE, &data_path); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 157 } |
133 | 158 |
134 void AllowMultipleInitializeCallsForTesting() { | 159 void AllowMultipleInitializeCallsForTesting() { |
135 #if !defined(NDEBUG) | 160 #if !defined(NDEBUG) |
136 g_check_called_once = false; | 161 g_check_called_once = false; |
137 #endif | 162 #endif |
138 } | 163 } |
139 | 164 |
140 } // namespace i18n | 165 } // namespace i18n |
141 } // namespace base | 166 } // namespace base |
OLD | NEW |