forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicu_util.cc
614 lines (550 loc) · 20.9 KB
/
icu_util.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/i18n/icu_util.h"
#if defined(OS_WIN)
#include <windows.h>
#endif
#include <memory>
#include <string>
#include "base/debug/alias.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/metrics_hashes.h"
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "build/build_config.h"
#include "build/chromecast_buildflags.h"
#include "third_party/icu/source/common/unicode/putil.h"
#include "third_party/icu/source/common/unicode/udata.h"
#include "third_party/icu/source/common/unicode/utrace.h"
#if defined(OS_ANDROID)
#include "base/android/apk_assets.h"
#include "base/android/timezone_utils.h"
#endif
#if defined(OS_IOS)
#include "base/ios/ios_util.h"
#endif
#if defined(OS_APPLE)
#include "base/mac/foundation_util.h"
#endif
#if defined(OS_FUCHSIA)
#include "base/fuchsia/intl_profile_watcher.h"
#endif
#if defined(OS_ANDROID) || defined(OS_FUCHSIA)
#include "third_party/icu/source/common/unicode/unistr.h"
#endif
#if defined(OS_ANDROID) || defined(OS_FUCHSIA) || \
((defined(OS_LINUX) || defined(OS_CHROMEOS)) && !BUILDFLAG(IS_CHROMECAST))
#include "third_party/icu/source/i18n/unicode/timezone.h"
#endif
namespace base {
namespace i18n {
#if !defined(OS_NACL)
namespace {
#if DCHECK_IS_ON()
// Assert that we are not called more than once. Even though calling this
// function isn't harmful (ICU can handle it), being called twice probably
// indicates a programming error.
bool g_check_called_once = true;
bool g_called_once = false;
#endif // DCHECK_IS_ON()
#if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
// To debug http://crbug.com/445616.
int g_debug_icu_last_error;
int g_debug_icu_load;
int g_debug_icu_pf_error_details;
int g_debug_icu_pf_last_error;
#if defined(OS_WIN)
wchar_t g_debug_icu_pf_filename[_MAX_PATH];
#endif // OS_WIN
// Use an unversioned file name to simplify a icu version update down the road.
// No need to change the filename in multiple places (gyp files, windows
// build pkg configurations, etc). 'l' stands for Little Endian.
// This variable is exported through the header file.
const char kIcuDataFileName[] = "icudtl.dat";
const char kIcuExtraDataFileName[] = "icudtl_extra.dat";
// Time zone data loading.
// For now, only Fuchsia has a meaningful use case for this feature, so it is
// only implemented for OS_FUCHSIA.
#if defined(OS_FUCHSIA)
// The environment variable used to point the ICU data loader to the directory
// containing time zone data. This is available from ICU version 54. The env
// variable approach is antiquated by today's standards (2019), but is the
// recommended way to configure ICU.
//
// See for details: http://userguide.icu-project.org/datetime/timezone
const char kIcuTimeZoneEnvVariable[] = "ICU_TIMEZONE_FILES_DIR";
// We assume that Fuchsia will provide time zone data at this path for Chromium
// to load, and that the path will be timely updated when Fuchsia needs to
// uprev the ICU version it is using. There are unit tests that will fail at
// Fuchsia roll time in case either Chromium or Fuchsia get upgraded to
// mutually incompatible ICU versions. That should be enough to alert the
// developers of the need to keep ICU library versions in ICU and Fuchsia in
// reasonable sync.
const char kIcuTimeZoneDataDir[] = "/config/data/tzdata/icu/44/le";
#endif // defined(OS_FUCHSIA)
#if defined(OS_ANDROID)
const char kAssetsPathPrefix[] = "assets/";
#endif // defined(OS_ANDROID)
// File handle intentionally never closed. Not using File here because its
// Windows implementation guards against two instances owning the same
// PlatformFile (which we allow since we know it is never freed).
PlatformFile g_icudtl_pf = kInvalidPlatformFile;
MemoryMappedFile* g_icudtl_mapped_file = nullptr;
MemoryMappedFile::Region g_icudtl_region;
PlatformFile g_icudtl_extra_pf = kInvalidPlatformFile;
MemoryMappedFile* g_icudtl_extra_mapped_file = nullptr;
MemoryMappedFile::Region g_icudtl_extra_region;
#if defined(OS_FUCHSIA)
// The directory from which the ICU data loader will be configured to load time
// zone data. It is only changed by SetIcuTimeZoneDataDirForTesting().
const char* g_icu_time_zone_data_dir = kIcuTimeZoneDataDir;
#endif // defined(OS_FUCHSIA)
struct PfRegion {
public:
PlatformFile pf;
MemoryMappedFile::Region region;
};
std::unique_ptr<PfRegion> OpenIcuDataFile(const std::string& filename,
const std::string& split_name) {
auto result = std::make_unique<PfRegion>();
#if defined(OS_ANDROID)
result->pf = android::OpenApkAsset(kAssetsPathPrefix + filename, split_name,
&result->region);
if (result->pf != -1) {
return result;
}
#endif // defined(OS_ANDROID)
// For unit tests, data file is located on disk, so try there as a fallback.
#if !defined(OS_APPLE)
FilePath data_path;
if (!PathService::Get(DIR_ASSETS, &data_path)) {
LOG(ERROR) << "Can't find " << filename;
return nullptr;
}
#if defined(OS_WIN)
// TODO(brucedawson): http://crbug.com/445616
wchar_t tmp_buffer[_MAX_PATH] = {0};
wcscpy_s(tmp_buffer, data_path.value().c_str());
debug::Alias(tmp_buffer);
#endif
data_path = data_path.AppendASCII(filename);
#if defined(OS_WIN)
// TODO(brucedawson): http://crbug.com/445616
wchar_t tmp_buffer2[_MAX_PATH] = {0};
wcscpy_s(tmp_buffer2, data_path.value().c_str());
debug::Alias(tmp_buffer2);
#endif
#else // !defined(OS_APPLE)
// Assume it is in the framework bundle's Resources directory.
ScopedCFTypeRef<CFStringRef> data_file_name(SysUTF8ToCFStringRef(filename));
FilePath data_path = mac::PathForFrameworkBundleResource(data_file_name);
#if defined(OS_IOS)
FilePath override_data_path = ios::FilePathOfEmbeddedICU();
if (!override_data_path.empty()) {
data_path = override_data_path;
}
#endif // !defined(OS_IOS)
if (data_path.empty()) {
LOG(ERROR) << filename << " not found in bundle";
return nullptr;
}
#endif // !defined(OS_APPLE)
File file(data_path, File::FLAG_OPEN | File::FLAG_READ);
if (file.IsValid()) {
// TODO(brucedawson): http://crbug.com/445616.
g_debug_icu_pf_last_error = 0;
g_debug_icu_pf_error_details = 0;
#if defined(OS_WIN)
g_debug_icu_pf_filename[0] = 0;
#endif // OS_WIN
result->pf = file.TakePlatformFile();
result->region = MemoryMappedFile::Region::kWholeFile;
}
#if defined(OS_WIN)
else {
// TODO(brucedawson): http://crbug.com/445616.
g_debug_icu_pf_last_error = ::GetLastError();
g_debug_icu_pf_error_details = file.error_details();
wcscpy_s(g_debug_icu_pf_filename, data_path.value().c_str());
}
#endif // OS_WIN
return result;
}
void LazyOpenIcuDataFile() {
if (g_icudtl_pf != kInvalidPlatformFile) {
return;
}
auto pf_region = OpenIcuDataFile(kIcuDataFileName, std::string());
if (!pf_region) {
return;
}
g_icudtl_pf = pf_region->pf;
g_icudtl_region = pf_region->region;
}
// Configures ICU to load external time zone data, if appropriate.
void InitializeExternalTimeZoneData() {
#if defined(OS_FUCHSIA)
if (!base::DirectoryExists(base::FilePath(g_icu_time_zone_data_dir))) {
// TODO(https://crbug.com/1061262): Make this FATAL unless expected.
PLOG(WARNING) << "Could not open: '" << g_icu_time_zone_data_dir
<< "'. Using built-in timezone database";
return;
}
// Set the environment variable to override the location used by ICU.
// Loading can still fail if the directory is empty or its data is invalid.
std::unique_ptr<base::Environment> env = base::Environment::Create();
env->SetVar(kIcuTimeZoneEnvVariable, g_icu_time_zone_data_dir);
#endif // defined(OS_FUCHSIA)
}
int LoadIcuData(PlatformFile data_fd,
const MemoryMappedFile::Region& data_region,
std::unique_ptr<MemoryMappedFile>* out_mapped_data_file,
UErrorCode* out_error_code) {
InitializeExternalTimeZoneData();
if (data_fd == kInvalidPlatformFile) {
LOG(ERROR) << "Invalid file descriptor to ICU data received.";
return 1; // To debug http://crbug.com/445616.
}
*out_mapped_data_file = std::make_unique<MemoryMappedFile>();
if (!(*out_mapped_data_file)->Initialize(File(data_fd), data_region)) {
LOG(ERROR) << "Couldn't mmap icu data file";
return 2; // To debug http://crbug.com/445616.
}
(*out_error_code) = U_ZERO_ERROR;
udata_setCommonData(const_cast<uint8_t*>((*out_mapped_data_file)->data()),
out_error_code);
if (U_FAILURE(*out_error_code)) {
LOG(ERROR) << "Failed to initialize ICU with data file: "
<< u_errorName(*out_error_code);
return 3; // To debug http://crbug.com/445616.
}
return 0;
}
bool InitializeICUWithFileDescriptorInternal(
PlatformFile data_fd,
const MemoryMappedFile::Region& data_region) {
// This can be called multiple times in tests.
if (g_icudtl_mapped_file) {
g_debug_icu_load = 0; // To debug http://crbug.com/445616.
return true;
}
std::unique_ptr<MemoryMappedFile> mapped_file;
UErrorCode err;
g_debug_icu_load = LoadIcuData(data_fd, data_region, &mapped_file, &err);
if (g_debug_icu_load == 1 || g_debug_icu_load == 2) {
return false;
}
g_icudtl_mapped_file = mapped_file.release();
if (g_debug_icu_load == 3) {
g_debug_icu_last_error = err;
}
// Never try to load ICU data from files.
udata_setFileAccess(UDATA_ONLY_PACKAGES, &err);
return U_SUCCESS(err);
}
bool InitializeICUFromDataFile() {
// If the ICU data directory is set, ICU won't actually load the data until
// it is needed. This can fail if the process is sandboxed at that time.
// Instead, we map the file in and hand off the data so the sandbox won't
// cause any problems.
LazyOpenIcuDataFile();
bool result =
InitializeICUWithFileDescriptorInternal(g_icudtl_pf, g_icudtl_region);
#if defined(OS_WIN)
int debug_icu_load = g_debug_icu_load;
debug::Alias(&debug_icu_load);
int debug_icu_last_error = g_debug_icu_last_error;
debug::Alias(&debug_icu_last_error);
int debug_icu_pf_last_error = g_debug_icu_pf_last_error;
debug::Alias(&debug_icu_pf_last_error);
int debug_icu_pf_error_details = g_debug_icu_pf_error_details;
debug::Alias(&debug_icu_pf_error_details);
wchar_t debug_icu_pf_filename[_MAX_PATH] = {0};
wcscpy_s(debug_icu_pf_filename, g_debug_icu_pf_filename);
debug::Alias(&debug_icu_pf_filename);
CHECK(result); // TODO(brucedawson): http://crbug.com/445616
#endif // defined(OS_WIN)
return result;
}
#endif // (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
// Explicitly initialize ICU's time zone if necessary.
// On some platforms, the time zone must be explicitly initialized zone rather
// than relying on ICU's internal initialization.
void InitializeIcuTimeZone() {
#if defined(OS_ANDROID)
// On Android, we can't leave it up to ICU to set the default time zone
// because ICU's time zone detection does not work in many time zones (e.g.
// Australia/Sydney, Asia/Seoul, Europe/Paris ). Use JNI to detect the host
// time zone and set the ICU default time zone accordingly in advance of
// actual use. See crbug.com/722821 and
// https://ssl.icu-project.org/trac/ticket/13208 .
std::u16string zone_id = android::GetDefaultTimeZoneId();
icu::TimeZone::adoptDefault(icu::TimeZone::createTimeZone(
icu::UnicodeString(false, zone_id.data(), zone_id.length())));
#elif defined(OS_FUCHSIA)
// The platform-specific mechanisms used by ICU's detectHostTimeZone() to
// determine the default time zone will not work on Fuchsia. Therefore,
// proactively set the default system.
// This is also required by TimeZoneMonitorFuchsia::ProfileMayHaveChanged(),
// which uses the current default to detect whether the time zone changed in
// the new profile.
// If the system time zone cannot be obtained or is not understood by ICU,
// the "unknown" time zone will be returned by createTimeZone() and used.
std::string zone_id =
FuchsiaIntlProfileWatcher::GetPrimaryTimeZoneIdForIcuInitialization();
icu::TimeZone::adoptDefault(
icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(zone_id)));
#elif (defined(OS_LINUX) || defined(OS_CHROMEOS)) && !BUILDFLAG(IS_CHROMECAST)
// To respond to the time zone change properly, the default time zone
// cache in ICU has to be populated on starting up.
// See TimeZoneMonitorLinux::NotifyClientsFromImpl().
std::unique_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault());
#endif // defined(OS_ANDROID)
}
const char kICUDataFile[] = "ICU.DataFile";
const char kICUCreateInstance[] = "ICU.CreateInstance";
enum class ICUCreateInstance {
kCharacterBreakIterator = 0,
kWordBreakIterator = 1,
kLineBreakIterator = 2,
kLineBreakIteratorTypeLoose = 3,
kLineBreakIteratorTypeNormal = 4,
kLineBreakIteratorTypeStrict = 5,
kSentenceBreakIterator = 6,
kTitleBreakIterator = 7,
kThaiBreakEngine = 8,
kLaoBreakEngine = 9,
kBurmeseBreakEngine = 10,
kKhmerBreakEngine = 11,
kChineseJapaneseBreakEngine = 12,
kMaxValue = kChineseJapaneseBreakEngine
};
// Callback functions to report the opening of ICU Data File, and creation of
// key objects to UMA. This help us to understand what built-in ICU data files
// are rarely used in the user's machines and the distribution of ICU usage.
static void U_CALLCONV TraceICUEntry(const void*, int32_t fn_number) {
switch (fn_number) {
case UTRACE_UBRK_CREATE_CHARACTER:
base::UmaHistogramEnumeration(kICUCreateInstance,
ICUCreateInstance::kCharacterBreakIterator);
break;
case UTRACE_UBRK_CREATE_SENTENCE:
base::UmaHistogramEnumeration(kICUCreateInstance,
ICUCreateInstance::kSentenceBreakIterator);
break;
case UTRACE_UBRK_CREATE_TITLE:
base::UmaHistogramEnumeration(kICUCreateInstance,
ICUCreateInstance::kTitleBreakIterator);
break;
case UTRACE_UBRK_CREATE_WORD:
base::UmaHistogramEnumeration(kICUCreateInstance,
ICUCreateInstance::kWordBreakIterator);
break;
default:
return;
}
}
static void U_CALLCONV TraceICUData(const void* context,
int32_t fn_number,
int32_t level,
const char* fmt,
va_list args) {
switch (fn_number) {
case UTRACE_UDATA_DATA_FILE: {
std::string icu_data_file_name(va_arg(args, const char*));
va_end(args);
// Skip icu version specified prefix if exist.
// path is prefixed with icu version prefix such as "icudt65l-".
// Histogram only the part after the -.
if (icu_data_file_name.find("icudt") == 0) {
size_t dash = icu_data_file_name.find("-");
if (dash != std::string::npos) {
icu_data_file_name = icu_data_file_name.substr(dash + 1);
}
}
// UmaHistogramSparse should track less than 100 values.
// We currently have about total 55 built-in data files inside ICU
// so it fit the UmaHistogramSparse usage.
int hash = base::HashMetricName(icu_data_file_name);
base::UmaHistogramSparse(kICUDataFile, hash);
return;
}
case UTRACE_UBRK_CREATE_LINE: {
const char* lb_type = va_arg(args, const char*);
va_end(args);
ICUCreateInstance value;
switch (lb_type[0]) {
case '\0':
value = ICUCreateInstance::kLineBreakIterator;
break;
case 'l':
DCHECK(strcmp(lb_type, "loose") == 0);
value = ICUCreateInstance::kLineBreakIteratorTypeLoose;
break;
case 'n':
DCHECK(strcmp(lb_type, "normal") == 0);
value = ICUCreateInstance::kLineBreakIteratorTypeNormal;
break;
case 's':
DCHECK(strcmp(lb_type, "strict") == 0);
value = ICUCreateInstance::kLineBreakIteratorTypeStrict;
break;
default:
return;
}
base::UmaHistogramEnumeration(kICUCreateInstance, value);
return;
}
case UTRACE_UBRK_CREATE_BREAK_ENGINE: {
const char* script = va_arg(args, const char*);
va_end(args);
ICUCreateInstance value;
switch (script[0]) {
case 'H':
DCHECK(strcmp(script, "Hani") == 0);
value = ICUCreateInstance::kChineseJapaneseBreakEngine;
break;
case 'K':
DCHECK(strcmp(script, "Khmr") == 0);
value = ICUCreateInstance::kKhmerBreakEngine;
break;
case 'L':
DCHECK(strcmp(script, "Laoo") == 0);
value = ICUCreateInstance::kLaoBreakEngine;
break;
case 'M':
DCHECK(strcmp(script, "Mymr") == 0);
value = ICUCreateInstance::kBurmeseBreakEngine;
break;
case 'T':
DCHECK(strcmp(script, "Thai") == 0);
value = ICUCreateInstance::kThaiBreakEngine;
break;
default:
return;
}
base::UmaHistogramEnumeration(kICUCreateInstance, value);
return;
}
}
}
// Common initialization to run regardless of how ICU is initialized.
// There are multiple exposed InitializeIcu* functions. This should be called
// as at the end of (the last functions in the sequence of) these functions.
bool DoCommonInitialization() {
// TODO(jungshik): Some callers do not care about tz at all. If necessary,
// add a boolean argument to this function to init the default tz only
// when requested.
InitializeIcuTimeZone();
const void* context = nullptr;
utrace_setFunctions(context, TraceICUEntry, nullptr, TraceICUData);
utrace_setLevel(UTRACE_VERBOSE);
return true;
}
} // namespace
#if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
bool InitializeExtraICUWithFileDescriptor(
PlatformFile data_fd,
const MemoryMappedFile::Region& data_region) {
if (g_icudtl_pf != kInvalidPlatformFile) {
// Must call InitializeExtraICUWithFileDescriptor() before
// InitializeICUWithFileDescriptor().
return false;
}
std::unique_ptr<MemoryMappedFile> mapped_file;
UErrorCode err;
if (LoadIcuData(data_fd, data_region, &mapped_file, &err) != 0) {
return false;
}
g_icudtl_extra_mapped_file = mapped_file.release();
return true;
}
bool InitializeICUWithFileDescriptor(
PlatformFile data_fd,
const MemoryMappedFile::Region& data_region) {
#if DCHECK_IS_ON()
DCHECK(!g_check_called_once || !g_called_once);
g_called_once = true;
#endif
if (!InitializeICUWithFileDescriptorInternal(data_fd, data_region))
return false;
return DoCommonInitialization();
}
PlatformFile GetIcuDataFileHandle(MemoryMappedFile::Region* out_region) {
CHECK_NE(g_icudtl_pf, kInvalidPlatformFile);
*out_region = g_icudtl_region;
return g_icudtl_pf;
}
PlatformFile GetIcuExtraDataFileHandle(MemoryMappedFile::Region* out_region) {
if (g_icudtl_extra_pf == kInvalidPlatformFile) {
return kInvalidPlatformFile;
}
*out_region = g_icudtl_extra_region;
return g_icudtl_extra_pf;
}
bool InitializeExtraICU(const std::string& split_name) {
if (g_icudtl_pf != kInvalidPlatformFile) {
// Must call InitializeExtraICU() before InitializeICU().
return false;
}
auto pf_region = OpenIcuDataFile(kIcuExtraDataFileName, split_name);
if (!pf_region) {
return false;
}
g_icudtl_extra_pf = pf_region->pf;
g_icudtl_extra_region = pf_region->region;
std::unique_ptr<MemoryMappedFile> mapped_file;
UErrorCode err;
if (LoadIcuData(g_icudtl_extra_pf, g_icudtl_extra_region, &mapped_file,
&err) != 0) {
return false;
}
g_icudtl_extra_mapped_file = mapped_file.release();
return true;
}
void ResetGlobalsForTesting() {
g_icudtl_pf = kInvalidPlatformFile;
g_icudtl_mapped_file = nullptr;
g_icudtl_extra_pf = kInvalidPlatformFile;
g_icudtl_extra_mapped_file = nullptr;
#if defined(OS_FUCHSIA)
g_icu_time_zone_data_dir = kIcuTimeZoneDataDir;
#endif // defined(OS_FUCHSIA)
}
#if defined(OS_FUCHSIA)
// |dir| must remain valid until ResetGlobalsForTesting() is called.
void SetIcuTimeZoneDataDirForTesting(const char* dir) {
g_icu_time_zone_data_dir = dir;
}
#endif // defined(OS_FUCHSIA)
#endif // (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
bool InitializeICU() {
#if DCHECK_IS_ON()
DCHECK(!g_check_called_once || !g_called_once);
g_called_once = true;
#endif
#if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC)
// The ICU data is statically linked.
#elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
if (!InitializeICUFromDataFile())
return false;
#else
#error Unsupported ICU_UTIL_DATA_IMPL value
#endif // (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC)
return DoCommonInitialization();
}
void AllowMultipleInitializeCallsForTesting() {
#if DCHECK_IS_ON()
g_check_called_once = false;
#endif
}
#endif // !defined(OS_NACL)
} // namespace i18n
} // namespace base