mirror of
https://github.com/encounter/engine.git
synced 2026-03-30 11:09:55 -07:00
Remove obsolete AssetBundle implementations
This commit is contained in:
@@ -6,12 +6,6 @@ import("//mojo/public/mojo_application.gni")
|
||||
|
||||
source_set("lib") {
|
||||
sources = [
|
||||
"asset_bundle_impl.cc",
|
||||
"asset_bundle_impl.h",
|
||||
"asset_unpacker_impl.cc",
|
||||
"asset_unpacker_impl.h",
|
||||
"asset_unpacker_job.cc",
|
||||
"asset_unpacker_job.h",
|
||||
"zip_asset_bundle.cc",
|
||||
"zip_asset_bundle.h",
|
||||
]
|
||||
@@ -25,41 +19,3 @@ source_set("lib") {
|
||||
"//third_party/zlib:zip",
|
||||
]
|
||||
}
|
||||
|
||||
mojo_native_application("asset_bundle") {
|
||||
sources = [
|
||||
"main.cc",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//mojo/application",
|
||||
"//mojo/public/cpp/application",
|
||||
"//mojo/public/cpp/bindings:callback",
|
||||
"//mojo/public/cpp/system",
|
||||
"//mojo/services/asset_bundle/interfaces",
|
||||
":lib",
|
||||
]
|
||||
}
|
||||
|
||||
mojo_native_application("apptests") {
|
||||
output_name = "asset_bundle_apptests"
|
||||
|
||||
testonly = true
|
||||
|
||||
sources = [
|
||||
"asset_bundle_apptest.cc",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//mojo/application",
|
||||
"//mojo/application:test_support",
|
||||
"//mojo/data_pipe_utils",
|
||||
"//mojo/public/cpp/bindings",
|
||||
"//mojo/services/asset_bundle/interfaces",
|
||||
"//third_party/zlib:zip",
|
||||
]
|
||||
|
||||
data_deps = [ ":asset_bundle($default_toolchain)" ]
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
// Copyright 2015 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 "base/bind.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "mojo/data_pipe_utils/data_pipe_utils.h"
|
||||
#include "mojo/public/cpp/application/application_impl.h"
|
||||
#include "mojo/public/cpp/application/application_test_base.h"
|
||||
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
|
||||
#include "third_party/zlib/google/zip.h"
|
||||
|
||||
namespace asset_bundle {
|
||||
|
||||
class AssetBundleAppTest : public mojo::test::ApplicationTestBase {
|
||||
public:
|
||||
AssetBundleAppTest() {}
|
||||
~AssetBundleAppTest() override {}
|
||||
|
||||
void SetUp() override {
|
||||
mojo::test::ApplicationTestBase::SetUp();
|
||||
application_impl()->ConnectToService("mojo:asset_bundle", &asset_unpacker_);
|
||||
}
|
||||
|
||||
protected:
|
||||
mojo::asset_bundle::AssetUnpackerPtr asset_unpacker_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AssetBundleAppTest);
|
||||
};
|
||||
|
||||
TEST_F(AssetBundleAppTest, CanGetText) {
|
||||
std::string foo_content = "Some plain data";
|
||||
std::string bar_content = "The wrong data";
|
||||
|
||||
base::ScopedTempDir zip_dir;
|
||||
ASSERT_TRUE(zip_dir.CreateUniqueTempDir());
|
||||
|
||||
base::FilePath foo_path = zip_dir.path().Append("foo.txt");
|
||||
base::WriteFile(foo_path, foo_content.data(), foo_content.size());
|
||||
|
||||
base::FilePath bar_path = zip_dir.path().Append("bar.txt");
|
||||
base::WriteFile(bar_path, bar_content.data(), bar_content.size());
|
||||
|
||||
base::FilePath zip_path;
|
||||
ASSERT_TRUE(base::CreateTemporaryFile(&zip_path));
|
||||
|
||||
zip::Zip(zip_dir.path(), zip_path, false);
|
||||
std::string zip_contents;
|
||||
ASSERT_TRUE(base::ReadFileToString(zip_path, &zip_contents));
|
||||
ASSERT_TRUE(base::DeleteFile(zip_path, false));
|
||||
|
||||
mojo::DataPipe zip_pipe;
|
||||
mojo::asset_bundle::AssetBundlePtr asset_bundle;
|
||||
asset_unpacker_->UnpackZipStream(zip_pipe.consumer_handle.Pass(),
|
||||
GetProxy(&asset_bundle));
|
||||
|
||||
EXPECT_TRUE(mojo::common::BlockingCopyFromString(
|
||||
zip_contents, zip_pipe.producer_handle));
|
||||
zip_pipe.producer_handle.reset();
|
||||
|
||||
std::string asset_content;
|
||||
asset_bundle->GetAsStream("foo.txt",
|
||||
[&](mojo::ScopedDataPipeConsumerHandle asset_pipe) {
|
||||
mojo::common::BlockingCopyToString(asset_pipe.Pass(), &asset_content);
|
||||
});
|
||||
ASSERT_TRUE(asset_bundle.WaitForIncomingResponse());
|
||||
|
||||
EXPECT_EQ(foo_content, asset_content)
|
||||
<< "Failed to get the correct contents back from the asset bundle";
|
||||
|
||||
std::string missing_content;
|
||||
asset_bundle->GetAsStream("missing.txt",
|
||||
[&](mojo::ScopedDataPipeConsumerHandle asset_pipe) {
|
||||
mojo::common::BlockingCopyToString(asset_pipe.Pass(), &missing_content);
|
||||
});
|
||||
ASSERT_TRUE(asset_bundle.WaitForIncomingResponse());
|
||||
|
||||
EXPECT_EQ("", missing_content)
|
||||
<< "Missing asset keys are treated as empty data streams";
|
||||
|
||||
std::string outside_content;
|
||||
asset_bundle->GetAsStream("../../out-of-bundle.txt",
|
||||
[&](mojo::ScopedDataPipeConsumerHandle asset_pipe) {
|
||||
mojo::common::BlockingCopyToString(asset_pipe.Pass(), &outside_content);
|
||||
});
|
||||
ASSERT_TRUE(asset_bundle.WaitForIncomingResponse());
|
||||
|
||||
EXPECT_EQ("", outside_content)
|
||||
<< "Traversing outside of bundle is treated as an empty data stream";
|
||||
}
|
||||
|
||||
} // namespace asset_bundle
|
||||
@@ -1,54 +0,0 @@
|
||||
// Copyright 2015 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 "services/asset_bundle/asset_bundle_impl.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "mojo/data_pipe_utils/data_pipe_utils.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace asset_bundle {
|
||||
namespace {
|
||||
|
||||
void Ignored(bool) {
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AssetBundleImpl::AssetBundleImpl(InterfaceRequest<AssetBundle> request,
|
||||
scoped_ptr<base::ScopedTempDir> asset_dir,
|
||||
scoped_refptr<base::TaskRunner> worker_runner)
|
||||
: binding_(this, request.Pass()),
|
||||
asset_dir_(asset_dir.Pass()),
|
||||
worker_runner_(worker_runner.Pass()) {
|
||||
}
|
||||
|
||||
AssetBundleImpl::~AssetBundleImpl() {
|
||||
}
|
||||
|
||||
void AssetBundleImpl::GetAsStream(
|
||||
const String& asset_name,
|
||||
const Callback<void(ScopedDataPipeConsumerHandle)>& callback) {
|
||||
DataPipe pipe;
|
||||
callback.Run(pipe.consumer_handle.Pass());
|
||||
|
||||
std::string asset_string = asset_name.To<std::string>();
|
||||
base::FilePath asset_path =
|
||||
base::MakeAbsoluteFilePath(asset_dir_->path().Append(asset_string));
|
||||
|
||||
auto asset_dir_abs = base::MakeAbsoluteFilePath(asset_dir_->path());
|
||||
if (!asset_dir_abs.IsParent(asset_path)) {
|
||||
LOG(WARNING) << "Requested asset '" << asset_string << "' does not exist.";
|
||||
return;
|
||||
}
|
||||
|
||||
common::CopyFromFile(asset_path, pipe.producer_handle.Pass(), 0,
|
||||
worker_runner_.get(), base::Bind(&Ignored));
|
||||
}
|
||||
|
||||
} // namespace asset_bundle
|
||||
} // namespace mojo
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#ifndef SERVICES_ASSET_BUNDLE_ASSET_BUNDLE_IMPL_H_
|
||||
#define SERVICES_ASSET_BUNDLE_ASSET_BUNDLE_IMPL_H_
|
||||
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/task_runner.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "mojo/public/cpp/bindings/strong_binding.h"
|
||||
#include "mojo/public/cpp/system/data_pipe.h"
|
||||
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace asset_bundle {
|
||||
|
||||
class AssetBundleImpl : public AssetBundle {
|
||||
public:
|
||||
AssetBundleImpl(InterfaceRequest<AssetBundle> request,
|
||||
scoped_ptr<base::ScopedTempDir> asset_dir,
|
||||
scoped_refptr<base::TaskRunner> worker_runner);
|
||||
~AssetBundleImpl() override;
|
||||
|
||||
// AssetBundle implementation
|
||||
void GetAsStream(
|
||||
const String& asset_name,
|
||||
const Callback<void(ScopedDataPipeConsumerHandle)>& callback) override;
|
||||
|
||||
private:
|
||||
StrongBinding<AssetBundle> binding_;
|
||||
scoped_ptr<base::ScopedTempDir> asset_dir_;
|
||||
scoped_refptr<base::TaskRunner> worker_runner_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AssetBundleImpl);
|
||||
};
|
||||
|
||||
} // namespace asset_bundle
|
||||
} // namespace mojo
|
||||
|
||||
#endif // SERVICES_ASSET_BUNDLE_ASSET_BUNDLE_IMPL_H_
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright 2015 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 "services/asset_bundle/asset_unpacker_impl.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "services/asset_bundle/asset_unpacker_job.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace asset_bundle {
|
||||
|
||||
AssetUnpackerImpl::AssetUnpackerImpl(
|
||||
InterfaceRequest<AssetUnpacker> request,
|
||||
scoped_refptr<base::TaskRunner> worker_runner)
|
||||
: binding_(this, request.Pass()), worker_runner_(worker_runner.Pass()) {
|
||||
}
|
||||
|
||||
AssetUnpackerImpl::~AssetUnpackerImpl() {
|
||||
}
|
||||
|
||||
void AssetUnpackerImpl::UnpackZipStream(ScopedDataPipeConsumerHandle zipped,
|
||||
InterfaceRequest<AssetBundle> request) {
|
||||
(new AssetUnpackerJob(request.Pass(), worker_runner_))->Unpack(zipped.Pass());
|
||||
}
|
||||
|
||||
} // namespace asset_bundle
|
||||
} // namespace mojo
|
||||
@@ -1,39 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#ifndef SERVICES_ASSET_BUNDLE_ASSET_UNPACKER_IMPL_H_
|
||||
#define SERVICES_ASSET_BUNDLE_ASSET_UNPACKER_IMPL_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/task_runner.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "mojo/public/cpp/bindings/strong_binding.h"
|
||||
#include "mojo/public/cpp/system/data_pipe.h"
|
||||
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace asset_bundle {
|
||||
|
||||
class AssetUnpackerImpl : public AssetUnpacker {
|
||||
public:
|
||||
AssetUnpackerImpl(InterfaceRequest<AssetUnpacker> request,
|
||||
scoped_refptr<base::TaskRunner> worker_runner);
|
||||
~AssetUnpackerImpl() override;
|
||||
|
||||
// AssetUnpacker implementation
|
||||
void UnpackZipStream(ScopedDataPipeConsumerHandle zipped_assets,
|
||||
InterfaceRequest<AssetBundle> asset_bundle) override;
|
||||
|
||||
private:
|
||||
StrongBinding<AssetUnpacker> binding_;
|
||||
|
||||
scoped_refptr<base::TaskRunner> worker_runner_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AssetUnpackerImpl);
|
||||
};
|
||||
|
||||
} // namespace asset_bundle
|
||||
} // namespace mojo
|
||||
|
||||
#endif // SERVICES_ASSET_BUNDLE_ASSET_UNPACKER_IMPL_H_
|
||||
@@ -1,85 +0,0 @@
|
||||
// Copyright 2015 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 "services/asset_bundle/asset_unpacker_job.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "services/asset_bundle/asset_bundle_impl.h"
|
||||
#include "third_party/zlib/google/zip.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace asset_bundle {
|
||||
namespace {
|
||||
|
||||
void UnzipAssets(
|
||||
const base::FilePath& zip_path,
|
||||
scoped_ptr<base::ScopedTempDir> asset_dir,
|
||||
scoped_refptr<base::TaskRunner> task_runner,
|
||||
base::Callback<void(scoped_ptr<base::ScopedTempDir>)> callback) {
|
||||
if (!zip::Unzip(zip_path, asset_dir->path())) {
|
||||
task_runner->PostTask(FROM_HERE, base::Bind(callback, nullptr));
|
||||
} else {
|
||||
task_runner->PostTask(FROM_HERE,
|
||||
base::Bind(callback, base::Passed(asset_dir.Pass())));
|
||||
}
|
||||
base::DeleteFile(zip_path, false);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AssetUnpackerJob::AssetUnpackerJob(
|
||||
InterfaceRequest<AssetBundle> asset_bundle,
|
||||
scoped_refptr<base::TaskRunner> worker_runner)
|
||||
: asset_bundle_(asset_bundle.Pass()),
|
||||
worker_runner_(worker_runner.Pass()),
|
||||
weak_factory_(this) {
|
||||
}
|
||||
|
||||
AssetUnpackerJob::~AssetUnpackerJob() {
|
||||
}
|
||||
|
||||
void AssetUnpackerJob::Unpack(ScopedDataPipeConsumerHandle zipped_assets) {
|
||||
base::FilePath zip_path;
|
||||
if (!CreateTemporaryFile(&zip_path)) {
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
common::CopyToFile(zipped_assets.Pass(), zip_path, worker_runner_.get(),
|
||||
base::Bind(&AssetUnpackerJob::OnZippedAssetsAvailable,
|
||||
weak_factory_.GetWeakPtr(), zip_path));
|
||||
}
|
||||
|
||||
void AssetUnpackerJob::OnZippedAssetsAvailable(const base::FilePath& zip_path,
|
||||
bool success) {
|
||||
if (!success) {
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
scoped_ptr<base::ScopedTempDir> asset_dir(new base::ScopedTempDir());
|
||||
if (!asset_dir->CreateUniqueTempDir()) {
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
worker_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&UnzipAssets, zip_path, base::Passed(asset_dir.Pass()),
|
||||
base::MessageLoop::current()->task_runner(),
|
||||
base::Bind(&AssetUnpackerJob::OnUnzippedAssetsAvailable,
|
||||
weak_factory_.GetWeakPtr())));
|
||||
}
|
||||
|
||||
void AssetUnpackerJob::OnUnzippedAssetsAvailable(
|
||||
scoped_ptr<base::ScopedTempDir> asset_dir) {
|
||||
if (asset_dir)
|
||||
new AssetBundleImpl(asset_bundle_.Pass(), asset_dir.Pass(), worker_runner_);
|
||||
|
||||
delete this;
|
||||
}
|
||||
|
||||
} // namespace asset_bundle
|
||||
} // namespace mojo
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
#ifndef SERVICES_ASSET_BUNDLE_ASSET_UNPACKER_JOB_H_
|
||||
#define SERVICES_ASSET_BUNDLE_ASSET_UNPACKER_JOB_H_
|
||||
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/task_runner.h"
|
||||
#include "mojo/data_pipe_utils/data_pipe_utils.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace asset_bundle {
|
||||
|
||||
class AssetUnpackerJob {
|
||||
public:
|
||||
AssetUnpackerJob(InterfaceRequest<AssetBundle> asset_bundle,
|
||||
scoped_refptr<base::TaskRunner> worker_runner);
|
||||
~AssetUnpackerJob();
|
||||
|
||||
void Unpack(ScopedDataPipeConsumerHandle zipped_assets);
|
||||
|
||||
private:
|
||||
void OnZippedAssetsAvailable(const base::FilePath& zip_path, bool success);
|
||||
void OnUnzippedAssetsAvailable(scoped_ptr<base::ScopedTempDir> temp_dir);
|
||||
|
||||
InterfaceRequest<AssetBundle> asset_bundle_;
|
||||
scoped_refptr<base::TaskRunner> worker_runner_;
|
||||
base::WeakPtrFactory<AssetUnpackerJob> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AssetUnpackerJob);
|
||||
};
|
||||
|
||||
} // namespace asset_bundle
|
||||
} // namespace mojo
|
||||
|
||||
#endif // SERVICES_ASSET_BUNDLE_ASSET_UNPACKER_JOB_H_
|
||||
@@ -1,63 +0,0 @@
|
||||
// Copyright 2015 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 "base/macros.h"
|
||||
#include "base/threading/sequenced_worker_pool.h"
|
||||
#include "mojo/application/application_runner_chromium.h"
|
||||
#include "mojo/public/c/system/main.h"
|
||||
#include "mojo/public/cpp/application/application_connection.h"
|
||||
#include "mojo/public/cpp/application/application_delegate.h"
|
||||
#include "mojo/public/cpp/application/interface_factory.h"
|
||||
#include "services/asset_bundle/asset_unpacker_impl.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace asset_bundle {
|
||||
|
||||
class AssetBundleApp : public ApplicationDelegate,
|
||||
public InterfaceFactory<AssetUnpacker> {
|
||||
public:
|
||||
AssetBundleApp() {}
|
||||
~AssetBundleApp() override {}
|
||||
|
||||
private:
|
||||
// |ApplicationDelegate| override:
|
||||
bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
|
||||
connection->AddService<AssetUnpacker>(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
// |InterfaceFactory<AssetUnpacker>| implementation:
|
||||
void Create(ApplicationConnection* connection,
|
||||
InterfaceRequest<AssetUnpacker> request) override {
|
||||
// Lazily initialize |sequenced_worker_pool_|. (We can't create it in the
|
||||
// constructor, since AtExitManager is only created in
|
||||
// ApplicationRunnerChromium::Run().)
|
||||
if (!sequenced_worker_pool_) {
|
||||
// TODO(vtl): What's the "right" way to choose the maximum number of
|
||||
// threads?
|
||||
sequenced_worker_pool_ =
|
||||
new base::SequencedWorkerPool(4, "AssetBundleWorker");
|
||||
}
|
||||
|
||||
new AssetUnpackerImpl(
|
||||
request.Pass(),
|
||||
sequenced_worker_pool_->GetTaskRunnerWithShutdownBehavior(
|
||||
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
|
||||
}
|
||||
|
||||
// We don't really need the "sequenced" part, but we need to be able to shut
|
||||
// down our worker pool.
|
||||
scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AssetBundleApp);
|
||||
};
|
||||
|
||||
} // namespace asset_bundle
|
||||
} // namespace mojo
|
||||
|
||||
MojoResult MojoMain(MojoHandle application_request) {
|
||||
mojo::ApplicationRunnerChromium runner(
|
||||
new mojo::asset_bundle::AssetBundleApp());
|
||||
return runner.Run(application_request);
|
||||
}
|
||||
Reference in New Issue
Block a user