Flutter Engine
directory_asset_bundle.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/assets/directory_asset_bundle.h"
6 
7 #include <utility>
8 
9 #include "flutter/fml/eintr_wrapper.h"
10 #include "flutter/fml/file.h"
11 #include "flutter/fml/mapping.h"
12 
13 namespace flutter {
14 
16  fml::UniqueFD descriptor,
17  bool is_valid_after_asset_manager_change)
18  : descriptor_(std::move(descriptor)) {
19  if (!fml::IsDirectory(descriptor_)) {
20  return;
21  }
22  is_valid_after_asset_manager_change_ = is_valid_after_asset_manager_change;
23  is_valid_ = true;
24 }
25 
27 
28 // |AssetResolver|
29 bool DirectoryAssetBundle::IsValid() const {
30  return is_valid_;
31 }
32 
33 // |AssetResolver|
34 bool DirectoryAssetBundle::IsValidAfterAssetManagerChange() const {
35  return is_valid_after_asset_manager_change_;
36 }
37 
38 // |AssetResolver|
39 std::unique_ptr<fml::Mapping> DirectoryAssetBundle::GetAsMapping(
40  const std::string& asset_name) const {
41  if (!is_valid_) {
42  FML_DLOG(WARNING) << "Asset bundle was not valid.";
43  return nullptr;
44  }
45 
46  auto mapping = std::make_unique<fml::FileMapping>(fml::OpenFile(
47  descriptor_, asset_name.c_str(), false, fml::FilePermission::kRead));
48 
49  if (!mapping->IsValid()) {
50  return nullptr;
51  }
52 
53  return mapping;
54 }
55 
56 } // namespace flutter
Definition: ref_ptr.h:252
DirectoryAssetBundle(fml::UniqueFD descriptor, bool is_valid_after_asset_manager_change)
bool IsDirectory(const fml::UniqueFD &directory)
Definition: file_posix.cc:124
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Definition: file_posix.cc:64
#define FML_DLOG(severity)
Definition: logging.h:85