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