• 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 #ifndef OHOS_MEDIA_PHOTOS_DATA_HANDLER
16 #define OHOS_MEDIA_PHOTOS_DATA_HANDLER
17 
18 #include <string>
19 
20 #include "photos_dao.h"
21 
22 namespace OHOS::Media {
23 class PhotosDataHandler {
24 public:
25     void OnStart(int32_t sceneCode, const std::string &taskId, std::shared_ptr<NativeRdb::RdbStore> mediaLibraryRdb);
26     void HandleDirtyFiles();
27 
28 private:
29     PhotosDataHandler &SetSceneCode(int32_t sceneCode);
30     PhotosDataHandler &SetTaskId(const std::string &taskId);
31     PhotosDataHandler &SetMediaLibraryRdb(std::shared_ptr<NativeRdb::RdbStore> mediaLibraryRdb);
32     void HandleDirtyFilesBatch(int32_t offset);
33     int32_t CleanDirtyFiles(const std::vector<PhotosDao::PhotosRowData> &dirtyFiles);
34     int32_t DeleteDirtyFilesInDb();
35     int32_t SetVisibleFilesInDb();
36     bool DeleteDirtyFile(const PhotosDao::PhotosRowData &dirtyFile);
37     bool ShouldSetVisible(const PhotosDao::PhotosRowData &dirtyFile);
38     void AddToCleanFailedFiles(const PhotosDao::PhotosRowData &dirtyFile);
39     void AddToSetVisibleFiles(const PhotosDao::PhotosRowData &dirtyFile);
40     bool IsLocalFileExist(const PhotosDao::PhotosRowData &dirtyFile);
41     bool IsFileExist(const PhotosDao::PhotosRowData &dirtyFile);
42     void ReportDirtyFile(const std::string &errorCode, const PhotosDao::PhotosRowData &dirtyFile);
43 
44 private:
45     int32_t sceneCode_ {-1};
46     std::string taskId_;
47     std::shared_ptr<NativeRdb::RdbStore> mediaLibraryRdb_;
48     std::mutex cleanFailedFilesMutex_;
49     std::mutex setVisibleFilesMutex_;
50     std::vector<std::string> cleanFailedFiles_;
51     std::vector<std::string> setVisibleFiles_;
52     PhotosDao photosDao_;
53     std::atomic<int32_t> dirtyFileCleanNumber_ {0};
54     std::atomic<int32_t> failedDirtyFileCleanNumber_ {0};
55 };
56 }  // namespace OHOS::Media
57 
58 #endif  // OHOS_MEDIA_PHOTOS_DATA_HANDLER
59