提交 5f65a121 编写于 作者: A Adam Barth 提交者: GitHub

Remove //base dependency from engine.cc (#2891)

We now just call stat directly to test whether a file exists.
上级 67a42cd1
......@@ -16,6 +16,8 @@ source_set("tonic") {
"dart_library_loader.h",
"dart_library_provider.cc",
"dart_library_provider.h",
"dart_library_provider_files.cc",
"dart_library_provider_files.h",
"dart_snapshot_loader.cc",
"dart_snapshot_loader.h",
"dart_state.cc",
......@@ -23,8 +25,11 @@ source_set("tonic") {
]
deps = [
"//base",
"//dart/runtime/bin:embedded_dart_io",
"//glue",
"//lib/tonic/parsers",
"//mojo/data_pipe_utils",
"//mojo/public/cpp/system",
]
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/shell/dart/dart_library_provider_files.h"
#include "flutter/tonic/dart_library_provider_files.h"
#include "base/bind.h"
#include "base/files/file_util.h"
......@@ -64,8 +64,8 @@ DartLibraryProviderFiles::DartLibraryProviderFiles() {}
DartLibraryProviderFiles::~DartLibraryProviderFiles() {}
void DartLibraryProviderFiles::LoadPackagesMap(const base::FilePath& packages) {
packages_ = packages;
void DartLibraryProviderFiles::LoadPackagesMap(const std::string& packages) {
packages_ = base::FilePath(packages);
std::string packages_source;
if (!base::ReadFileToString(base::MakeAbsoluteFilePath(packages_),
&packages_source)) {
......
......@@ -18,7 +18,7 @@ class DartLibraryProviderFiles : public blink::DartLibraryProvider {
DartLibraryProviderFiles();
~DartLibraryProviderFiles() override;
void LoadPackagesMap(const base::FilePath& packages);
void LoadPackagesMap(const std::string& packages);
protected:
// |DartLibraryProvider| implementation:
......
......@@ -79,7 +79,6 @@ source_set("common") {
"//sky/services/pointer:interfaces",
"//sky/services/rasterizer:interfaces",
"//sky/services/semantics:interfaces",
"//sky/shell/dart",
]
}
......
# 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.
source_set("dart") {
sources = [
"dart_library_provider_files.cc",
"dart_library_provider_files.h",
]
deps = [
"//base",
"//build/config/sanitizers:deps",
"//dart/runtime:libdart",
"//flutter/tonic",
"//lib/tonic/parsers",
"//mojo/data_pipe_utils",
"//mojo/public/cpp/application",
"//sky/engine/wtf",
]
}
......@@ -4,20 +4,20 @@
#include "sky/shell/ui/engine.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include <unistd.h>
#include "flutter/assets/directory_asset_bundle.h"
#include "flutter/assets/zip_asset_bundle.h"
#include "flutter/tonic/dart_library_provider_files.h"
#include "glue/movable_wrapper.h"
#include "glue/trace_event.h"
#include "lib/ftl/files/path.h"
#include "mojo/public/cpp/application/connect.h"
#include "sky/engine/bindings/mojo_services.h"
#include "sky/engine/core/script/dart_init.h"
#include "sky/engine/core/script/ui_dart_state.h"
#include "sky/engine/public/platform/Platform.h"
#include "sky/engine/public/web/Sky.h"
#include "sky/shell/dart/dart_library_provider_files.h"
#include "sky/shell/shell.h"
#include "sky/shell/ui/animator.h"
#include "sky/shell/ui/flutter_font_selector.h"
......@@ -29,6 +29,22 @@ namespace sky {
namespace shell {
namespace {
bool PathExists(const std::string& path) {
return access(path.c_str(), R_OK) == 0;
}
std::string FindPackagesPath(const std::string& main_dart) {
std::string directory = files::GetDirectoryName(main_dart);
std::string packages_path = directory + "/.packages";
if (!PathExists(packages_path)) {
directory = files::GetDirectoryName(directory);
packages_path = directory + "/.packages";
if (!PathExists(packages_path))
packages_path = std::string();
}
return packages_path;
}
PlatformImpl* g_platform_impl = nullptr;
} // namespace
......@@ -72,17 +88,9 @@ void Engine::RunFromSource(const std::string& main,
// Assets.
ConfigureDirectoryAssetBundle(assets_directory);
// .packages.
base::FilePath packages_path = base::FilePath(std::string(packages));
if (packages_path.empty()) {
base::FilePath main_dir = base::FilePath(main).DirName();
packages_path = main_dir.Append(FILE_PATH_LITERAL(".packages"));
if (!base::PathExists(packages_path)) {
packages_path = main_dir.Append(base::FilePath::kParentDirectory)
.Append(FILE_PATH_LITERAL(".packages"));
if (!base::PathExists(packages_path))
packages_path = base::FilePath();
}
}
std::string packages_path = packages;
if (packages_path.empty())
packages_path = FindPackagesPath(main);
DartLibraryProviderFiles* provider = new DartLibraryProviderFiles();
dart_library_provider_.reset(provider);
if (!packages_path.empty())
......@@ -231,27 +239,19 @@ void Engine::RunFromFile(const mojo::String& main,
const mojo::String& packages,
const mojo::String& bundle) {
TRACE_EVENT0("flutter", "Engine::RunFromFile");
std::string main_str(main);
std::string main_dart(main);
if (bundle.size() != 0) {
// The specification of an FLX bundle is optional.
ConfigureZipAssetBundle(bundle);
}
base::FilePath packages_path = base::FilePath(std::string(packages));
if (packages_path.empty()) {
base::FilePath main_dir = base::FilePath(main_str).DirName();
packages_path = main_dir.Append(FILE_PATH_LITERAL(".packages"));
if (!base::PathExists(packages_path)) {
packages_path = main_dir.Append(base::FilePath::kParentDirectory)
.Append(FILE_PATH_LITERAL(".packages"));
if (!base::PathExists(packages_path))
packages_path = base::FilePath();
}
}
std::string packages_path = packages;
if (packages_path.empty())
packages_path = FindPackagesPath(main_dart);
DartLibraryProviderFiles* provider = new DartLibraryProviderFiles();
dart_library_provider_.reset(provider);
if (!packages_path.empty())
provider->LoadPackagesMap(packages_path);
RunFromLibrary(main_str);
RunFromLibrary(main_dart);
}
void Engine::RunFromBundle(const mojo::String& script_uri,
......
......@@ -5,7 +5,6 @@
#ifndef SKY_SHELL_UI_ENGINE_H_
#define SKY_SHELL_UI_ENGINE_H_
#include "base/files/file_path.h"
#include "flutter/assets/zip_asset_store.h"
#include "lib/ftl/macros.h"
#include "lib/ftl/memory/weak_ptr.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册