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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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/application/application_runner_chromium.h"
6 #include "mojo/common/weak_binding_set.h"
7 #include "mojo/public/c/system/main.h"
8 #include "mojo/public/cpp/application/application_connection.h"
9 #include "mojo/public/cpp/application/application_delegate.h"
10 #include "mojo/public/cpp/application/interface_factory.h"
11 #include "mojo/public/cpp/bindings/interface_ptr.h"
12 #include "mojo/services/icu_data/public/interfaces/icu_data.mojom.h"
13
14 namespace {
15
16 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
17 extern "C" int icu_data_table_size;
18 extern "C" const char icu_data_table_hash[];
19
20 class ICUDataImpl : public mojo::ApplicationDelegate,
21 public mojo::ICUData,
22 public mojo::InterfaceFactory<mojo::ICUData> {
23 public:
24 ICUDataImpl() {}
25 ~ICUDataImpl() override {}
26
27 // mojo::ApplicationDelegate implementation.
28 bool ConfigureIncomingConnection(
29 mojo::ApplicationConnection* connection) override {
30 connection->AddService(this);
31 return true;
32 }
33
34 // mojo::InterfaceFactory<mojo::ICUData> implementation.
35 void Create(mojo::ApplicationConnection* connection,
36 mojo::InterfaceRequest<mojo::ICUData> request) override {
37 bindings_.AddBinding(this, request.Pass());
38 }
39
40 void Map(const mojo::String& sha1hash,
41 const mojo::Callback<void(mojo::ScopedSharedBufferHandle)>& callback)
42 override {
43 if (std::string(sha1hash) != std::string(icu_data_table_hash)) {
44 callback.Run(mojo::ScopedSharedBufferHandle());
45 return;
46 }
47 EnsureBuffer();
48 mojo::ScopedSharedBufferHandle handle;
49 // FIXME: We should create a read-only duplicate of the handle.
50 mojo::DuplicateBuffer(buffer_->handle.get(), nullptr, &handle);
51 callback.Run(handle.Pass());
52 }
53
54 private:
55 void EnsureBuffer() {
56 if (buffer_)
57 return;
58 const int64_t kBufferSize = icu_data_table_size;
59 buffer_.reset(new mojo::SharedBuffer(kBufferSize));
60 void* ptr = nullptr;
61 MojoResult rv = mojo::MapBuffer(buffer_->handle.get(), 0, kBufferSize, &ptr,
62 MOJO_MAP_BUFFER_FLAG_NONE);
63 CHECK_EQ(rv, MOJO_RESULT_OK);
64 memcpy(ptr, icu_data_table, kBufferSize);
65 rv = mojo::UnmapBuffer(ptr);
66 CHECK_EQ(rv, MOJO_RESULT_OK);
67 }
68
69 scoped_ptr<mojo::SharedBuffer> buffer_;
70 mojo::WeakBindingSet<ICUData> bindings_;
71 };
72 }
73
74 MojoResult MojoMain(MojoHandle shell_handle) {
75 mojo::ApplicationRunnerChromium runner(new ICUDataImpl);
76 return runner.Run(shell_handle);
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698