| 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> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // If the ICU data directory is set, ICU won't actually load the data until | 83 // If the ICU data directory is set, ICU won't actually load the data until |
| 84 // it is needed. This can fail if the process is sandboxed at that time. | 84 // it is needed. This can fail if the process is sandboxed at that time. |
| 85 // Instead, we map the file in and hand off the data so the sandbox won't | 85 // Instead, we map the file in and hand off the data so the sandbox won't |
| 86 // cause any problems. | 86 // cause any problems. |
| 87 | 87 |
| 88 // Chrome doesn't normally shut down ICU, so the mapped data shouldn't ever | 88 // Chrome doesn't normally shut down ICU, so the mapped data shouldn't ever |
| 89 // be released. | 89 // be released. |
| 90 CR_DEFINE_STATIC_LOCAL(base::MemoryMappedFile, mapped_file, ()); | 90 CR_DEFINE_STATIC_LOCAL(base::MemoryMappedFile, mapped_file, ()); |
| 91 if (!mapped_file.IsValid()) { | 91 if (!mapped_file.IsValid()) { |
| 92 #if !defined(OS_MACOSX) | 92 #if !defined(OS_MACOSX) |
| 93 FilePath data_path; |
| 94 #if defined(OS_WIN) |
| 95 // The data file will be in the same directory as the current module. |
| 96 bool path_ok = PathService::Get(base::DIR_MODULE, &data_path); |
| 97 #else |
| 93 // For now, expect the data file to be alongside the executable. | 98 // For now, expect the data file to be alongside the executable. |
| 94 // This is sufficient while we work on unit tests, but will eventually | 99 // This is sufficient while we work on unit tests, but will eventually |
| 95 // likely live in a data directory. | 100 // likely live in a data directory. |
| 96 FilePath data_path; | |
| 97 bool path_ok = PathService::Get(base::DIR_EXE, &data_path); | 101 bool path_ok = PathService::Get(base::DIR_EXE, &data_path); |
| 102 #endif |
| 98 DCHECK(path_ok); | 103 DCHECK(path_ok); |
| 99 data_path = data_path.AppendASCII(ICU_UTIL_DATA_FILE_NAME); | 104 data_path = data_path.AppendASCII(ICU_UTIL_DATA_FILE_NAME); |
| 100 #else | 105 #else |
| 101 // Assume it is in the framework bundle's Resources directory. | 106 // Assume it is in the framework bundle's Resources directory. |
| 102 FilePath data_path = | 107 FilePath data_path = |
| 103 base::mac::PathForFrameworkBundleResource(CFSTR(ICU_UTIL_DATA_FILE_NAME)); | 108 base::mac::PathForFrameworkBundleResource(CFSTR(ICU_UTIL_DATA_FILE_NAME)); |
| 104 if (data_path.empty()) { | 109 if (data_path.empty()) { |
| 105 DLOG(ERROR) << ICU_UTIL_DATA_FILE_NAME << " not found in bundle"; | 110 DLOG(ERROR) << ICU_UTIL_DATA_FILE_NAME << " not found in bundle"; |
| 106 return false; | 111 return false; |
| 107 } | 112 } |
| 108 #endif // OS check | 113 #endif // OS check |
| 109 if (!mapped_file.Initialize(data_path)) { | 114 if (!mapped_file.Initialize(data_path)) { |
| 110 DLOG(ERROR) << "Couldn't mmap " << data_path.value(); | 115 DLOG(ERROR) << "Couldn't mmap " << data_path.AsUTF8Unsafe(); |
| 111 return false; | 116 return false; |
| 112 } | 117 } |
| 113 } | 118 } |
| 114 UErrorCode err = U_ZERO_ERROR; | 119 UErrorCode err = U_ZERO_ERROR; |
| 115 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); | 120 udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); |
| 116 return err == U_ZERO_ERROR; | 121 return err == U_ZERO_ERROR; |
| 117 #endif | 122 #endif |
| 118 } | 123 } |
| 119 | 124 |
| 120 } // namespace i18n | 125 } // namespace i18n |
| 121 } // namespace base | 126 } // namespace base |
| OLD | NEW |