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