• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 OHOS_MEDIALIBRARY_ASSET_DATA_MANAGER_H
17 #define OHOS_MEDIALIBRARY_ASSET_DATA_MANAGER_H
18 
19 #include <string>
20 #include <vector>
21 #include <unordered_set>
22 #include <unordered_map>
23 
24 #include "accurate_refresh_data_manager.h"
25 #include "abs_rdb_predicates.h"
26 
27 #include "accurate_common_data.h"
28 #include "photo_asset_change_info.h"
29 #include "multi_thread_asset_change_info_mgr.h"
30 
31 namespace OHOS {
32 namespace Media::AccurateRefresh {
33 #define EXPORT __attribute__ ((visibility ("default")))
34 
35 class EXPORT AssetDataManager : public AccurateRefreshDataManager<PhotoAssetChangeInfo, PhotoAssetChangeData> {
36 public:
AssetDataManager()37     AssetDataManager() : AssetDataManager(nullptr)
38     {}
AssetDataManager(std::shared_ptr<TransactionOperations> trans)39     AssetDataManager(std::shared_ptr<TransactionOperations> trans)
40         : AccurateRefreshDataManager<PhotoAssetChangeInfo, PhotoAssetChangeData>(trans)
41     {}
42     virtual ~AssetDataManager();
43     int32_t UpdateModifiedDatas() override;
44     int32_t PostProcessModifiedDatas(const std::vector<int32_t> &keys) override;
45     std::vector<int32_t> GetInitKeys() override;
46     int32_t SetContentChanged(int32_t fileId, bool isChanged);
47     int32_t SetThumbnailStatus(int32_t fileId, int32_t status);
48     int32_t UpdateNotifyInfo();
49     // 更新完对应fileId后清除
50     void ClearMultiThreadChangeData(int32_t fileId);
51     // 清除所有的fileId
52     void ClearMultiThreadChangeDatas();
53 
54 private:
55     int32_t UpdateThumbnailChangeStatus(PhotoAssetChangeData &assetChangeData);
56     int32_t GetChangeInfoKey(const PhotoAssetChangeInfo &changeInfo) override;
57     std::vector<PhotoAssetChangeInfo> GetInfoByKeys(const std::vector<int32_t> &fileIds) override;
58     std::vector<PhotoAssetChangeInfo> GetInfosByPredicates(const NativeRdb::AbsRdbPredicates &predicates) override;
59     std::vector<PhotoAssetChangeInfo> GetInfosByResult(const std::shared_ptr<NativeRdb::ResultSet> &resultSet) override;
60     void PostInsertBeforeData(PhotoAssetChangeData &changeData, PendingInfo &pendingInfo) override;
61     void PostInsertAfterData(PhotoAssetChangeData &changeData, PendingInfo &pendingInfo, bool isAdd = false) override;
62     bool CheckUpdateDataForMultiThread(PhotoAssetChangeData &changeData) override;
63     void UpdatePendingInfo(PhotoAssetChangeData &changeData, PendingInfo &pendingInfo);
64 
65 private:
66     std::unordered_map<int32_t, PhotoAssetContentInfo> contentInfos;
67     // 用于清理MultiThreadAssetChangeInfoMgr中的资产信息
68     std::unordered_set<int32_t> multiThreadAssetIds_;
69 };
70 
71 }  // namespace Media::AccurateRefresh
72 }  // namespace OHOS
73 
74 #endif