Skip to content

Commit

Permalink
Remove last mojom interface (flutter#3184)
Browse files Browse the repository at this point in the history
We no longer use mojom to transport messages. We still use the Mojo EDK
to spin the event loop, however.
  • Loading branch information
abarth authored Oct 28, 2016
1 parent e26bf9a commit 4b8c905
Show file tree
Hide file tree
Showing 65 changed files with 269 additions and 1,181 deletions.
12 changes: 0 additions & 12 deletions assets/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,15 @@ source_set("assets") {
sources = [
"directory_asset_bundle.cc",
"directory_asset_bundle.h",
"unzip_job.cc",
"unzip_job.h",
"unzipper_provider.cc",
"unzipper_provider.h",
"zip_asset_bundle.cc",
"zip_asset_bundle.h",
"zip_asset_store.cc",
"zip_asset_store.h",
]

deps = [
"//flutter/glue",
"//lib/ftl",
"//lib/zip",
"//mojo/public/cpp/bindings:callback",
"//mojo/public/cpp/system",
"//mojo/public/cpp/bindings:utility",
"//third_party/zlib:minizip",
]

public_deps = [
"//mojo/services/asset_bundle/interfaces",
]
}
28 changes: 2 additions & 26 deletions assets/directory_asset_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,13 @@

#include <utility>

#include "flutter/glue/data_pipe_utils.h"
#include "lib/ftl/files/eintr_wrapper.h"
#include "lib/ftl/files/file.h"
#include "lib/ftl/files/path.h"
#include "lib/ftl/files/unique_fd.h"

namespace blink {

void DirectoryAssetBundle::GetAsStream(
const mojo::String& asset_name,
const mojo::Callback<void(mojo::ScopedDataPipeConsumerHandle)>& callback) {
mojo::DataPipe pipe;
callback.Run(std::move(pipe.consumer_handle));

std::string asset_path = GetPathForAsset(asset_name.get());
if (asset_path.empty())
return;

// TODO(abarth): Consider moving the |open| call to task_runner_.
ftl::UniqueFD fd(HANDLE_EINTR(open(asset_path.c_str(), O_RDONLY)));
if (fd.get() < 0)
return;
glue::CopyFromFileDescriptor(std::move(fd), std::move(pipe.producer_handle),
task_runner_, [](bool ignored) {});
}

bool DirectoryAssetBundle::GetAsBuffer(const std::string& asset_name,
std::vector<uint8_t>* data) {
std::string asset_path = GetPathForAsset(asset_name);
Expand All @@ -45,13 +26,8 @@ bool DirectoryAssetBundle::GetAsBuffer(const std::string& asset_name,

DirectoryAssetBundle::~DirectoryAssetBundle() {}

DirectoryAssetBundle::DirectoryAssetBundle(
mojo::InterfaceRequest<AssetBundle> request,
std::string directory,
ftl::RefPtr<ftl::TaskRunner> task_runner)
: binding_(this, std::move(request)),
directory_(std::move(directory)),
task_runner_(std::move(task_runner)) {}
DirectoryAssetBundle::DirectoryAssetBundle(std::string directory)
: directory_(std::move(directory)) {}

std::string DirectoryAssetBundle::GetPathForAsset(
const std::string& asset_name) {
Expand Down
25 changes: 6 additions & 19 deletions assets/directory_asset_bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,24 @@
#ifndef FLUTTER_ASSETS_DIRECTORY_ASSET_BUNDLE_H_
#define FLUTTER_ASSETS_DIRECTORY_ASSET_BUNDLE_H_

#include <string>
#include <vector>

#include "lib/ftl/macros.h"
#include "lib/ftl/tasks/task_runner.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/environment/async_waiter.h"
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"

namespace blink {

// A mojo service that serves assets out of a directory.
class DirectoryAssetBundle : public mojo::asset_bundle::AssetBundle {
class DirectoryAssetBundle {
public:
DirectoryAssetBundle(mojo::InterfaceRequest<AssetBundle> request,
std::string directory,
ftl::RefPtr<ftl::TaskRunner> task_runner);
~DirectoryAssetBundle() override;

// mojo::assert_bundle::AssetBundle implementation:
void GetAsStream(
const mojo::String& asset_name,
const mojo::Callback<void(mojo::ScopedDataPipeConsumerHandle)>& callback)
override;
explicit DirectoryAssetBundle(std::string directory);
~DirectoryAssetBundle();

bool GetAsBuffer(const std::string& asset_name, std::vector<uint8_t>* data);

private:
std::string GetPathForAsset(const std::string& asset_name);

mojo::Binding<mojo::asset_bundle::AssetBundle> binding_;
const std::string directory_;
ftl::RefPtr<ftl::TaskRunner> task_runner_;

FTL_DISALLOW_COPY_AND_ASSIGN(DirectoryAssetBundle);
};
Expand Down
90 changes: 0 additions & 90 deletions assets/unzip_job.cc

This file was deleted.

46 changes: 0 additions & 46 deletions assets/unzip_job.h

This file was deleted.

26 changes: 0 additions & 26 deletions assets/zip_asset_bundle.cc

This file was deleted.

35 changes: 0 additions & 35 deletions assets/zip_asset_bundle.h

This file was deleted.

32 changes: 2 additions & 30 deletions assets/zip_asset_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,18 @@

#include <utility>

#include "flutter/assets/unzip_job.h"
#include "flutter/glue/data_pipe_utils.h"
#include "lib/ftl/files/eintr_wrapper.h"
#include "lib/ftl/files/unique_fd.h"
#include "lib/zip/unique_unzipper.h"
#include "third_party/zlib/contrib/minizip/unzip.h"

namespace blink {

ZipAssetStore::ZipAssetStore(UnzipperProvider unzipper_provider,
ftl::RefPtr<ftl::TaskRunner> task_runner)
: unzipper_provider_(std::move(unzipper_provider)),
task_runner_(std::move(task_runner)) {}
ZipAssetStore::ZipAssetStore(UnzipperProvider unzipper_provider)
: unzipper_provider_(std::move(unzipper_provider)) {}

ZipAssetStore::~ZipAssetStore() {}

void ZipAssetStore::AddOverlayFile(std::string asset_name,
std::string file_path) {
overlay_files_.emplace(std::move(asset_name), std::move(file_path));
}

void ZipAssetStore::GetAsStream(const std::string& asset_name,
mojo::ScopedDataPipeProducerHandle producer) {
auto overlay = overlay_files_.find(asset_name);
if (overlay != overlay_files_.end()) {
// TODO(abarth): Consider moving the |open| call to task_runner_.
ftl::UniqueFD fd(HANDLE_EINTR(open(overlay->second.c_str(), O_RDONLY)));
if (fd.get() < 0)
return;
glue::CopyFromFileDescriptor(std::move(fd), std::move(producer),
task_runner_, [](bool ignored) {});
} else {
zip::UniqueUnzipper unzipper = unzipper_provider_();
if (!unzipper.is_valid())
return;
new UnzipJob(std::move(unzipper), asset_name, std::move(producer),
task_runner_);
}
}

bool ZipAssetStore::GetAsBuffer(const std::string& asset_name,
std::vector<uint8_t>* data) {
zip::UniqueUnzipper unzipper = unzipper_provider_();
Expand Down
Loading

0 comments on commit 4b8c905

Please sign in to comment.