• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "core/common/resource/resource_manager.h"
17 
18 #include <memory>
19 #include <string>
20 
21 #include "base/log/log_wrapper.h"
22 #include "base/memory/referenced.h"
23 #include "core/components/theme/resource_adapter.h"
24 
25 namespace OHOS::Ace {
26 namespace {
27 const std::string DEFAULT_BUNDLE_NAME = "";
28 const std::string DEFAULT_MODULE_NAME = "";
29 } // namespace
30 
GetInstance()31 ResourceManager& ResourceManager::GetInstance()
32 {
33     static ResourceManager instance;
34     return instance;
35 }
36 
GetOrCreateResourceAdapter(RefPtr<ResourceObject> & resourceObject)37 RefPtr<ResourceAdapter> ResourceManager::GetOrCreateResourceAdapter(RefPtr<ResourceObject>& resourceObject)
38 {
39     std::string bundleName = resourceObject->GetBundleName();
40     std::string moduleName = resourceObject->GetModuleName();
41 
42     auto resourceAdapter = GetResourceAdapter(bundleName, moduleName);
43     if (resourceAdapter == nullptr) {
44         resourceAdapter = ResourceAdapter::CreateNewResourceAdapter(bundleName, moduleName);
45         if (!resourceAdapter) {
46             return GetResourceAdapter(DEFAULT_BUNDLE_NAME, DEFAULT_MODULE_NAME);
47         }
48         AddResourceAdapter(bundleName, moduleName, resourceAdapter);
49     }
50     return resourceAdapter;
51 }
52 } // namespace OHOS::Ace