Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1075)

Side by Side Diff: base/i18n/icu_util.cc

Issue 1431133003: mandoline: Reland "Fix ICU initialization". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT and then fix compile. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/i18n/icu_util.h ('k') | components/html_viewer/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 137
138 bool InitializeICUWithFileDescriptorInternal( 138 bool InitializeICUWithFileDescriptorInternal(
139 PlatformFile data_fd, 139 PlatformFile data_fd,
140 const MemoryMappedFile::Region& data_region) { 140 const MemoryMappedFile::Region& data_region) {
141 // This can be called multiple times in tests. 141 // This can be called multiple times in tests.
142 if (g_icudtl_mapped_file) { 142 if (g_icudtl_mapped_file) {
143 return true; 143 return true;
144 } 144 }
145 if (data_fd == kInvalidPlatformFile) { 145 if (data_fd == kInvalidPlatformFile) {
146 LOG(ERROR) << "Invalid file descriptor to ICU data received.";
146 return false; 147 return false;
147 } 148 }
148 149
149 scoped_ptr<MemoryMappedFile> icudtl_mapped_file(new MemoryMappedFile()); 150 scoped_ptr<MemoryMappedFile> icudtl_mapped_file(new MemoryMappedFile());
150 if (!icudtl_mapped_file->Initialize(File(data_fd), data_region)) { 151 if (!icudtl_mapped_file->Initialize(File(data_fd), data_region)) {
151 LOG(ERROR) << "Couldn't mmap icu data file"; 152 LOG(ERROR) << "Couldn't mmap icu data file";
152 return false; 153 return false;
153 } 154 }
154 g_icudtl_mapped_file = icudtl_mapped_file.release(); 155 g_icudtl_mapped_file = icudtl_mapped_file.release();
155 156
156 UErrorCode err = U_ZERO_ERROR; 157 UErrorCode err = U_ZERO_ERROR;
157 udata_setCommonData(const_cast<uint8*>(g_icudtl_mapped_file->data()), &err); 158 udata_setCommonData(const_cast<uint8*>(g_icudtl_mapped_file->data()), &err);
158 return err == U_ZERO_ERROR; 159 return err == U_ZERO_ERROR;
159 } 160 }
160 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE 161 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
161 #endif // !defined(OS_NACL) 162 #endif // !defined(OS_NACL)
162 163
163 } // namespace 164 } // namespace
164 165
165 #if !defined(OS_NACL) 166 #if !defined(OS_NACL)
166 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE 167 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
168 #if defined(OS_ANDROID)
167 bool InitializeICUWithFileDescriptor( 169 bool InitializeICUWithFileDescriptor(
168 PlatformFile data_fd, 170 PlatformFile data_fd,
169 const MemoryMappedFile::Region& data_region) { 171 const MemoryMappedFile::Region& data_region) {
170 #if !defined(NDEBUG) 172 #if !defined(NDEBUG)
171 DCHECK(!g_check_called_once || !g_called_once); 173 DCHECK(!g_check_called_once || !g_called_once);
172 g_called_once = true; 174 g_called_once = true;
173 #endif 175 #endif
174 return InitializeICUWithFileDescriptorInternal(data_fd, data_region); 176 return InitializeICUWithFileDescriptorInternal(data_fd, data_region);
175 } 177 }
176 178
177 PlatformFile GetIcuDataFileHandle(MemoryMappedFile::Region* out_region) { 179 PlatformFile GetIcuDataFileHandle(MemoryMappedFile::Region* out_region) {
178 CHECK_NE(g_icudtl_pf, kInvalidPlatformFile); 180 CHECK_NE(g_icudtl_pf, kInvalidPlatformFile);
179 *out_region = g_icudtl_region; 181 *out_region = g_icudtl_region;
180 return g_icudtl_pf; 182 return g_icudtl_pf;
181 } 183 }
184 #endif
185
186 const uint8* GetRawIcuMemory() {
187 CHECK(g_icudtl_mapped_file);
188 return g_icudtl_mapped_file->data();
189 }
190
191 bool InitializeICUFromRawMemory(const uint8* raw_memory) {
192 #if !defined(COMPONENT_BUILD)
193 #if !defined(NDEBUG)
194 DCHECK(!g_check_called_once || !g_called_once);
195 g_called_once = true;
196 #endif
197
198 UErrorCode err = U_ZERO_ERROR;
199 udata_setCommonData(const_cast<uint8*>(raw_memory), &err);
200 return err == U_ZERO_ERROR;
201 #else
202 return true;
203 #endif
204 }
205
182 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE 206 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
183 207
184 bool InitializeICU() { 208 bool InitializeICU() {
185 #if !defined(NDEBUG) 209 #if !defined(NDEBUG)
186 DCHECK(!g_check_called_once || !g_called_once); 210 DCHECK(!g_check_called_once || !g_called_once);
187 g_called_once = true; 211 g_called_once = true;
188 #endif 212 #endif
189 213
190 bool result; 214 bool result;
191 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) 215 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 #endif // !defined(OS_NACL) 264 #endif // !defined(OS_NACL)
241 265
242 void AllowMultipleInitializeCallsForTesting() { 266 void AllowMultipleInitializeCallsForTesting() {
243 #if !defined(NDEBUG) && !defined(OS_NACL) 267 #if !defined(NDEBUG) && !defined(OS_NACL)
244 g_check_called_once = false; 268 g_check_called_once = false;
245 #endif 269 #endif
246 } 270 }
247 271
248 } // namespace i18n 272 } // namespace i18n
249 } // namespace base 273 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/icu_util.h ('k') | components/html_viewer/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698