未验证 提交 299a7c25 编写于 作者: C Chinmay Garde 提交者: GitHub

Remove support for reading FLX archives from engine. (#5305)

The embedders have moved on already. This also removes a //garnet dependency on zlib wrappers.
上级 34ffb6ad
......@@ -9,8 +9,6 @@ source_set("assets") {
"asset_resolver.h",
"directory_asset_bundle.cc",
"directory_asset_bundle.h",
"zip_asset_store.cc",
"zip_asset_store.h",
]
deps = [
......@@ -18,11 +16,6 @@ source_set("assets") {
"$flutter_root/fml",
"$flutter_root/glue",
"//garnet/public/lib/fxl",
"//garnet/public/lib/zip",
]
public_deps = [
"//third_party/zlib:minizip",
]
public_configs = [ "$flutter_root:config" ]
......
......@@ -5,7 +5,6 @@
#include "flutter/assets/asset_manager.h"
#include "flutter/assets/directory_asset_bundle.h"
#include "flutter/assets/zip_asset_store.h"
#include "flutter/glue/trace_event.h"
#include "lib/fxl/files/path.h"
......
// 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/assets/zip_asset_store.h"
#include "lib/fxl/build_config.h"
#include <fcntl.h>
#if !defined(OS_WIN)
#include <unistd.h>
#endif
#include <string>
#include <utility>
#include "flutter/glue/trace_event.h"
namespace blink {
ZipAssetStore::ZipAssetStore(std::string file_path)
: file_path_(std::move(file_path)) {
BuildStatCache();
}
ZipAssetStore::~ZipAssetStore() = default;
zip::UniqueUnzipper ZipAssetStore::CreateUnzipper() const {
return zip::UniqueUnzipper{::unzOpen2(file_path_.c_str(), nullptr)};
}
// |blink::AssetResolver|
bool ZipAssetStore::IsValid() const {
return stat_cache_.size() > 0;
}
// |blink::AssetResolver|
bool ZipAssetStore::GetAsBuffer(const std::string& asset_name,
std::vector<uint8_t>* data) const {
TRACE_EVENT0("flutter", "ZipAssetStore::GetAsBuffer");
auto found = stat_cache_.find(asset_name);
if (found == stat_cache_.end()) {
return false;
}
auto unzipper = CreateUnzipper();
if (!unzipper.is_valid()) {
return false;
}
int result = UNZ_OK;
result = unzGoToFilePos(unzipper.get(), &(found->second.file_pos));
if (result != UNZ_OK) {
FXL_LOG(WARNING) << "unzGetCurrentFileInfo failed, error=" << result;
return false;
}
result = unzOpenCurrentFile(unzipper.get());
if (result != UNZ_OK) {
FXL_LOG(WARNING) << "unzOpenCurrentFile failed, error=" << result;
return false;
}
data->resize(found->second.uncompressed_size);
int total_read = 0;
while (total_read < static_cast<int>(data->size())) {
int bytes_read = unzReadCurrentFile(
unzipper.get(), data->data() + total_read, data->size() - total_read);
if (bytes_read <= 0) {
return false;
}
total_read += bytes_read;
}
return true;
}
void ZipAssetStore::BuildStatCache() {
TRACE_EVENT0("flutter", "ZipAssetStore::BuildStatCache");
auto unzipper = CreateUnzipper();
if (!unzipper.is_valid()) {
return;
}
if (unzGoToFirstFile(unzipper.get()) != UNZ_OK) {
return;
}
do {
int result = UNZ_OK;
// Get the current file name.
unz_file_info file_info = {};
char file_name[255];
result = unzGetCurrentFileInfo(unzipper.get(), &file_info, file_name,
sizeof(file_name), nullptr, 0, nullptr, 0);
if (result != UNZ_OK) {
continue;
}
if (file_info.uncompressed_size == 0) {
continue;
}
// Get the current file position.
unz_file_pos file_pos = {};
result = unzGetFilePos(unzipper.get(), &file_pos);
if (result != UNZ_OK) {
continue;
}
std::string file_name_key(file_name, file_info.size_filename);
CacheEntry entry(file_pos, file_info.uncompressed_size);
stat_cache_.emplace(std::move(file_name_key), std::move(entry));
} while (unzGoToNextFile(unzipper.get()) == UNZ_OK);
}
} // namespace blink
// 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.
#ifndef FLUTTER_ASSETS_ZIP_ASSET_STORE_H_
#define FLUTTER_ASSETS_ZIP_ASSET_STORE_H_
#include <map>
#include "flutter/assets/asset_resolver.h"
#include "lib/fxl/macros.h"
#include "lib/fxl/memory/ref_counted.h"
#include "lib/zip/unique_unzipper.h"
#include "third_party/zlib/contrib/minizip/unzip.h"
namespace blink {
class ZipAssetStore final : public AssetResolver {
public:
ZipAssetStore(std::string file_path);
~ZipAssetStore() override;
private:
struct CacheEntry {
unz_file_pos file_pos;
size_t uncompressed_size;
CacheEntry(unz_file_pos p_file_pos, size_t p_uncompressed_size)
: file_pos(p_file_pos), uncompressed_size(p_uncompressed_size) {}
};
std::string file_path_;
mutable std::map<std::string, CacheEntry> stat_cache_;
// |blink::AssetResolver|
bool IsValid() const override;
// |blink::AssetResolver|
bool GetAsBuffer(const std::string& asset_name,
std::vector<uint8_t>* data) const override;
void BuildStatCache();
zip::UniqueUnzipper CreateUnzipper() const;
FXL_DISALLOW_COPY_AND_ASSIGN(ZipAssetStore);
};
} // namespace blink
#endif // FLUTTER_ASSETS_ZIP_ASSET_STORE_H_
......@@ -7,7 +7,6 @@
#include <sstream>
#include "flutter/assets/directory_asset_bundle.h"
#include "flutter/assets/zip_asset_store.h"
#include "flutter/fml/file.h"
#include "flutter/runtime/dart_vm.h"
......@@ -24,9 +23,6 @@ RunConfiguration RunConfiguration::InferFromSettings(
std::make_unique<blink::DirectoryAssetBundle>(fml::OpenFile(
settings.assets_path.c_str(), fml::OpenPermission::kRead, true)));
asset_manager->PushBack(
std::make_unique<blink::ZipAssetStore>(settings.flx_path));
return {IsolateConfiguration::InferFromSettings(settings, asset_manager),
asset_manager};
}
......
......@@ -322,8 +322,6 @@ ORIGIN: ../../../flutter/assets/directory_asset_bundle.cc + ../../../LICENSE
TYPE: LicenseType.bsd
FILE: ../../../flutter/assets/directory_asset_bundle.cc
FILE: ../../../flutter/assets/directory_asset_bundle.h
FILE: ../../../flutter/assets/zip_asset_store.cc
FILE: ../../../flutter/assets/zip_asset_store.h
FILE: ../../../flutter/common/settings.cc
FILE: ../../../flutter/common/settings.h
FILE: ../../../flutter/flow/export_node.cc
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册