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

Side by Side Diff: services/icu_data/icu_data_impl.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 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 "services/icu_data/data.h"
13 #include "services/icu_data/icu_data.mojom.h"
14
15 namespace icu_data {
16
17 class ICUDataImpl : public mojo::ApplicationDelegate,
18 public ICUData,
19 public mojo::InterfaceFactory<ICUData> {
20 public:
21 ICUDataImpl() {}
22 ~ICUDataImpl() override {}
23
24 // mojo::ApplicationDelegate implementation.
25 bool ConfigureIncomingConnection(
26 mojo::ApplicationConnection* connection) override {
27 connection->AddService(this);
28 return true;
29 }
30
31 // mojo::InterfaceFactory<mojo::ICUData> implementation.
32 void Create(mojo::ApplicationConnection* connection,
33 mojo::InterfaceRequest<ICUData> request) override {
34 bindings_.AddBinding(this, request.Pass());
35 }
36
37 void Map(const mojo::String& sha1hash,
38 const mojo::Callback<void(mojo::ScopedSharedBufferHandle)>& callback)
39 override {
40 if (std::string(sha1hash) != std::string(kICUDataTableHash)) {
41 callback.Run(mojo::ScopedSharedBufferHandle());
42 return;
43 }
44 EnsureBuffer();
45 mojo::ScopedSharedBufferHandle handle;
46 // FIXME: We should create a read-only duplicate of the handle.
47 mojo::DuplicateBuffer(buffer_->handle.get(), nullptr, &handle);
48 callback.Run(handle.Pass());
49 }
50
51 private:
52 void EnsureBuffer() {
53 if (buffer_)
54 return;
55 buffer_.reset(new mojo::SharedBuffer(kICUDataTableSize));
56 void* ptr = nullptr;
57 MojoResult rv = mojo::MapBuffer(buffer_->handle.get(), 0, kICUDataTableSize,
58 &ptr, MOJO_MAP_BUFFER_FLAG_NONE);
59 CHECK_EQ(rv, MOJO_RESULT_OK);
60 memcpy(ptr, kICUDataTable, kICUDataTableSize);
61 rv = mojo::UnmapBuffer(ptr);
62 CHECK_EQ(rv, MOJO_RESULT_OK);
63 }
64
65 scoped_ptr<mojo::SharedBuffer> buffer_;
66 mojo::WeakBindingSet<ICUData> bindings_;
67 };
68 }
69
70 MojoResult MojoMain(MojoHandle shell_handle) {
71 mojo::ApplicationRunnerChromium runner(new icu_data::ICUDataImpl);
72 return runner.Run(shell_handle);
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698