Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Unified Diff: mojo/icu/icu.cc

Issue 826093004: Support ICU on Android (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address review comments Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « mojo/icu/icu.h ('k') | services/BUILD.gn » ('j') | services/icu_data/icu_data.mojom » ('J')

Powered by Google App Engine
This is Rietveld 408576698