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

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

Issue 317833006: [ICU] Avoid reading ICU data files in render process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address reviewer's comments Created 6 years, 6 months 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 | Annotate | Revision Log
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 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 #if !defined(NDEBUG) 49 #if !defined(NDEBUG)
50 // Assert that we are not called more than once. Even though calling this 50 // Assert that we are not called more than once. Even though calling this
51 // function isn't harmful (ICU can handle it), being called twice probably 51 // function isn't harmful (ICU can handle it), being called twice probably
52 // indicates a programming error. 52 // indicates a programming error.
53 bool g_called_once = false; 53 bool g_called_once = false;
54 bool g_check_called_once = true; 54 bool g_check_called_once = true;
55 #endif 55 #endif
56 } 56 }
57 57
58
59 #if defined(OS_ANDROID)
60 bool InitializeICU(int data_fd) {
61 #if !defined(NDEBUG)
62 DCHECK(!g_check_called_once || !g_called_once);
63 g_called_once = true;
64 #endif
65
66 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC)
jungshik at Google 2014/06/06 23:07:50 nit: intentation
67 // The ICU data is statically linked.
68 return true;
69 #elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
70 CR_DEFINE_STATIC_LOCAL(base::MemoryMappedFile, mapped_file, ());
71 if (!mapped_file.IsValid()) {
72 if (!mapped_file.Initialize(base::File(data_fd))) {
73 LOG(ERROR) << "Couldn't mmap icu data file";
74 return false;
75 }
76 }
77 UErrorCode err = U_ZERO_ERROR;
78 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err);
79 return err == U_ZERO_ERROR;
80 #endif // ICU_UTIL_DATA_FILE
81 }
82 #endif
83
84
58 bool InitializeICU() { 85 bool InitializeICU() {
59 #if !defined(NDEBUG) 86 #if !defined(NDEBUG)
60 DCHECK(!g_check_called_once || !g_called_once); 87 DCHECK(!g_check_called_once || !g_called_once);
61 g_called_once = true; 88 g_called_once = true;
62 #endif 89 #endif
63 90
64 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED) 91 #if (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED)
65 // We expect to find the ICU data module alongside the current module. 92 // We expect to find the ICU data module alongside the current module.
66 FilePath data_path; 93 FilePath data_path;
67 PathService::Get(base::DIR_MODULE, &data_path); 94 PathService::Get(base::DIR_MODULE, &data_path);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 159 }
133 160
134 void AllowMultipleInitializeCallsForTesting() { 161 void AllowMultipleInitializeCallsForTesting() {
135 #if !defined(NDEBUG) 162 #if !defined(NDEBUG)
136 g_check_called_once = false; 163 g_check_called_once = false;
137 #endif 164 #endif
138 } 165 }
139 166
140 } // namespace i18n 167 } // namespace i18n
141 } // namespace base 168 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698