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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED | 42 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED |
43 #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" | 43 #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" |
44 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
45 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" | 45 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" |
46 #endif | 46 #endif |
47 #endif | 47 #endif |
48 | 48 |
49 namespace { | 49 namespace { |
50 #if !defined(OS_NACL) | 50 #if !defined(OS_NACL) |
51 #if !defined(NDEBUG) | 51 #if DCHECK_IS_ON() |
52 // Assert that we are not called more than once. Even though calling this | 52 // Assert that we are not called more than once. Even though calling this |
53 // function isn't harmful (ICU can handle it), being called twice probably | 53 // function isn't harmful (ICU can handle it), being called twice probably |
54 // indicates a programming error. | 54 // indicates a programming error. |
55 bool g_check_called_once = true; | 55 bool g_check_called_once = true; |
56 bool g_called_once = false; | 56 bool g_called_once = false; |
57 #endif // !defined(NDEBUG) | 57 #endif // DCHECK_IS_ON() |
58 | 58 |
59 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | 59 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE |
60 | 60 |
61 // To debug http://crbug.com/445616. | 61 // To debug http://crbug.com/445616. |
62 int g_debug_icu_last_error; | 62 int g_debug_icu_last_error; |
63 int g_debug_icu_load; | 63 int g_debug_icu_load; |
64 int g_debug_icu_pf_error_details; | 64 int g_debug_icu_pf_error_details; |
65 int g_debug_icu_pf_last_error; | 65 int g_debug_icu_pf_last_error; |
66 #if defined(OS_WIN) | 66 #if defined(OS_WIN) |
67 wchar_t g_debug_icu_pf_filename[_MAX_PATH]; | 67 wchar_t g_debug_icu_pf_filename[_MAX_PATH]; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 #endif // !defined(OS_NACL) | 194 #endif // !defined(OS_NACL) |
195 | 195 |
196 } // namespace | 196 } // namespace |
197 | 197 |
198 #if !defined(OS_NACL) | 198 #if !defined(OS_NACL) |
199 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | 199 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE |
200 #if defined(OS_ANDROID) | 200 #if defined(OS_ANDROID) |
201 bool InitializeICUWithFileDescriptor( | 201 bool InitializeICUWithFileDescriptor( |
202 PlatformFile data_fd, | 202 PlatformFile data_fd, |
203 const MemoryMappedFile::Region& data_region) { | 203 const MemoryMappedFile::Region& data_region) { |
204 #if !defined(NDEBUG) | 204 #if DCHECK_IS_ON() |
205 DCHECK(!g_check_called_once || !g_called_once); | 205 DCHECK(!g_check_called_once || !g_called_once); |
206 g_called_once = true; | 206 g_called_once = true; |
207 #endif | 207 #endif |
208 return InitializeICUWithFileDescriptorInternal(data_fd, data_region); | 208 return InitializeICUWithFileDescriptorInternal(data_fd, data_region); |
209 } | 209 } |
210 | 210 |
211 PlatformFile GetIcuDataFileHandle(MemoryMappedFile::Region* out_region) { | 211 PlatformFile GetIcuDataFileHandle(MemoryMappedFile::Region* out_region) { |
212 CHECK_NE(g_icudtl_pf, kInvalidPlatformFile); | 212 CHECK_NE(g_icudtl_pf, kInvalidPlatformFile); |
213 *out_region = g_icudtl_region; | 213 *out_region = g_icudtl_region; |
214 return g_icudtl_pf; | 214 return g_icudtl_pf; |
215 } | 215 } |
216 #endif | 216 #endif |
217 | 217 |
218 const uint8_t* GetRawIcuMemory() { | 218 const uint8_t* GetRawIcuMemory() { |
219 CHECK(g_icudtl_mapped_file); | 219 CHECK(g_icudtl_mapped_file); |
220 return g_icudtl_mapped_file->data(); | 220 return g_icudtl_mapped_file->data(); |
221 } | 221 } |
222 | 222 |
223 bool InitializeICUFromRawMemory(const uint8_t* raw_memory) { | 223 bool InitializeICUFromRawMemory(const uint8_t* raw_memory) { |
224 #if !defined(COMPONENT_BUILD) | 224 #if !defined(COMPONENT_BUILD) |
225 #if !defined(NDEBUG) | 225 #if DCHECK_IS_ON() |
226 DCHECK(!g_check_called_once || !g_called_once); | 226 DCHECK(!g_check_called_once || !g_called_once); |
227 g_called_once = true; | 227 g_called_once = true; |
228 #endif | 228 #endif |
229 | 229 |
230 UErrorCode err = U_ZERO_ERROR; | 230 UErrorCode err = U_ZERO_ERROR; |
231 udata_setCommonData(const_cast<uint8_t*>(raw_memory), &err); | 231 udata_setCommonData(const_cast<uint8_t*>(raw_memory), &err); |
232 return err == U_ZERO_ERROR; | 232 return err == U_ZERO_ERROR; |
233 #else | 233 #else |
234 return true; | 234 return true; |
235 #endif | 235 #endif |
236 } | 236 } |
237 | 237 |
238 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | 238 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE |
239 | 239 |
240 bool InitializeICU() { | 240 bool InitializeICU() { |
241 #if !defined(NDEBUG) | 241 #if DCHECK_IS_ON() |
242 DCHECK(!g_check_called_once || !g_called_once); | 242 DCHECK(!g_check_called_once || !g_called_once); |
243 g_called_once = true; | 243 g_called_once = true; |
244 #endif | 244 #endif |
245 | 245 |
246 bool result; | 246 bool result; |
247 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) | 247 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) |
248 // We expect to find the ICU data module alongside the current module. | 248 // We expect to find the ICU data module alongside the current module. |
249 FilePath data_path; | 249 FilePath data_path; |
250 PathService::Get(DIR_MODULE, &data_path); | 250 PathService::Get(DIR_MODULE, &data_path); |
251 data_path = data_path.AppendASCII(ICU_UTIL_DATA_SHARED_MODULE_NAME); | 251 data_path = data_path.AppendASCII(ICU_UTIL_DATA_SHARED_MODULE_NAME); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // when requested. | 300 // when requested. |
301 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 301 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
302 if (result) | 302 if (result) |
303 std::unique_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); | 303 std::unique_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); |
304 #endif | 304 #endif |
305 return result; | 305 return result; |
306 } | 306 } |
307 #endif // !defined(OS_NACL) | 307 #endif // !defined(OS_NACL) |
308 | 308 |
309 void AllowMultipleInitializeCallsForTesting() { | 309 void AllowMultipleInitializeCallsForTesting() { |
310 #if !defined(NDEBUG) && !defined(OS_NACL) | 310 #if DCHECK_IS_ON() && !defined(OS_NACL) |
311 g_check_called_once = false; | 311 g_check_called_once = false; |
312 #endif | 312 #endif |
313 } | 313 } |
314 | 314 |
315 } // namespace i18n | 315 } // namespace i18n |
316 } // namespace base | 316 } // namespace base |
OLD | NEW |