Upload upstream chromium 67.0.3396
[platform/framework/web/chromium-efl.git] / base / i18n / icu_util.h
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_I18N_ICU_UTIL_H_
6 #define BASE_I18N_ICU_UTIL_H_
7
8 #include <stdint.h>
9
10 #include "base/files/memory_mapped_file.h"
11 #include "base/i18n/base_i18n_export.h"
12 #include "build/build_config.h"
13
14 #define ICU_UTIL_DATA_FILE   0
15 #define ICU_UTIL_DATA_SHARED 1
16 #define ICU_UTIL_DATA_STATIC 2
17
18 namespace base {
19 namespace i18n {
20
21 #if !defined(OS_NACL)
22 // Call this function to load ICU's data tables for the current process.  This
23 // function should be called before ICU is used.
24 BASE_I18N_EXPORT bool InitializeICU();
25
26 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
27 #if defined(OS_ANDROID)
28 // Returns the PlatformFile and Region that was initialized by InitializeICU().
29 // Use with InitializeICUWithFileDescriptor().
30 BASE_I18N_EXPORT PlatformFile GetIcuDataFileHandle(
31     MemoryMappedFile::Region* out_region);
32
33 // Android uses a file descriptor passed by browser process to initialize ICU
34 // in render processes.
35 BASE_I18N_EXPORT bool InitializeICUWithFileDescriptor(
36     PlatformFile data_fd,
37     const MemoryMappedFile::Region& data_region);
38 #endif
39
40 // Returns a void pointer to the memory mapped ICU data file.
41 //
42 // There are cases on Android where we would be unsafely reusing a file
43 // descriptor within the same process when initializing two copies of ICU from
44 // different binaries in the same address space. This returns an unowned
45 // pointer to the memory mapped icu data file; consumers copies of base must
46 // not outlive the copy of base that owns the memory mapped file.
47 BASE_I18N_EXPORT const uint8_t* GetRawIcuMemory();
48
49 // Initializes ICU memory
50 //
51 // This does nothing in component builds; this initialization should only be
52 // done in cases where there could be two copies of base in a single process in
53 // non-component builds. (The big example is standalone service libraries: the
54 // Service Manager will have a copy of base linked in, and the majority of
55 // service libraries will have base linked in but in non-component builds,
56 // these will be separate copies of base.)
57 BASE_I18N_EXPORT bool InitializeICUFromRawMemory(const uint8_t* raw_memory);
58 #endif  // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
59 #endif  // !defined(OS_NACL)
60
61 // In a test binary, the call above might occur twice.
62 BASE_I18N_EXPORT void AllowMultipleInitializeCallsForTesting();
63
64 }  // namespace i18n
65 }  // namespace base
66
67 #endif  // BASE_I18N_ICU_UTIL_H_