Chromium Code Reviews| 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" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #elif ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED | 37 #elif ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED |
| 38 #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" | 38 #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" |
| 39 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 40 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" | 40 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" |
| 41 #endif | 41 #endif |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 namespace base { | 44 namespace base { |
| 45 namespace i18n { | 45 namespace i18n { |
| 46 | 46 |
| 47 namespace { | |
| 48 | |
| 49 #ifndef NDEBUG | |
|
sky
2014/03/14 21:35:56
#if !defined(NDEBUG)
jam
2014/03/14 22:35:40
Done.
| |
| 50 // 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 | |
| 52 // indicates a programming error. | |
| 53 bool g_called_once = false; | |
|
sky
2014/03/14 21:35:56
I'm pretty sure these don't get g_ (just called_on
jam
2014/03/14 22:35:40
really? I see > 1K hits for " g_" in cs
| |
| 54 bool g_check_called_once = true; | |
| 55 #endif | |
| 56 } | |
| 57 | |
| 47 bool InitializeICU() { | 58 bool InitializeICU() { |
| 48 #ifndef NDEBUG | 59 #ifndef NDEBUG |
| 49 // Assert that we are not called more than once. Even though calling this | 60 DCHECK(!g_check_called_once || !g_called_once); |
|
sky
2014/03/14 21:35:56
I'm not familiar with this code. Do you need to wo
jam
2014/03/14 22:35:40
not multiple threads, but multiple initializations
| |
| 50 // function isn't harmful (ICU can handle it), being called twice probably | 61 g_called_once = true; |
| 51 // indicates a programming error. | |
| 52 static bool called_once = false; | |
| 53 DCHECK(!called_once); | |
| 54 called_once = true; | |
| 55 #endif | 62 #endif |
| 56 | 63 |
| 57 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) | 64 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) |
| 58 // We expect to find the ICU data module alongside the current module. | 65 // We expect to find the ICU data module alongside the current module. |
| 59 FilePath data_path; | 66 FilePath data_path; |
| 60 PathService::Get(base::DIR_MODULE, &data_path); | 67 PathService::Get(base::DIR_MODULE, &data_path); |
| 61 data_path = data_path.AppendASCII(ICU_UTIL_DATA_SHARED_MODULE_NAME); | 68 data_path = data_path.AppendASCII(ICU_UTIL_DATA_SHARED_MODULE_NAME); |
| 62 | 69 |
| 63 HMODULE module = LoadLibrary(data_path.value().c_str()); | 70 HMODULE module = LoadLibrary(data_path.value().c_str()); |
| 64 if (!module) { | 71 if (!module) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 DLOG(ERROR) << "Couldn't mmap " << data_path.AsUTF8Unsafe(); | 124 DLOG(ERROR) << "Couldn't mmap " << data_path.AsUTF8Unsafe(); |
| 118 return false; | 125 return false; |
| 119 } | 126 } |
| 120 } | 127 } |
| 121 UErrorCode err = U_ZERO_ERROR; | 128 UErrorCode err = U_ZERO_ERROR; |
| 122 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); | 129 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); |
| 123 return err == U_ZERO_ERROR; | 130 return err == U_ZERO_ERROR; |
| 124 #endif | 131 #endif |
| 125 } | 132 } |
| 126 | 133 |
| 134 void AllowMultipleInitializeCallsForTesting() { | |
| 135 #ifndef NDEBUG | |
|
sky
2014/03/14 21:35:56
#if !defined(NDEBUG)
jam
2014/03/14 22:35:40
Done.
| |
| 136 g_check_called_once = false; | |
| 137 #endif | |
| 138 } | |
| 139 | |
| 127 } // namespace i18n | 140 } // namespace i18n |
| 128 } // namespace base | 141 } // namespace base |
| OLD | NEW |