From 4a972e2d52aac0bfd257fbb4fbc26099af43b63b Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 10 Aug 2016 12:50:00 -0700 Subject: [PATCH] Teach //flutter/glue to build on Fuchsia (#2898) --- glue/BUILD.gn | 25 ++++++++--- ...ipe_job.cc => drain_data_pipe_job_base.cc} | 2 +- glue/drain_data_pipe_job_fuchsia.cc | 43 +++++++++++++++++++ glue/{stack_trace.cc => stack_trace_base.cc} | 0 glue/stack_trace_fuchsia.cc | 11 +++++ glue/{thread.cc => thread_base.cc} | 0 glue/thread_fuchsia.cc | 27 ++++++++++++ 7 files changed, 101 insertions(+), 7 deletions(-) rename glue/{drain_data_pipe_job.cc => drain_data_pipe_job_base.cc} (96%) create mode 100644 glue/drain_data_pipe_job_fuchsia.cc rename glue/{stack_trace.cc => stack_trace_base.cc} (100%) create mode 100644 glue/stack_trace_fuchsia.cc rename glue/{thread.cc => thread_base.cc} (100%) create mode 100644 glue/thread_fuchsia.cc diff --git a/glue/BUILD.gn b/glue/BUILD.gn index dbefe5bff8ec8..81cc7893c76ac 100644 --- a/glue/BUILD.gn +++ b/glue/BUILD.gn @@ -6,14 +6,9 @@ source_set("glue") { sources = [ "data_pipe_utils.cc", "data_pipe_utils.h", - "drain_data_pipe_job.cc", "drain_data_pipe_job.h", "movable_wrapper.h", - "stack_trace.cc", "stack_trace.h", - "task_runner_adaptor.cc", - "task_runner_adaptor.h", - "thread.cc", "thread.h", "trace_event.h", ] @@ -24,7 +19,25 @@ source_set("glue") { "//mojo/public/cpp/system", ] - if (!is_fuchsia) { + if (is_fuchsia) { + sources += [ + "drain_data_pipe_job_fuchsia.cc", + "stack_trace_fuchsia.cc", + "thread_fuchsia.cc", + ] + + deps += [ + "//lib/mtl", + ] + } else { + sources += [ + "drain_data_pipe_job_base.cc", + "stack_trace_base.cc", + "task_runner_adaptor.cc", + "task_runner_adaptor.h", + "thread_base.cc", + ] + deps += [ "//base", "//mojo/data_pipe_utils", diff --git a/glue/drain_data_pipe_job.cc b/glue/drain_data_pipe_job_base.cc similarity index 96% rename from glue/drain_data_pipe_job.cc rename to glue/drain_data_pipe_job_base.cc index 89c985b73b682..2e01f710e6fd6 100644 --- a/glue/drain_data_pipe_job.cc +++ b/glue/drain_data_pipe_job_base.cc @@ -29,7 +29,7 @@ class DrainDataPipeJob::JobImpl : public DataPipeDrainer::Client { std::vector buffer_; ResultCallback callback_; - mojo::common::DataPipeDrainer drainer_; + DataPipeDrainer drainer_; FTL_DISALLOW_COPY_AND_ASSIGN(JobImpl); }; diff --git a/glue/drain_data_pipe_job_fuchsia.cc b/glue/drain_data_pipe_job_fuchsia.cc new file mode 100644 index 0000000000000..dc0cc4b8a739d --- /dev/null +++ b/glue/drain_data_pipe_job_fuchsia.cc @@ -0,0 +1,43 @@ +// Copyright 2016 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 "flutter/glue/drain_data_pipe_job.h" + +#include + +#include "lib/mtl/data_pipe/data_pipe_drainer.h" + +using mtl::DataPipeDrainer; + +namespace glue { + +class DrainDataPipeJob::JobImpl : public DataPipeDrainer::Client { + public: + explicit JobImpl(mojo::ScopedDataPipeConsumerHandle handle, + const ResultCallback& callback) + : callback_(callback), drainer_(this, std::move(handle)) {} + + private: + // mojo::common::DataPipeDrainer::Client + void OnDataAvailable(const void* data, size_t num_bytes) override { + const char* bytes = static_cast(data); + buffer_.insert(buffer_.end(), bytes, bytes + num_bytes); + } + + void OnDataComplete() override { callback_(std::move(buffer_)); } + + std::vector buffer_; + ResultCallback callback_; + DataPipeDrainer drainer_; + + FTL_DISALLOW_COPY_AND_ASSIGN(JobImpl); +}; + +DrainDataPipeJob::DrainDataPipeJob(mojo::ScopedDataPipeConsumerHandle handle, + const ResultCallback& callback) + : impl_(new JobImpl(std::move(handle), callback)) {} + +DrainDataPipeJob::~DrainDataPipeJob() {} + +} // namespace glue diff --git a/glue/stack_trace.cc b/glue/stack_trace_base.cc similarity index 100% rename from glue/stack_trace.cc rename to glue/stack_trace_base.cc diff --git a/glue/stack_trace_fuchsia.cc b/glue/stack_trace_fuchsia.cc new file mode 100644 index 0000000000000..abd82c661d28c --- /dev/null +++ b/glue/stack_trace_fuchsia.cc @@ -0,0 +1,11 @@ +// Copyright 2016 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 "flutter/glue/stack_trace.h" + +namespace glue { + +void PrintStackTrace() {} + +} // namespace glue diff --git a/glue/thread.cc b/glue/thread_base.cc similarity index 100% rename from glue/thread.cc rename to glue/thread_base.cc diff --git a/glue/thread_fuchsia.cc b/glue/thread_fuchsia.cc new file mode 100644 index 0000000000000..61252c993af8f --- /dev/null +++ b/glue/thread_fuchsia.cc @@ -0,0 +1,27 @@ +// Copyright 2016 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 "flutter/glue/thread.h" + +#include + +#include "lib/mtl/threading/create_thread.h" + +namespace glue { + +class Thread::ThreadImpl { + public: + std::thread thread_; +}; + +Thread::Thread(std::string name) : impl_(new ThreadImpl()) {} + +Thread::~Thread() {} + +bool Thread::Start() { + impl_->thread_ = mtl::CreateThread(&task_runner_); + return true; +} + +} // namespace glue