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

Unified Diff: services/icu_data/main.cc

Issue 826093004: Support ICU on Android (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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: services/icu_data/main.cc
diff --git a/services/icu_data/main.cc b/services/icu_data/main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..548aefdaea793e6aa1f83a673d2ba7633f037539
--- /dev/null
+++ b/services/icu_data/main.cc
@@ -0,0 +1,77 @@
+// Copyright 2014 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/application/application_runner_chromium.h"
+#include "mojo/common/weak_binding_set.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/interface_factory.h"
+#include "mojo/public/cpp/bindings/interface_ptr.h"
+#include "mojo/services/icu_data/public/interfaces/icu_data.mojom.h"
+
+namespace {
+
+extern "C" const char icu_data_table[];
jamesr 2015/01/08 01:23:08 what does extern "C" ... inside an anonymous names
abarth-chromium 2015/01/08 04:18:12 I can move the externs outside of the anonymous na
+extern "C" int icu_data_table_size;
+extern "C" const char icu_data_table_hash[];
+
+class ICUDataImpl : public mojo::ApplicationDelegate,
+ public mojo::ICUData,
+ public mojo::InterfaceFactory<mojo::ICUData> {
+ public:
+ ICUDataImpl() {}
+ ~ICUDataImpl() override {}
+
+ // mojo::ApplicationDelegate implementation.
+ bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) override {
+ connection->AddService(this);
+ return true;
+ }
+
+ // mojo::InterfaceFactory<mojo::ICUData> implementation.
+ void Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<mojo::ICUData> request) override {
+ bindings_.AddBinding(this, request.Pass());
+ }
+
+ void Map(const mojo::String& sha1hash,
+ const mojo::Callback<void(mojo::ScopedSharedBufferHandle)>& callback)
+ override {
+ if (std::string(sha1hash) != std::string(icu_data_table_hash)) {
+ callback.Run(mojo::ScopedSharedBufferHandle());
+ return;
+ }
+ EnsureBuffer();
+ mojo::ScopedSharedBufferHandle handle;
+ // FIXME: We should create a read-only duplicate of the handle.
+ mojo::DuplicateBuffer(buffer_->handle.get(), nullptr, &handle);
+ callback.Run(handle.Pass());
+ }
+
+ private:
+ void EnsureBuffer() {
+ if (buffer_)
+ return;
+ const int64_t kBufferSize = icu_data_table_size;
+ buffer_.reset(new mojo::SharedBuffer(kBufferSize));
+ void* ptr = nullptr;
+ MojoResult rv = mojo::MapBuffer(buffer_->handle.get(), 0, kBufferSize, &ptr,
+ MOJO_MAP_BUFFER_FLAG_NONE);
+ CHECK_EQ(rv, MOJO_RESULT_OK);
+ memcpy(ptr, icu_data_table, kBufferSize);
+ rv = mojo::UnmapBuffer(ptr);
+ CHECK_EQ(rv, MOJO_RESULT_OK);
+ }
+
+ scoped_ptr<mojo::SharedBuffer> buffer_;
+ mojo::WeakBindingSet<ICUData> bindings_;
+};
+}
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::ApplicationRunnerChromium runner(new ICUDataImpl);
+ return runner.Run(shell_handle);
+}

Powered by Google App Engine
This is Rietveld 408576698