| 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 #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> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/files/memory_mapped_file.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 20 #include "base/strings/sys_string_conversions.h" | 21 #include "base/strings/sys_string_conversions.h" |
| 21 #include "third_party/icu/public/common/unicode/putil.h" | 22 #include "third_party/icu/public/common/unicode/putil.h" |
| 22 #include "third_party/icu/public/common/unicode/udata.h" | 23 #include "third_party/icu/public/common/unicode/udata.h" |
| 23 | 24 |
| 24 #if defined(OS_MACOSX) | 25 #if defined(OS_MACOSX) |
| 25 #include "base/mac/foundation_util.h" | 26 #include "base/mac/foundation_util.h" |
| 26 #endif | 27 #endif |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 udata_setFileAccess(UDATA_ONLY_PACKAGES, &err); | 105 udata_setFileAccess(UDATA_ONLY_PACKAGES, &err); |
| 105 return err == U_ZERO_ERROR; | 106 return err == U_ZERO_ERROR; |
| 106 #else | 107 #else |
| 107 // If the ICU data directory is set, ICU won't actually load the data until | 108 // If the ICU data directory is set, ICU won't actually load the data until |
| 108 // it is needed. This can fail if the process is sandboxed at that time. | 109 // it is needed. This can fail if the process is sandboxed at that time. |
| 109 // Instead, Mac maps the file in and hands off the data so the sandbox won't | 110 // Instead, Mac maps the file in and hands off the data so the sandbox won't |
| 110 // cause any problems. | 111 // cause any problems. |
| 111 | 112 |
| 112 // Chrome doesn't normally shut down ICU, so the mapped data shouldn't ever | 113 // Chrome doesn't normally shut down ICU, so the mapped data shouldn't ever |
| 113 // be released. | 114 // be released. |
| 114 static file_util::MemoryMappedFile mapped_file; | 115 static base::MemoryMappedFile mapped_file; |
| 115 if (!mapped_file.IsValid()) { | 116 if (!mapped_file.IsValid()) { |
| 116 // Assume it is in the framework bundle's Resources directory. | 117 // Assume it is in the framework bundle's Resources directory. |
| 117 FilePath data_path = | 118 FilePath data_path = |
| 118 base::mac::PathForFrameworkBundleResource(CFSTR(ICU_UTIL_DATA_FILE_NAME)); | 119 base::mac::PathForFrameworkBundleResource(CFSTR(ICU_UTIL_DATA_FILE_NAME)); |
| 119 if (data_path.empty()) { | 120 if (data_path.empty()) { |
| 120 DLOG(ERROR) << ICU_UTIL_DATA_FILE_NAME << " not found in bundle"; | 121 DLOG(ERROR) << ICU_UTIL_DATA_FILE_NAME << " not found in bundle"; |
| 121 return false; | 122 return false; |
| 122 } | 123 } |
| 123 if (!mapped_file.Initialize(data_path)) { | 124 if (!mapped_file.Initialize(data_path)) { |
| 124 DLOG(ERROR) << "Couldn't mmap " << data_path.value(); | 125 DLOG(ERROR) << "Couldn't mmap " << data_path.value(); |
| 125 return false; | 126 return false; |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 UErrorCode err = U_ZERO_ERROR; | 129 UErrorCode err = U_ZERO_ERROR; |
| 129 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); | 130 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); |
| 130 return err == U_ZERO_ERROR; | 131 return err == U_ZERO_ERROR; |
| 131 #endif // OS check | 132 #endif // OS check |
| 132 #endif | 133 #endif |
| 133 } | 134 } |
| 134 | 135 |
| 135 } // namespace icu_util | 136 } // namespace icu_util |
| OLD | NEW |