| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // Assert that we are not called more than once. Even though calling this | 56 // Assert that we are not called more than once. Even though calling this |
| 57 // function isn't harmful (ICU can handle it), being called twice probably | 57 // function isn't harmful (ICU can handle it), being called twice probably |
| 58 // indicates a programming error. | 58 // indicates a programming error. |
| 59 bool g_check_called_once = true; | 59 bool g_check_called_once = true; |
| 60 bool g_called_once = false; | 60 bool g_called_once = false; |
| 61 #endif // !defined(NDEBUG) | 61 #endif // !defined(NDEBUG) |
| 62 | 62 |
| 63 // To debug http://crbug.com/445616. | 63 // To debug http://crbug.com/445616. |
| 64 int g_debug_icu_last_error; | 64 int g_debug_icu_last_error; |
| 65 int g_debug_icu_load; | 65 int g_debug_icu_load; |
| 66 int g_debug_icu_pf_error_details; |
| 66 int g_debug_icu_pf_last_error; | 67 int g_debug_icu_pf_last_error; |
| 67 int g_debug_icu_pf_error_details; | 68 #if defined(OS_WIN) |
| 69 wchar_t g_debug_icu_pf_filename[_MAX_PATH]; |
| 70 #endif // OS_WIN |
| 68 | 71 |
| 69 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | 72 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE |
| 70 // Use an unversioned file name to simplify a icu version update down the road. | 73 // Use an unversioned file name to simplify a icu version update down the road. |
| 71 // No need to change the filename in multiple places (gyp files, windows | 74 // No need to change the filename in multiple places (gyp files, windows |
| 72 // build pkg configurations, etc). 'l' stands for Little Endian. | 75 // build pkg configurations, etc). 'l' stands for Little Endian. |
| 73 // This variable is exported through the header file. | 76 // This variable is exported through the header file. |
| 74 const char kIcuDataFileName[] = "icudtl.dat"; | 77 const char kIcuDataFileName[] = "icudtl.dat"; |
| 75 #if defined(OS_ANDROID) | 78 #if defined(OS_ANDROID) |
| 76 const char kAndroidAssetsIcuDataFileName[] = "assets/icudtl.dat"; | 79 const char kAndroidAssetsIcuDataFileName[] = "assets/icudtl.dat"; |
| 77 #endif | 80 #endif |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 if (data_path.empty()) { | 146 if (data_path.empty()) { |
| 144 LOG(ERROR) << kIcuDataFileName << " not found in bundle"; | 147 LOG(ERROR) << kIcuDataFileName << " not found in bundle"; |
| 145 return; | 148 return; |
| 146 } | 149 } |
| 147 #endif // !defined(OS_MACOSX) | 150 #endif // !defined(OS_MACOSX) |
| 148 File file(data_path, File::FLAG_OPEN | File::FLAG_READ); | 151 File file(data_path, File::FLAG_OPEN | File::FLAG_READ); |
| 149 if (file.IsValid()) { | 152 if (file.IsValid()) { |
| 150 // TODO(scottmg): http://crbug.com/445616. | 153 // TODO(scottmg): http://crbug.com/445616. |
| 151 g_debug_icu_pf_last_error = 0; | 154 g_debug_icu_pf_last_error = 0; |
| 152 g_debug_icu_pf_error_details = 0; | 155 g_debug_icu_pf_error_details = 0; |
| 156 #if defined(OS_WIN) |
| 157 g_debug_icu_pf_filename[0] = 0; |
| 158 #endif // OS_WIN |
| 153 | 159 |
| 154 g_icudtl_pf = file.TakePlatformFile(); | 160 g_icudtl_pf = file.TakePlatformFile(); |
| 155 g_icudtl_region = MemoryMappedFile::Region::kWholeFile; | 161 g_icudtl_region = MemoryMappedFile::Region::kWholeFile; |
| 156 } | 162 } |
| 157 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
| 158 else { | 164 else { |
| 159 // TODO(scottmg): http://crbug.com/445616. | 165 // TODO(scottmg): http://crbug.com/445616. |
| 160 g_debug_icu_pf_last_error = ::GetLastError(); | 166 g_debug_icu_pf_last_error = ::GetLastError(); |
| 161 g_debug_icu_pf_error_details = file.error_details(); | 167 g_debug_icu_pf_error_details = file.error_details(); |
| 168 wcscpy_s(g_debug_icu_pf_filename, data_path.value().c_str()); |
| 162 } | 169 } |
| 163 #endif // OS_WIN | 170 #endif // OS_WIN |
| 164 } | 171 } |
| 165 | 172 |
| 166 bool InitializeICUWithFileDescriptorInternal( | 173 bool InitializeICUWithFileDescriptorInternal( |
| 167 PlatformFile data_fd, | 174 PlatformFile data_fd, |
| 168 const MemoryMappedFile::Region& data_region) { | 175 const MemoryMappedFile::Region& data_region) { |
| 169 // This can be called multiple times in tests. | 176 // This can be called multiple times in tests. |
| 170 if (g_icudtl_mapped_file) { | 177 if (g_icudtl_mapped_file) { |
| 171 g_debug_icu_load = 0; // To debug http://crbug.com/445616. | 178 g_debug_icu_load = 0; // To debug http://crbug.com/445616. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 InitializeICUWithFileDescriptorInternal(g_icudtl_pf, g_icudtl_region); | 289 InitializeICUWithFileDescriptorInternal(g_icudtl_pf, g_icudtl_region); |
| 283 #if defined(OS_WIN) | 290 #if defined(OS_WIN) |
| 284 int debug_icu_load = g_debug_icu_load; | 291 int debug_icu_load = g_debug_icu_load; |
| 285 debug::Alias(&debug_icu_load); | 292 debug::Alias(&debug_icu_load); |
| 286 int debug_icu_last_error = g_debug_icu_last_error; | 293 int debug_icu_last_error = g_debug_icu_last_error; |
| 287 debug::Alias(&debug_icu_last_error); | 294 debug::Alias(&debug_icu_last_error); |
| 288 int debug_icu_pf_last_error = g_debug_icu_pf_last_error; | 295 int debug_icu_pf_last_error = g_debug_icu_pf_last_error; |
| 289 debug::Alias(&debug_icu_pf_last_error); | 296 debug::Alias(&debug_icu_pf_last_error); |
| 290 int debug_icu_pf_error_details = g_debug_icu_pf_error_details; | 297 int debug_icu_pf_error_details = g_debug_icu_pf_error_details; |
| 291 debug::Alias(&debug_icu_pf_error_details); | 298 debug::Alias(&debug_icu_pf_error_details); |
| 299 wchar_t debug_icu_pf_filename[_MAX_PATH] = {0}; |
| 300 wcscpy_s(debug_icu_pf_filename, g_debug_icu_pf_filename); |
| 301 debug::Alias(&debug_icu_pf_filename); |
| 292 CHECK(result); // TODO(scottmg): http://crbug.com/445616 | 302 CHECK(result); // TODO(scottmg): http://crbug.com/445616 |
| 293 #endif | 303 #endif |
| 294 #endif | 304 #endif |
| 295 | 305 |
| 296 // To respond to the timezone change properly, the default timezone | 306 // To respond to the timezone change properly, the default timezone |
| 297 // cache in ICU has to be populated on starting up. | 307 // cache in ICU has to be populated on starting up. |
| 298 // TODO(jungshik): Some callers do not care about tz at all. If necessary, | 308 // TODO(jungshik): Some callers do not care about tz at all. If necessary, |
| 299 // add a boolean argument to this function to init'd the default tz only | 309 // add a boolean argument to this function to init'd the default tz only |
| 300 // when requested. | 310 // when requested. |
| 301 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 311 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 302 if (result) | 312 if (result) |
| 303 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); | 313 scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); |
| 304 #endif | 314 #endif |
| 305 return result; | 315 return result; |
| 306 } | 316 } |
| 307 #endif // !defined(OS_NACL) | 317 #endif // !defined(OS_NACL) |
| 308 | 318 |
| 309 void AllowMultipleInitializeCallsForTesting() { | 319 void AllowMultipleInitializeCallsForTesting() { |
| 310 #if !defined(NDEBUG) && !defined(OS_NACL) | 320 #if !defined(NDEBUG) && !defined(OS_NACL) |
| 311 g_check_called_once = false; | 321 g_check_called_once = false; |
| 312 #endif | 322 #endif |
| 313 } | 323 } |
| 314 | 324 |
| 315 } // namespace i18n | 325 } // namespace i18n |
| 316 } // namespace base | 326 } // namespace base |
| OLD | NEW |