| Index: mojo/icu/icu.cc
|
| diff --git a/mojo/icu/icu.cc b/mojo/icu/icu.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..17b55b85b75986955797530b0f9909d379d1f5a0
|
| --- /dev/null
|
| +++ b/mojo/icu/icu.cc
|
| @@ -0,0 +1,53 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "mojo/icu/icu.h"
|
| +
|
| +#include "mojo/public/cpp/application/application_impl.h"
|
| +#include "services/icu_data/icu_data.mojom.h"
|
| +#include "third_party/icu/source/common/unicode/putil.h"
|
| +#include "third_party/icu/source/common/unicode/udata.h"
|
| +
|
| +#if !defined(OS_ANDROID)
|
| +#include "base/i18n/icu_util.h"
|
| +#endif
|
| +
|
| +namespace mojo {
|
| +namespace icu {
|
| +namespace {
|
| +
|
| +// These values are for Android arm32.
|
| +const char kDataHash[] = "750429c6b974f0207c476910cb688f08936317aa";
|
| +const int64_t kDataSize = 6038640;
|
| +
|
| +class Callback {
|
| + public:
|
| + void Run(mojo::ScopedSharedBufferHandle handle) const {
|
| + void* ptr = nullptr;
|
| + mojo::MapBuffer(handle.get(), 0, kDataSize, &ptr,
|
| + MOJO_MAP_BUFFER_FLAG_NONE);
|
| + UErrorCode err = U_ZERO_ERROR;
|
| + udata_setCommonData(ptr, &err);
|
| + // Leak the handle because we never unmap the buffer.
|
| + (void)handle.release();
|
| + };
|
| +};
|
| +}
|
| +
|
| +void Initialize(ApplicationImpl* app) {
|
| +#if !defined(OS_ANDROID)
|
| + // On desktop platforms, the icu data table is stored in a file on disk, which
|
| + // can be loaded using base.
|
| + base::i18n::InitializeICU();
|
| + return;
|
| +#endif
|
| +
|
| + icu_data::ICUDataPtr icu_data;
|
| + app->ConnectToService("mojo:icu_data", &icu_data);
|
| + icu_data->Map(kDataHash, Callback());
|
| + icu_data.WaitForIncomingMethodCall();
|
| +}
|
| +
|
| +} // namespace icu
|
| +} // namespace mojo
|
|
|