1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_ADAPTER_OHOS_CPP_FILE_ASSET_PROVIDER_H 17 #define FOUNDATION_ACE_ADAPTER_OHOS_CPP_FILE_ASSET_PROVIDER_H 18 19 #include <map> 20 #include <string> 21 #include <unordered_map> 22 #include <vector> 23 24 #include "flutter/assets/asset_resolver.h" 25 #include "flutter/fml/mapping.h" 26 27 #include "base/resource/asset_manager.h" 28 #include "base/utils/macros.h" 29 #include "core/common/flutter/flutter_asset_manager.h" 30 31 namespace OHOS::Ace { 32 33 class ACE_EXPORT FileAssetProvider : public FlutterAssetProvider { 34 DECLARE_ACE_TYPE(FileAssetProvider, FlutterAssetProvider); 35 36 public: 37 FileAssetProvider() = default; 38 ~FileAssetProvider() override = default; 39 40 bool Initialize(const std::string& packagePath, const std::vector<std::string>& assetBasePaths); 41 42 std::unique_ptr<fml::Mapping> GetAsMapping(const std::string& assetName) const override; 43 44 bool IsValid() const override; 45 46 std::string GetAssetPath(const std::string& assetName) override; 47 48 void GetAssetList(const std::string& path, std::vector<std::string>& assetList) override; 49 50 private: 51 mutable std::mutex mutex_; 52 std::string packagePath_; 53 std::vector<std::string> assetBasePaths_; 54 }; 55 56 } // namespace OHOS::Ace 57 58 #endif // FOUNDATION_ACE_ADAPTER_OHOS_CPP_FILE_ASSET_PROVIDER_H 59