forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
directory_asset_bundle.cc
50 lines (38 loc) · 1.23 KB
/
directory_asset_bundle.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 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/directory_asset_bundle.h"
#include <utility>
#include "flutter/fml/eintr_wrapper.h"
#include "flutter/fml/file.h"
#include "flutter/fml/mapping.h"
namespace blink {
DirectoryAssetBundle::DirectoryAssetBundle(fml::UniqueFD descriptor)
: descriptor_(std::move(descriptor)) {
if (!fml::IsDirectory(descriptor_)) {
return;
}
is_valid_ = true;
}
DirectoryAssetBundle::~DirectoryAssetBundle() = default;
// |blink::AssetResolver|
bool DirectoryAssetBundle::IsValid() const {
return is_valid_;
}
// |blink::AssetResolver|
std::unique_ptr<fml::Mapping> DirectoryAssetBundle::GetAsMapping(
const std::string& asset_name) const {
if (!is_valid_) {
FML_DLOG(WARNING) << "Asset bundle was not valid.";
return nullptr;
}
auto mapping = std::make_unique<fml::FileMapping>(
fml::OpenFile(descriptor_, asset_name.c_str(), fml::OpenPermission::kRead,
false /* directory */),
false /* executable */);
if (mapping->GetMapping() == nullptr) {
return nullptr;
}
return mapping;
}
} // namespace blink