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

Side by Side Diff: services/icu_data/icu_data_impl.cc

Issue 1987363004: Build libraries for a number of services. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: remove unnecessary imports Created 4 years, 7 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
« no previous file with comments | « services/icu_data/icu_data_impl.h ('k') | services/icu_data/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/application/application_runner_chromium.h" 5 #include "services/icu_data/icu_data_impl.h"
6 #include "mojo/common/binding_set.h" 6
7 #include "mojo/public/c/system/main.h"
8 #include "mojo/public/cpp/application/application_delegate.h"
9 #include "mojo/public/cpp/application/service_provider_impl.h"
10 #include "mojo/public/cpp/bindings/interface_ptr.h" 7 #include "mojo/public/cpp/bindings/interface_ptr.h"
11 #include "mojo/services/icu_data/interfaces/icu_data.mojom.h"
12 #include "services/icu_data/kICUData.h" 8 #include "services/icu_data/kICUData.h"
13 9
14 namespace icu_data { 10 namespace icu_data {
15 11
16 class ICUDataImpl : public mojo::ApplicationDelegate, public ICUData { 12 ICUDataImpl::ICUDataImpl() {}
17 public: 13 ICUDataImpl::~ICUDataImpl() {}
18 ICUDataImpl() {}
19 ~ICUDataImpl() override {}
20 14
21 // mojo::ApplicationDelegate implementation. 15 bool ICUDataImpl::ConfigureIncomingConnection(
22 bool ConfigureIncomingConnection( 16 mojo::ServiceProviderImpl* service_provider_impl) {
23 mojo::ServiceProviderImpl* service_provider_impl) override { 17 service_provider_impl->AddService<ICUData>(
24 service_provider_impl->AddService<ICUData>( 18 [this](const mojo::ConnectionContext& connection_context,
25 [this](const mojo::ConnectionContext& connection_context, 19 mojo::InterfaceRequest<ICUData> icu_data_request) {
26 mojo::InterfaceRequest<ICUData> icu_data_request) { 20 bindings_.AddBinding(this, icu_data_request.Pass());
27 bindings_.AddBinding(this, icu_data_request.Pass()); 21 });
28 });
29 22
30 return true; 23 return true;
31 }
32
33 void Map(const mojo::String& sha1hash,
34 const mojo::Callback<void(mojo::ScopedSharedBufferHandle)>& callback)
35 override {
36 if (std::string(sha1hash) != std::string(kICUData.hash)) {
37 LOG(WARNING) << "Failed to match sha1sum. Expected " << kICUData.hash;
38 callback.Run(mojo::ScopedSharedBufferHandle());
39 return;
40 }
41 EnsureBuffer();
42 mojo::ScopedSharedBufferHandle handle;
43 // FIXME: We should create a read-only duplicate of the handle.
44 mojo::DuplicateBuffer(buffer_->handle.get(), nullptr, &handle);
45 callback.Run(handle.Pass());
46 }
47
48 private:
49 void EnsureBuffer() {
50 if (buffer_)
51 return;
52 buffer_.reset(new mojo::SharedBuffer(kICUData.size));
53 void* ptr = nullptr;
54 MojoResult rv = mojo::MapBuffer(buffer_->handle.get(), 0, kICUData.size,
55 &ptr, MOJO_MAP_BUFFER_FLAG_NONE);
56 CHECK_EQ(rv, MOJO_RESULT_OK);
57 memcpy(ptr, kICUData.data, kICUData.size);
58 rv = mojo::UnmapBuffer(ptr);
59 CHECK_EQ(rv, MOJO_RESULT_OK);
60 }
61
62 scoped_ptr<mojo::SharedBuffer> buffer_;
63 mojo::BindingSet<ICUData> bindings_;
64 };
65 } 24 }
66 25
67 MojoResult MojoMain(MojoHandle application_request) { 26 void ICUDataImpl::Map(
68 mojo::ApplicationRunnerChromium runner(new icu_data::ICUDataImpl); 27 const mojo::String& sha1hash,
69 return runner.Run(application_request); 28 const mojo::Callback<void(mojo::ScopedSharedBufferHandle)>& callback) {
29 if (std::string(sha1hash) != std::string(kICUData.hash)) {
30 LOG(WARNING) << "Failed to match sha1sum. Expected " << kICUData.hash;
31 callback.Run(mojo::ScopedSharedBufferHandle());
32 return;
33 }
34 EnsureBuffer();
35 mojo::ScopedSharedBufferHandle handle;
36 // FIXME: We should create a read-only duplicate of the handle.
37 mojo::DuplicateBuffer(buffer_->handle.get(), nullptr, &handle);
38 callback.Run(handle.Pass());
70 } 39 }
40
41 void ICUDataImpl::EnsureBuffer() {
42 if (buffer_)
43 return;
44 buffer_.reset(new mojo::SharedBuffer(kICUData.size));
45 void* ptr = nullptr;
46 MojoResult rv = mojo::MapBuffer(buffer_->handle.get(), 0, kICUData.size, &ptr,
47 MOJO_MAP_BUFFER_FLAG_NONE);
48 CHECK_EQ(rv, MOJO_RESULT_OK);
49 memcpy(ptr, kICUData.data, kICUData.size);
50 rv = mojo::UnmapBuffer(ptr);
51 CHECK_EQ(rv, MOJO_RESULT_OK);
52 }
53
54 } // namespace icu_data
OLDNEW
« no previous file with comments | « services/icu_data/icu_data_impl.h ('k') | services/icu_data/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698