OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #include "mojo/icu/icu.h" |
| 6 |
| 7 #include "mojo/public/cpp/application/application_impl.h" |
| 8 #include "services/icu_data/icu_data.mojom.h" |
| 9 #include "third_party/icu/source/common/unicode/putil.h" |
| 10 #include "third_party/icu/source/common/unicode/udata.h" |
| 11 |
| 12 #if !defined(OS_ANDROID) |
| 13 #include "base/i18n/icu_util.h" |
| 14 #endif |
| 15 |
| 16 namespace mojo { |
| 17 namespace icu { |
| 18 namespace { |
| 19 |
| 20 // These values are for Android arm32. |
| 21 const char kDataHash[] = "750429c6b974f0207c476910cb688f08936317aa"; |
| 22 const int64_t kDataSize = 6038640; |
| 23 |
| 24 class Callback { |
| 25 public: |
| 26 void Run(mojo::ScopedSharedBufferHandle handle) const { |
| 27 void* ptr = nullptr; |
| 28 mojo::MapBuffer(handle.get(), 0, kDataSize, &ptr, |
| 29 MOJO_MAP_BUFFER_FLAG_NONE); |
| 30 UErrorCode err = U_ZERO_ERROR; |
| 31 udata_setCommonData(ptr, &err); |
| 32 // Leak the handle because we never unmap the buffer. |
| 33 (void)handle.release(); |
| 34 }; |
| 35 }; |
| 36 } |
| 37 |
| 38 void Initialize(ApplicationImpl* app) { |
| 39 #if !defined(OS_ANDROID) |
| 40 // On desktop platforms, the icu data table is stored in a file on disk, which |
| 41 // can be loaded using base. |
| 42 base::i18n::InitializeICU(); |
| 43 return; |
| 44 #endif |
| 45 |
| 46 icu_data::ICUDataPtr icu_data; |
| 47 app->ConnectToService("mojo:icu_data", &icu_data); |
| 48 icu_data->Map(kDataHash, Callback()); |
| 49 icu_data.WaitForIncomingMethodCall(); |
| 50 } |
| 51 |
| 52 } // namespace icu |
| 53 } // namespace mojo |
OLD | NEW |