Chinmay Garde 276481c4d3
Move tonic into //flutter/third_party. (#15895)
Tonic used to be used by multiple consumers outside of Flutter Engine. Due to
this, it has an unnecessary abstraction layer as well as utilities duplicated in
FML and other engine subsystems. The sole user of Tonic is now the Flutter
Engine. It is intended that the Flutter Engine team now owns this subsystem,
remove unnecessary utilities and document the headers. This is the first step in
the transition. No history is being imported as the initial history was already
lost in the transition of this component to fuchsia.googlesource. As this
component was unmaintained there, I could see no additional value in importing
the history of the patches there.

No functional change. Just moved the repo from //third_party to
//flutter/third_party and updates GN refs.
2020-01-25 17:01:56 -08:00

71 lines
2.1 KiB
C++

// Copyright 2013 The Flutter 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 LIB_TONIC_FILE_LOADER_FILE_LOADER_H_
#define LIB_TONIC_FILE_LOADER_FILE_LOADER_H_
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "third_party/dart/runtime/include/dart_api.h"
#include "tonic/common/macros.h"
#include "tonic/parsers/packages_map.h"
namespace tonic {
class FileLoader {
public:
FileLoader(int dirfd = -1);
~FileLoader();
bool LoadPackagesMap(const std::string& packages);
// The path to the `.packages` file the packages map was loaded from.
const std::string& packages() const { return packages_; }
Dart_Handle HandleLibraryTag(Dart_LibraryTag tag,
Dart_Handle library,
Dart_Handle url);
Dart_Handle CanonicalizeURL(Dart_Handle library, Dart_Handle url);
Dart_Handle Import(Dart_Handle url);
Dart_Handle Kernel(Dart_Handle url);
void SetPackagesUrl(Dart_Handle url);
Dart_Handle FetchBytes(const std::string& url,
uint8_t*& buffer,
intptr_t& buffer_size);
static const char kFileURLPrefix[];
static const size_t kFileURLPrefixLength;
static const std::string kPathSeparator;
private:
static std::string SanitizeURIEscapedCharacters(const std::string& str);
static std::string SanitizePath(const std::string& path);
static std::string CanonicalizeFileURL(const std::string& url);
std::string GetFilePathForURL(std::string url);
std::string GetFilePathForPackageURL(std::string url);
std::string GetFilePathForFileURL(std::string url);
std::string GetFileURLForPath(const std::string& path);
bool ReadFileToString(const std::string& path, std::string* result);
std::pair<uint8_t*, intptr_t> ReadFileToBytes(const std::string& path);
int dirfd_;
std::string packages_;
std::unique_ptr<PackagesMap> packages_map_;
std::vector<uint8_t*> kernel_buffers_;
TONIC_DISALLOW_COPY_AND_ASSIGN(FileLoader);
};
} // namespace tonic
#endif // LIB_TONIC_FILE_LOADER_FILE_LOADER_H_