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 |
11 #include <string> | 11 #include <string> |
12 | 12 |
| 13 #include "base/debug/alias.h" |
13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
14 #include "base/files/memory_mapped_file.h" | 15 #include "base/files/memory_mapped_file.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
19 #include "third_party/icu/source/common/unicode/putil.h" | 20 #include "third_party/icu/source/common/unicode/putil.h" |
20 #include "third_party/icu/source/common/unicode/udata.h" | 21 #include "third_party/icu/source/common/unicode/udata.h" |
21 | 22 |
22 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
(...skipping 18 matching lines...) Expand all Loading... |
41 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" | 42 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" |
42 #endif | 43 #endif |
43 #endif | 44 #endif |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 #if !defined(NDEBUG) | 48 #if !defined(NDEBUG) |
48 // Assert that we are not called more than once. Even though calling this | 49 // Assert that we are not called more than once. Even though calling this |
49 // function isn't harmful (ICU can handle it), being called twice probably | 50 // function isn't harmful (ICU can handle it), being called twice probably |
50 // indicates a programming error. | 51 // indicates a programming error. |
| 52 #if !defined(OS_NACL) |
51 bool g_called_once = false; | 53 bool g_called_once = false; |
| 54 #endif |
52 bool g_check_called_once = true; | 55 bool g_check_called_once = true; |
53 #endif | 56 #endif |
54 } | 57 } |
55 | 58 |
56 #if defined(OS_ANDROID) | 59 #if defined(OS_ANDROID) |
57 bool InitializeICUWithFileDescriptor( | 60 bool InitializeICUWithFileDescriptor( |
58 int data_fd, | 61 int data_fd, |
59 base::MemoryMappedFile::Region data_region) { | 62 base::MemoryMappedFile::Region data_region) { |
60 #if !defined(NDEBUG) | 63 #if !defined(NDEBUG) |
61 DCHECK(!g_check_called_once || !g_called_once); | 64 DCHECK(!g_check_called_once || !g_called_once); |
(...skipping 12 matching lines...) Expand all Loading... |
74 } | 77 } |
75 } | 78 } |
76 UErrorCode err = U_ZERO_ERROR; | 79 UErrorCode err = U_ZERO_ERROR; |
77 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); | 80 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); |
78 return err == U_ZERO_ERROR; | 81 return err == U_ZERO_ERROR; |
79 #endif // ICU_UTIL_DATA_FILE | 82 #endif // ICU_UTIL_DATA_FILE |
80 } | 83 } |
81 #endif | 84 #endif |
82 | 85 |
83 | 86 |
| 87 #if !defined(OS_NACL) |
84 bool InitializeICU() { | 88 bool InitializeICU() { |
85 #if !defined(NDEBUG) | 89 #if !defined(NDEBUG) |
86 DCHECK(!g_check_called_once || !g_called_once); | 90 DCHECK(!g_check_called_once || !g_called_once); |
87 g_called_once = true; | 91 g_called_once = true; |
88 #endif | 92 #endif |
89 | 93 |
90 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) | 94 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) |
91 // We expect to find the ICU data module alongside the current module. | 95 // We expect to find the ICU data module alongside the current module. |
92 FilePath data_path; | 96 FilePath data_path; |
93 PathService::Get(base::DIR_MODULE, &data_path); | 97 PathService::Get(base::DIR_MODULE, &data_path); |
(...skipping 26 matching lines...) Expand all Loading... |
120 | 124 |
121 // Chrome doesn't normally shut down ICU, so the mapped data shouldn't ever | 125 // Chrome doesn't normally shut down ICU, so the mapped data shouldn't ever |
122 // be released. | 126 // be released. |
123 CR_DEFINE_STATIC_LOCAL(base::MemoryMappedFile, mapped_file, ()); | 127 CR_DEFINE_STATIC_LOCAL(base::MemoryMappedFile, mapped_file, ()); |
124 if (!mapped_file.IsValid()) { | 128 if (!mapped_file.IsValid()) { |
125 #if !defined(OS_MACOSX) | 129 #if !defined(OS_MACOSX) |
126 FilePath data_path; | 130 FilePath data_path; |
127 #if defined(OS_WIN) | 131 #if defined(OS_WIN) |
128 // The data file will be in the same directory as the current module. | 132 // The data file will be in the same directory as the current module. |
129 bool path_ok = PathService::Get(base::DIR_MODULE, &data_path); | 133 bool path_ok = PathService::Get(base::DIR_MODULE, &data_path); |
| 134 wchar_t tmp_buffer[_MAX_PATH] = {0}; |
| 135 wcscpy_s(tmp_buffer, data_path.value().c_str()); |
| 136 base::debug::Alias(tmp_buffer); |
| 137 CHECK(path_ok); // TODO(scottmg): http://crbug.com/445616 |
130 #elif defined(OS_ANDROID) | 138 #elif defined(OS_ANDROID) |
131 bool path_ok = PathService::Get(base::DIR_ANDROID_APP_DATA, &data_path); | 139 bool path_ok = PathService::Get(base::DIR_ANDROID_APP_DATA, &data_path); |
132 #else | 140 #else |
133 // For now, expect the data file to be alongside the executable. | 141 // For now, expect the data file to be alongside the executable. |
134 // This is sufficient while we work on unit tests, but will eventually | 142 // This is sufficient while we work on unit tests, but will eventually |
135 // likely live in a data directory. | 143 // likely live in a data directory. |
136 bool path_ok = PathService::Get(base::DIR_EXE, &data_path); | 144 bool path_ok = PathService::Get(base::DIR_EXE, &data_path); |
137 #endif | 145 #endif |
138 DCHECK(path_ok); | 146 DCHECK(path_ok); |
139 data_path = data_path.AppendASCII(kIcuDataFileName); | 147 data_path = data_path.AppendASCII(kIcuDataFileName); |
| 148 |
| 149 #if defined(OS_WIN) |
| 150 // TODO(scottmg): http://crbug.com/445616 |
| 151 wchar_t tmp_buffer2[_MAX_PATH] = {0}; |
| 152 wcscpy_s(tmp_buffer2, data_path.value().c_str()); |
| 153 base::debug::Alias(tmp_buffer2); |
| 154 #endif |
| 155 |
140 #else | 156 #else |
141 // Assume it is in the framework bundle's Resources directory. | 157 // Assume it is in the framework bundle's Resources directory. |
142 base::ScopedCFTypeRef<CFStringRef> data_file_name( | 158 base::ScopedCFTypeRef<CFStringRef> data_file_name( |
143 SysUTF8ToCFStringRef(kIcuDataFileName)); | 159 SysUTF8ToCFStringRef(kIcuDataFileName)); |
144 FilePath data_path = | 160 FilePath data_path = |
145 base::mac::PathForFrameworkBundleResource(data_file_name); | 161 base::mac::PathForFrameworkBundleResource(data_file_name); |
146 if (data_path.empty()) { | 162 if (data_path.empty()) { |
147 LOG(ERROR) << kIcuDataFileName << " not found in bundle"; | 163 LOG(ERROR) << kIcuDataFileName << " not found in bundle"; |
148 return false; | 164 return false; |
149 } | 165 } |
150 #endif // OS check | 166 #endif // OS check |
151 if (!mapped_file.Initialize(data_path)) { | 167 if (!mapped_file.Initialize(data_path)) { |
| 168 #if defined(OS_WIN) |
| 169 CHECK(false); // TODO(scottmg): http://crbug.com/445616 |
| 170 #endif |
152 LOG(ERROR) << "Couldn't mmap " << data_path.AsUTF8Unsafe(); | 171 LOG(ERROR) << "Couldn't mmap " << data_path.AsUTF8Unsafe(); |
153 return false; | 172 return false; |
154 } | 173 } |
155 } | 174 } |
156 UErrorCode err = U_ZERO_ERROR; | 175 UErrorCode err = U_ZERO_ERROR; |
157 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); | 176 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); |
| 177 #if defined(OS_WIN) |
| 178 CHECK(err == U_ZERO_ERROR); // TODO(scottmg): http://crbug.com/445616 |
| 179 #endif |
158 return err == U_ZERO_ERROR; | 180 return err == U_ZERO_ERROR; |
159 #endif | 181 #endif |
160 } | 182 } |
| 183 #endif |
161 | 184 |
162 void AllowMultipleInitializeCallsForTesting() { | 185 void AllowMultipleInitializeCallsForTesting() { |
163 #if !defined(NDEBUG) | 186 #if !defined(NDEBUG) |
164 g_check_called_once = false; | 187 g_check_called_once = false; |
165 #endif | 188 #endif |
166 } | 189 } |
167 | 190 |
168 } // namespace i18n | 191 } // namespace i18n |
169 } // namespace base | 192 } // namespace base |
OLD | NEW |